Skip to content
This repository
  • 1 commit
  • 12 files changed
  • 0 comments
  • 1 contributor
12  lib/formtastic/inputs/base.rb
@@ -12,12 +12,12 @@ def initialize(builder, template, object, object_name, method, options)
12 12
         @method = method
13 13
         @options = options.dup
14 14
         
15  
-        warn_deprecated_option!(:value, ":input_html => { :value => '...'}")
16  
-        warn_deprecated_option!(:hint_class, "default_hint_class configuration")
17  
-        warn_deprecated_option!(:error_class, "default_error_class configuration")
18  
-        warn_deprecated_option!(:group_by, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
19  
-        warn_deprecated_option!(:group_label, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
20  
-        warn_deprecated_option!(:find_options, "YourModel.find(...)")
  15
+        removed_option!(:value)
  16
+        removed_option!(:hint_class)
  17
+        removed_option!(:error_class)
  18
+        removed_option!(:group_by)
  19
+        removed_option!(:group_label)
  20
+        removed_option!(:find_options)
21 21
       end
22 22
       
23 23
       # Usefull for deprecating options.
9  lib/formtastic/inputs/base/collections.rb
@@ -78,18 +78,11 @@ def collection_from_association
78 78
                     ) if reflection.options[:polymorphic] == true
79 79
             end
80 80
 
81  
-            find_options_from_options = options[:find_options] || {}
82  
-            conditions_from_options = find_options_from_options[:conditions] || {}
83 81
             conditions_from_reflection = (reflection.respond_to?(:options) && reflection.options[:conditions]) || {}
84 82
             conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc)
85 83
 
86 84
             scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
87  
-            if conditions_from_options.any?
88  
-              reflection.klass.scoped(scope_conditions).where(conditions_from_options)
89  
-            else
90  
-              find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
91  
-              reflection.klass.scoped(scope_conditions).where(find_options_from_options)
92  
-            end
  85
+            reflection.klass.scoped(scope_conditions).where({})
93 86
           end
94 87
         end
95 88
 
9  lib/formtastic/inputs/base/errors.rb
@@ -8,22 +8,19 @@ def error_html
8 8
         end
9 9
         
10 10
         def error_sentence_html
11  
-          error_class = options[:error_class] || builder.default_inline_error_class
12  
-          template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
  11
+          template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => builder.default_inline_error_class)
13 12
         end
14 13
                 
15 14
         def error_list_html
16  
-          error_class = options[:error_class] || builder.default_error_list_class
17 15
           list_elements = []
18 16
           errors.each do |error|
19 17
             list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
20 18
           end
21  
-          template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
  19
+          template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => builder.default_error_list_class)
22 20
         end
23 21
         
24 22
         def error_first_html
25  
-          error_class = options[:error_class] || builder.default_inline_error_class
26  
-          template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
  23
+          template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => builder.default_inline_error_class)
27 24
         end
28 25
         
29 26
         def error_none_html
