Permalink
Browse files

removed deprecated options :value, :hint_class, :error_class, :group_…

…by, :group_label, :find_options
  • Loading branch information...
1 parent f68d4c8 commit 9a78fa3fbd472183833987ba812db6a3fa75dcea @justinfrench justinfrench committed Jun 5, 2012
@@ -12,12 +12,12 @@ def initialize(builder, template, object, object_name, method, options)
@method = method
@options = options.dup
- warn_deprecated_option!(:value, ":input_html => { :value => '...'}")
- warn_deprecated_option!(:hint_class, "default_hint_class configuration")
- warn_deprecated_option!(:error_class, "default_error_class configuration")
- warn_deprecated_option!(:group_by, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
- warn_deprecated_option!(:group_label, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
- warn_deprecated_option!(:find_options, "YourModel.find(...)")
+ removed_option!(:value)
+ removed_option!(:hint_class)
+ removed_option!(:error_class)
+ removed_option!(:group_by)
+ removed_option!(:group_label)
+ removed_option!(:find_options)
end
# Usefull for deprecating options.
@@ -78,18 +78,11 @@ def collection_from_association
) if reflection.options[:polymorphic] == true
end
- find_options_from_options = options[:find_options] || {}
- conditions_from_options = find_options_from_options[:conditions] || {}
conditions_from_reflection = (reflection.respond_to?(:options) && reflection.options[:conditions]) || {}
conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc)
scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
- if conditions_from_options.any?
- reflection.klass.scoped(scope_conditions).where(conditions_from_options)
- else
- find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
- reflection.klass.scoped(scope_conditions).where(find_options_from_options)
- end
+ reflection.klass.scoped(scope_conditions).where({})
end
end
@@ -8,22 +8,19 @@ def error_html
end
def error_sentence_html
- error_class = options[:error_class] || builder.default_inline_error_class
- template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
+ template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => builder.default_inline_error_class)
end
def error_list_html
- error_class = options[:error_class] || builder.default_error_list_class
list_elements = []
errors.each do |error|
list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
end
- template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
+ template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => builder.default_error_list_class)
end
def error_first_html
- error_class = options[:error_class] || builder.default_inline_error_class
- template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
+ template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => builder.default_inline_error_class)
end
def error_none_html
@@ -1,77 +0,0 @@
-module Formtastic
- module Inputs
- module Base
- module GroupedCollections
-
- def raw_grouped_collection
- @raw_grouped_collection ||= raw_collection.map { |option| option.send(options[:group_by]) }.uniq
- end
-
- def grouped_collection
- @grouped_collection ||= raw_grouped_collection.sort_by { |group_item| group_item.send(group_label_method) }
- end
-
- def group_label_method
- @group_label_method ||= (group_label_method_from_options || group_label_method_from_grouped_collection)
- end
-
- def group_label_method_from_options
- options[:group_label]
- end
-
- def group_label_method_from_grouped_collection
- label_and_value_method_from_collection(raw_grouped_collection).first
- end
-
- def group_association
- @group_association ||= (group_association_from_options || group_association_from_reflection)
- end
-
- def group_association_from_options
- options[:group_association]
- end
-
- def group_by
- options[:group_by]
- end
-
- def group_association_from_reflection
- method_to_group_association_by = reflection.klass.reflect_on_association(group_by)
- group_class = method_to_group_association_by.klass
-
- # This will return in the normal case
- return method.to_s.pluralize.to_sym if group_class.reflect_on_association(method.to_s.pluralize)
-
- # This is for belongs_to associations named differently than their class
- # form.input :parent, :group_by => :customer
- # eg.
- # class Project
- # belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
- # belongs_to :customer
- # end
- # class Customer
- # has_many :projects
- # end
- group_method = group_class.to_s.underscore.pluralize.to_sym
- return group_method if group_class.reflect_on_association(group_method) # :projects
-
- # This is for has_many associations named differently than their class
- # eg.
- # class Project
- # belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
- # belongs_to :customer
- # end
- # class Customer
- # has_many :tasks, :class_name => 'Project', :foreign_key => 'customer_id'
- # end
- possible_associations = group_class.reflect_on_all_associations(:has_many).find_all {|assoc| assoc.klass == reflection.klass }
- return possible_associations.first.name.to_sym if possible_associations.count == 1
-
- raise "Cannot infer group association for #{method} grouped by #{group_by}, there were #{possible_associations.empty? ? 'no' : possible_associations.size} possible associations. Please specify using :group_association"
- end
-
- end
- end
- end
-end
-
@@ -8,7 +8,7 @@ def hint_html
template.content_tag(
:p,
Formtastic::Util.html_safe(hint_text),
- :class => (options[:hint_class] || builder.default_hint_class)
+ :class => builder.default_hint_class
)
end
end
@@ -8,7 +8,7 @@ def input_options
end
def formtastic_options
- [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
+ [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :class]
end
end
@@ -31,12 +31,8 @@ module Inputs
class HiddenInput
include Base
- # Override to include :value set directly from options hash. The :value set in :input_html
- # hash will be preferred over :value set directly in the options.
- #
- # @deprecated :value option
def input_html_options
- options.slice(:value).merge(super).merge(:required => nil).merge(:autofocus => nil)
+ super.merge(:required => nil).merge(:autofocus => nil)
end
def to_html
@@ -140,33 +140,19 @@ module Inputs
class SelectInput
include Base
include Base::Collections
- include Base::GroupedCollections
def to_html
input_wrapping do
hidden_input <<
label_html <<
- (options[:group_by] ? grouped_select_html : select_html)
+ select_html
end
end
def select_html
builder.select(input_name, collection, input_options, input_html_options)
end
- def grouped_select_html
- builder.grouped_collection_select(
- input_name,
- grouped_collection,
- group_association,
- group_label_method,
- value_method,
- label_method,
- input_options,
- input_html_options
- )
- end
-
def include_blank
options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
end
@@ -665,17 +665,7 @@ def length_should_be_required(options)
output_buffer.should have_tag("form li p.inline-hints", hint_text)
end
- it 'should have a custom hint class if I ask for one' do
- with_deprecation_silenced do
- hint_text = "this is the title of the post"
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
- end)
- output_buffer.should have_tag("form li p.custom-hint-class", hint_text)
- end
- end
-
- it 'should have a custom hint class defaulted for all forms' do
+ it 'should use the configured hint class' do
hint_text = "this is the title of the post"
Formtastic::FormBuilder.default_hint_class = "custom-hint-class"
concat(semantic_form_for(@new_post) do |builder|
@@ -720,25 +710,6 @@ def length_should_be_required(options)
end
end
- it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
- with_config :i18n_lookups_by_default, false do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :hints => {
- :post => {
- :title => @localized_hint_text
- }
- }
- }
- with_deprecation_silenced do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
- end)
- end
- output_buffer.should have_tag('form li p.custom-hint-class', @localized_hint_text)
- end
- end
-
it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
with_config :i18n_lookups_by_default, false do
concat(semantic_form_for(@new_post) do |builder|
@@ -12,10 +12,9 @@
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden))
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
+ concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
end)
end
end
@@ -35,10 +34,6 @@
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
end
- it "should pass any explicitly specified value - using :value" do
- output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
- end
-
# Handle Formtastic :input_html options for consistency.
it "should pass any explicitly specified value - using :input_html options" do
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
@@ -83,15 +78,14 @@
with_deprecation_silenced do
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
concat(builder.input(:secret, :as => :hidden))
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
+ concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
end)
end
end
- attributes_to_check = [:secret, :author_id, :published, :reviewer]
+ attributes_to_check = [:secret, :published, :reviewer]
attributes_to_check.each do |a|
it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
end
Oops, something went wrong.

0 comments on commit 9a78fa3

Please sign in to comment.