77  lib/formtastic/inputs/base/grouped_collections.rb
... ...
@@ -1,77 +0,0 @@
1  
-module Formtastic
2  
-  module Inputs
3  
-    module Base
4  
-      module GroupedCollections
5  
-      
6  
-        def raw_grouped_collection
7  
-          @raw_grouped_collection ||= raw_collection.map { |option| option.send(options[:group_by]) }.uniq
8  
-        end
9  
-      
10  
-        def grouped_collection
11  
-          @grouped_collection ||= raw_grouped_collection.sort_by { |group_item| group_item.send(group_label_method) }
12  
-        end
13  
-      
14  
-        def group_label_method
15  
-          @group_label_method ||= (group_label_method_from_options || group_label_method_from_grouped_collection)
16  
-        end
17  
-      
18  
-        def group_label_method_from_options
19  
-          options[:group_label]
20  
-        end
21  
-      
22  
-        def group_label_method_from_grouped_collection
23  
-          label_and_value_method_from_collection(raw_grouped_collection).first
24  
-        end
25  
-      
26  
-        def group_association
27  
-          @group_association ||= (group_association_from_options || group_association_from_reflection)
28  
-        end
29  
-      
30  
-        def group_association_from_options
31  
-          options[:group_association]
32  
-        end
33  
-      
34  
-        def group_by
35  
-          options[:group_by]
36  
-        end
37  
-      
38  
-        def group_association_from_reflection
39  
-          method_to_group_association_by = reflection.klass.reflect_on_association(group_by)
40  
-          group_class = method_to_group_association_by.klass
41  
-      
42  
-          # This will return in the normal case
43  
-          return method.to_s.pluralize.to_sym if group_class.reflect_on_association(method.to_s.pluralize)
44  
-      
45  
-          # This is for belongs_to associations named differently than their class
46  
-          # form.input :parent, :group_by => :customer
47  
-          # eg.
48  
-          # class Project
49  
-          #   belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
50  
-          #   belongs_to :customer
51  
-          # end
52  
-          # class Customer
53  
-          #   has_many :projects
54  
-          # end
55  
-          group_method = group_class.to_s.underscore.pluralize.to_sym
56  
-          return group_method if group_class.reflect_on_association(group_method) # :projects
57  
-      
58  
-          # This is for has_many associations named differently than their class
59  
-          # eg.
60  
-          # class Project
61  
-          #   belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id'
62  
-          #   belongs_to :customer
63  
-          # end
64  
-          # class Customer
65  
-          #   has_many :tasks, :class_name => 'Project', :foreign_key => 'customer_id'
66  
-          # end
67  
-          possible_associations = group_class.reflect_on_all_associations(:has_many).find_all {|assoc| assoc.klass == reflection.klass }
68  
-          return possible_associations.first.name.to_sym if possible_associations.count == 1
69  
-      
70  
-          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"
71  
-        end
72  
-
73  
-      end
74  
-    end
75  
-  end
76  
-end
77  
-      
2  lib/formtastic/inputs/base/hints.rb
@@ -8,7 +8,7 @@ def hint_html
8 8
             template.content_tag(
9 9
               :p, 
10 10
               Formtastic::Util.html_safe(hint_text), 
11  
-              :class => (options[:hint_class] || builder.default_hint_class)
  11
+              :class => builder.default_hint_class
12 12
             )
13 13
           end
14 14
         end
2  lib/formtastic/inputs/base/options.rb
@@ -8,7 +8,7 @@ def input_options
8 8
         end
9 9
         
10 10
         def formtastic_options
11  
-          [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
  11
+          [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :class]
12 12
         end
13 13
       
14 14
       end
6  lib/formtastic/inputs/hidden_input.rb
@@ -31,12 +31,8 @@ module Inputs
31 31
     class HiddenInput 
32 32
       include Base
33 33
       
34  
-      # Override to include :value set directly from options hash. The :value set in :input_html 
35  
-      # hash will be preferred over :value set directly in the options.
36  
-      #
37  
-      # @deprecated :value option
38 34
       def input_html_options
39  
-        options.slice(:value).merge(super).merge(:required => nil).merge(:autofocus => nil)
  35
+        super.merge(:required => nil).merge(:autofocus => nil)
40 36
       end
41 37
       
42 38
       def to_html
16  lib/formtastic/inputs/select_input.rb
@@ -140,13 +140,12 @@ module Inputs
140 140
     class SelectInput
141 141
       include Base
142 142
       include Base::Collections
143  
-      include Base::GroupedCollections
144 143
 
145 144
       def to_html
146 145
         input_wrapping do
147 146
           hidden_input <<
148 147
           label_html <<
149  
-          (options[:group_by] ? grouped_select_html : select_html)
  148
+          select_html
150 149
         end
151 150
       end
152 151
 
@@ -154,19 +153,6 @@ def select_html
154 153
         builder.select(input_name, collection, input_options, input_html_options)
155 154
       end
156 155
 
157  
-      def grouped_select_html
158  
-        builder.grouped_collection_select(
159  
-          input_name,
160  
-          grouped_collection,
161  
-          group_association,
162  
-          group_label_method,
163  
-          value_method,
164  
-          label_method,
165  
-          input_options,
166  
-          input_html_options
167  
-        )
168  
-      end
169  
-
170 156
       def include_blank
171 157
         options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
172 158
       end
31  spec/helpers/input_helper_spec.rb
@@ -665,17 +665,7 @@ def length_should_be_required(options)
665 665
           output_buffer.should have_tag("form li p.inline-hints", hint_text)
666 666
         end
667 667
 
668  
-				it 'should have a custom hint class if I ask for one' do
669  
-          with_deprecation_silenced do
670  
-            hint_text = "this is the title of the post"
671  
-            concat(semantic_form_for(@new_post) do |builder|
672  
-              concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
673  
-            end)
674  
-            output_buffer.should have_tag("form li p.custom-hint-class", hint_text)
675  
-          end
676  
-        end
677  
-
678  
-        it 'should have a custom hint class defaulted for all forms' do
  668
+        it 'should use the configured hint class' do
679 669
           hint_text = "this is the title of the post"
680 670
           Formtastic::FormBuilder.default_hint_class = "custom-hint-class"
681 671
           concat(semantic_form_for(@new_post) do |builder|
@@ -720,25 +710,6 @@ def length_should_be_required(options)
720 710
               end
721 711
             end
722 712
 
723  
-						it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
724  
-              with_config :i18n_lookups_by_default, false do
725  
-                ::I18n.backend.store_translations :en,
726  
-                :formtastic => {
727  
-                    :hints => {
728  
-                      :post => {
729  
-                        :title => @localized_hint_text
730  
-                       }
731  
-                     }
732  
-                  }
733  
-                with_deprecation_silenced do
734  
-                  concat(semantic_form_for(@new_post) do |builder|
735  
-                    concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
736  
-                  end)
737  
-                end
738  
-                output_buffer.should have_tag('form li p.custom-hint-class', @localized_hint_text)
739  
-              end
740  
-            end
741  
-
742 713
             it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
743 714
               with_config :i18n_lookups_by_default, false do
744 715
                 concat(semantic_form_for(@new_post) do |builder|
12  spec/inputs/hidden_input_spec.rb
@@ -12,10 +12,9 @@
12 12
     with_deprecation_silenced do
13 13
       concat(semantic_form_for(@new_post) do |builder|
14 14
         concat(builder.input(:secret, :as => :hidden))
15  
-        concat(builder.input(:author_id, :as => :hidden, :value => 99))
16 15
         concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
17 16
         concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
18  
-        concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
  17
+        concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
19 18
       end)
20 19
     end
21 20
   end
@@ -35,10 +34,6 @@
35 34
     output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
36 35
   end
37 36
   
38  
-  it "should pass any explicitly specified value - using :value" do
39  
-    output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
40  
-  end
41  
-
42 37
   # Handle Formtastic :input_html options for consistency.
43 38
   it "should pass any explicitly specified value - using :input_html options" do
44 39
     output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
@@ -83,15 +78,14 @@
83 78
       with_deprecation_silenced do
84 79
         concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
85 80
           concat(builder.input(:secret, :as => :hidden))
86  
-          concat(builder.input(:author_id, :as => :hidden, :value => 99))
87 81
           concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
88 82
           concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
89  
-          concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
  83
+          concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
90 84
         end)
91 85
       end
92 86
     end
93 87
 
94  
-    attributes_to_check = [:secret, :author_id, :published, :reviewer]
  88
+    attributes_to_check = [:secret, :published, :reviewer]
95 89
     attributes_to_check.each do |a|
96 90
       it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
97 91
     end
98  spec/inputs/select_input_spec.rb
@@ -200,21 +200,6 @@
200 200
     end
201 201
   end
202 202
 
203  
-  describe "for a belongs_to association with :group_by => :author" do
204  
-    it "should call author.posts" do
205  
-      ::Author.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Post, :name => :posts)] : []}
206  
-
207  
-      [@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
208  
-      @fred.should_receive(:posts)
209  
-
210  
-      with_deprecation_silenced do
211  
-        concat(semantic_form_for(@new_post) do |builder|
212  
-          concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
213  
-        end)
214  
-      end
215  
-    end
216  
-  end
217  
-
218 203
   describe "for a belongs_to association with :conditions" do
219 204
     before do
220 205
       ::Post.stub!(:reflect_on_association).with(:author).and_return do
@@ -232,89 +217,6 @@
232 217
       end
233 218
     end
234 219
 
235  
-    it "should call author.find with association conditions and find_options conditions" do
236  
-      ::Author.should_receive(:scoped).with(:conditions => {:active => true})
237  
-      ::Author.should_receive(:where).with({:publisher => true})
238  
-
239  
-      with_deprecation_silenced do
240  
-        semantic_form_for(@new_post) do |builder|
241  
-          concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
242  
-        end
243  
-      end
244  
-    end
245  
-  end
246  
-
247  
-  describe 'for a belongs_to association with :group_by => :continent' do
248  
-    before do
249  
-      @authors = [@bob, @fred, @fred, @fred]
250  
-      ::Author.stub!(:find).and_return(@authors)
251  
-      @continent_names = %w(Europe Africa)
252  
-      @continents = (0..1).map { |i| c = ::Continent.new; c.stub!(:id).and_return(100 - i);c }
253  
-      @authors[0..1].each_with_index { |author, i| author.stub!(:continent).and_return(@continents[i]) }
254  
-
255  
-      ::Continent.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Author, :name => :authors)] : [] }
256  
-      ::Continent.stub!(:reflect_on_association).and_return {|column_name| mock('reflection', :klass => Author) if column_name == :authors}
257  
-      ::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Continent, :macro => :belongs_to) if column_name == :continent }
258  
-
259  
-
260  
-      @continents.each_with_index do |continent, i|
261  
-        continent.stub!(:to_label).and_return(@continent_names[i])
262  
-        continent.stub!(:authors).and_return([@authors[i]])
263  
-      end
264  
-
265  
-      with_deprecation_silenced do
266  
-        concat(semantic_form_for(@new_post) do |builder|
267  
-          concat(builder.input(:author, :as => :select, :group_by => :continent ) )
268  
-          concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
269  
-          concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
270  
-          concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
271  
-        end)
272  
-      end
273  
-    end
274  
-
275  
-    it_should_have_input_wrapper_with_class("select")
276  
-    it_should_have_input_wrapper_with_id("post_author_input")
277  
-    it_should_have_label_with_text(/Author/)
278  
-    it_should_have_label_for('post_author_id')
279  
-
280  
-    # TODO, need to find a way to repeat some of the specs and logic from the belongs_to specs without grouping
281  
-
282  
-    0.upto(1) do |i|
283  
-      it 'should have all option groups and the right values' do
284  
-        output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
285  
-      end
286  
-
287  
-      it 'should have custom group labels' do
288  
-        output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
289  
-      end
290  
-
291  
-      it 'should have custom author labels' do
292  
-        output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
293  
-      end
294  
-
295  
-      it 'should have custom author and group labels' do
296  
-        output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
297  
-      end
298  
-    end
299  
-
300  
-    it 'should have no duplicate groups' do
301  
-      output_buffer.should have_tag('form li select optgroup', :count => 8)
302  
-    end
303  
-
304  
-    it 'should sort the groups on the label method' do
305  
-      output_buffer.should have_tag("form li select optgroup[@label='Africa']")
306  
-      output_buffer.should have_tag("form li select optgroup[@label='99']")
307  
-    end
308  
-
309  
-    it 'should call find with :include for more optimized queries' do
310  
-      Author.should_receive(:where).with(:include => :continent)
311  
-
312  
-      with_deprecation_silenced do 
313  
-        semantic_form_for(@new_post) do |builder|
314  
-          concat(builder.input(:author, :as => :select, :group_by => :continent ) )
315  
-        end
316  
-      end
317  
-    end
318 220
   end
319 221
 
320 222
   describe 'for a has_many association' do
2  spec/support/custom_macros.rb
@@ -255,7 +255,7 @@ def it_should_apply_error_logic_for_input_type(type)
255 255
         end
256 256
       end
257 257
     end
258  
-
  258
+    
259 259
     def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
260 260
       it "should call find on the association class when no collection is provided" do
261 261
         ::Author.should_receive(:where)

No commit comments for this range

Something went wrong with that request. Please try again.