Skip to content
This repository
Browse code

Renamed (with backwards compatibility) and deprecation notices) :labe…

…l_method => :member_label, :value_method => :member_value and :grouped_label_method => :grouped_label. Fixes #533.
  • Loading branch information...
commit 8d4d9edce25692312f6c31ab4a928cb5d832c6d5 1 parent dbf01b5
Justin French authored May 05, 2011
2  README.textile
Source Rendered
@@ -171,7 +171,7 @@ If you want to customize the label text, or render some hint text below the fiel
171 171
     <% form.inputs :name => "Advanced Options", :id => "advanced" do %>
172 172
       <%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
173 173
       <%= form.input :section, :as => :radio %>
174  
-      <%= form.input :user, :label => "Author", :label_method => :full_name %>
  174
+      <%= form.input :user, :label => "Author", :member_label => :full_name %>
175 175
       <%= form.input :categories, :required => false %>
176 176
       <%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
177 177
     <% end %>
15  lib/formtastic/helpers/input_helper.rb
@@ -136,12 +136,18 @@ module InputHelper
136 136
       # @option options :collection [Array<ActiveModel, String, Symbol>, Hash{String => String, Boolean}, OrderedHash{String => String, Boolean}]
137 137
       #   Override collection of objects in the association (`:select`, `:radio` & `:check_boxes` inputs only)
138 138
       #
139  
-      # @option options :label_method [Symbol, Proc, Method]
  139
+      # @option options :member_label [Symbol, Proc, Method]
140 140
       #   Override the method called on each object in the `:collection` for use as the `<label>` content (`:check_boxes` & `:radio` inputs) or `<option>` content (`:select` inputs)
141 141
       #
142  
-      # @option options :value_method [Symbol, Proc, Method]
  142
+      # @option options :label_method [Symbol, Proc, Method]
  143
+      #   Deprecated, renamed to :member_label
  144
+      #
  145
+      # @option options :member_value [Symbol, Proc, Method]
143 146
       #   Override the method called on each object in the `:collection` for use as the `value` attribute in the `<input>` (`:check_boxes` & `:radio` inputs) or `<option>` (`:select` inputs)
144 147
       #
  148
+      # @option options :value_method [Symbol, Proc, Method]
  149
+      #   Deprecated, renamed to :member_value
  150
+      #
145 151
       # @option options :hint_class [String]
146 152
       #   Override the `class` attribute applied to the `<p>` tag used when a `:hint` is rendered for an input
147 153
       #
@@ -158,6 +164,9 @@ module InputHelper
158 164
       #   TODO will probably be deprecated
159 165
       #
160 166
       # @option options :group_label_method [Symbol]
  167
+      #   Deprecated, use `:group_label`
  168
+      #
  169
+      # @option options :group_label [Symbol]
161 170
       #   TODO will probably be deprecated
162 171
       #
163 172
       # @option options :include_blank [Boolean]
@@ -167,7 +176,7 @@ module InputHelper
167 176
       #   Specify the text in the first ('blank') `:select` input `<option>` to prompt a user to make a selection (implicitly sets `:include_blank` to `true`)
168 177
       #
169 178
       # @todo Can we kill `:hint_class` & `:error_class`? What's the use case for input-by-input? Shift to config or burn!
170  
-      # @todo Can we kill `:group_by` & `:group_label_method`? Should be done with :collection => grouped_options_for_select(...)
  179
+      # @todo Can we kill `:group_by` & `:group_label`/`:group_label_method`? Should be done with :collection => grouped_options_for_select(...)
171 180
       # @todo Can we kill `:find_options`? Should be done with MyModel.some_scope.where(...).order(...).whatever_scope
172 181
       # @todo Can we kill `:label`, `:hint` & `:prompt`? All strings could be shifted to i18n!
173 182
       #
11  lib/formtastic/inputs/base.rb
@@ -11,6 +11,17 @@ def initialize(builder, template, object, object_name, method, options)
11 11
         @object_name = object_name
12 12
         @method = method
13 13
         @options = options.dup
  14
+        
  15
+        warn_and_correct_option!(:label_method, :member_label)
  16
+        warn_and_correct_option!(:value_method, :member_value)
  17
+        warn_and_correct_option!(:group_label_method, :group_label)
  18
+      end
  19
+      
  20
+      def warn_and_correct_option!(old_option_name, new_option_name)
  21
+        if options.key?(old_option_name)
  22
+          ::ActiveSupport::Deprecation.warn("The :#{old_option_name} option is deprecated in favour of :#{new_option_name} and will be removed from Formtastic after 2.0")
  23
+          options[new_option_name] = options.delete(old_option_name)
  24
+        end
14 25
       end
15 26
       
16 27
       extend ActiveSupport::Autoload
6  lib/formtastic/inputs/base/collections.rb
@@ -24,8 +24,8 @@ def label_and_value_method(_collection, grouped=false)
24 24
           end
25 25
       
26 26
           # Order of preference: user supplied method, class defaults, auto-detect
27  
-          label = (grouped ? options[:grouped_label_method] : options[:label_method]) || label || builder.collection_label_methods.find { |m| sample.respond_to?(m) }
28  
-          value = (grouped ? options[:grouped_value_method] : options[:value_method]) || value || builder.collection_value_methods.find { |m| sample.respond_to?(m) }
  27
+          label = (grouped ? options[:grouped_label_method] : options[:member_label]) || label || builder.collection_label_methods.find { |m| sample.respond_to?(m) }
  28
+          value = (grouped ? options[:grouped_value_method] : options[:member_value]) || value || builder.collection_value_methods.find { |m| sample.respond_to?(m) }
29 29
       
30 30
           [label, value]
31 31
         end
@@ -41,7 +41,7 @@ def collection
41 41
           # Return if we have an Array of strings, fixnums or arrays
42 42
           return raw_collection if (raw_collection.instance_of?(Array) || raw_collection.instance_of?(Range)) &&
43 43
                                [Array, Fixnum, String, Symbol].include?(raw_collection.first.class) &&
44  
-                               !(options.include?(:label_method) || options.include?(:value_method))
  44
+                               !(options.include?(:member_label) || options.include?(:member_value))
45 45
                        
46 46
           raw_collection.map { |o| [send_or_call(label_method, o), send_or_call(value_method, o)] }
47 47
         end
2  lib/formtastic/inputs/base/grouped_collections.rb
@@ -16,7 +16,7 @@ def group_label_method
16 16
         end
17 17
       
18 18
         def group_label_method_from_options
19  
-          options[:group_label_method]
  19
+          options[:group_label]
20 20
         end
21 21
       
22 22
         def group_label_method_from_grouped_collection
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, :value_method, :label_method, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
  11
+          [:priority_countries, :priority_zones, :value_method, :label_method, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
12 12
         end
13 13
       
14 14
       end
28  lib/formtastic/inputs/check_boxes_input.rb
@@ -52,23 +52,23 @@ module Inputs
52 52
     # @example `:disabled` can be used to disable any checkboxes with a value found in the given Array
53 53
     #   <%= f.input :categories, :as => :check_boxes, :collection => ["a", "b"], :disabled => ["a"] %>
54 54
     #
55  
-    # @example `:label_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
56  
-    #   <%= f.input :categories, :as => :check_boxes, :label_method => :name %>
57  
-    #   <%= f.input :categories, :as => :check_boxes, :label_method => :name_with_post_count
58  
-    #   <%= f.input :categories, :as => :check_boxes, :label_method => { |c| "#{c.name} (#{pluralize("post", c.posts.count)})" }
  55
+    # @example `:member_label` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
  56
+    #   <%= f.input :categories, :as => :check_boxes, :member_label => :name %>
  57
+    #   <%= f.input :categories, :as => :check_boxes, :member_label => :name_with_post_count
  58
+    #   <%= f.input :categories, :as => :check_boxes, :member_label => { |c| "#{c.name} (#{pluralize("post", c.posts.count)})" }
59 59
     #
60  
-    # @example `:label_method` can be used with a helper method (both examples have the same result)
61  
-    #   <%= f.input :categories, :as => :check_boxes, :label_method => method(:fancy_label)
62  
-    #   <%= f.input :categories, :as => :check_boxes, :label_method => Proc.new { |category| fancy_label(category) }
  60
+    # @example `:member_label` can be used with a helper method (both examples have the same result)
  61
+    #   <%= f.input :categories, :as => :check_boxes, :member_label => method(:fancy_label)
  62
+    #   <%= f.input :categories, :as => :check_boxes, :member_label => Proc.new { |category| fancy_label(category) }
63 63
     #
64  
-    # @example `:value_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
65  
-    #   <%= f.input :categories, :as => :check_boxes, :value_method => :code %>
66  
-    #   <%= f.input :categories, :as => :check_boxes, :value_method => :isbn
67  
-    #   <%= f.input :categories, :as => :check_boxes, :value_method => Proc.new { |c| c.name.downcase.underscore }
  64
+    # @example `:member_value` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
  65
+    #   <%= f.input :categories, :as => :check_boxes, :member_value => :code %>
  66
+    #   <%= f.input :categories, :as => :check_boxes, :member_value => :isbn
  67
+    #   <%= f.input :categories, :as => :check_boxes, :member_value => Proc.new { |c| c.name.downcase.underscore }
68 68
     #
69  
-    # @example `:value_method` can be used with a helper method (both examples have the same result)
70  
-    #   <%= f.input :categories, :as => :check_boxes, :value_method => method(:some_helper)
71  
-    #   <%= f.input :categories, :as => :check_boxes, :value_method => Proc.new { |category| some_helper(category) }
  69
+    # @example `:member_value` can be used with a helper method (both examples have the same result)
  70
+    #   <%= f.input :categories, :as => :check_boxes, :member_value => method(:some_helper)
  71
+    #   <%= f.input :categories, :as => :check_boxes, :member_value => Proc.new { |category| some_helper(category) }
72 72
     #
73 73
     # @example `:value_as_class` can be used to add a class to the `<li>` wrapped around each choice using the checkbox value for custom styling of each choice
74 74
     #   <%= f.input :categories, :as => :check_boxes, :value_as_class => true %>
28  lib/formtastic/inputs/radio_input.rb
@@ -32,7 +32,7 @@ module Inputs
32 32
     # You can override or customise this collection through the `:collection` option (see examples).
33 33
     #
34 34
     # The way on which Formtastic renders the `value` attribute and label for each choice is
35  
-    # customisable through the `:label_method` and `:value_method` options (see examples below).
  35
+    # customisable through the `:member_label` and `:member_value` options (see examples below).
36 36
     # When not provided, we fall back to a list of methods to try on each object such as
37 37
     # `:to_label`, `:name` and `:to_s`, which are defined in the configurations
38 38
     # `collection_label_methods` and `collection_value_methods`.
@@ -85,22 +85,22 @@ module Inputs
85 85
     #   <%= f.input :author, :as => :radio, :collection => [["Justin", 1], ["Kate", 3]] %>
86 86
     #   <%= f.input :author, :as => :radio, :collection => 1..5 %>
87 87
     #
88  
-    # @example The `:label_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
89  
-    #   <%= f.input :author, :as => :radio, :label_method => :name %>
90  
-    #   <%= f.input :author, :as => :radio, :label_method => :name_with_post_count
91  
-    #   <%= f.input :author, :as => :radio, :label_method => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
  88
+    # @example The `:member_label` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
  89
+    #   <%= f.input :author, :as => :radio, :member_label => :name %>
  90
+    #   <%= f.input :author, :as => :radio, :member_label => :name_with_post_count
  91
+    #   <%= f.input :author, :as => :radio, :member_label => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
92 92
     #
93  
-    # @example `:label_method` can be used with a helper method (both examples have the same result)
94  
-    #   <%= f.input :author, :as => :radio, :label_method => method(:fancy_label)
95  
-    #   <%= f.input :author, :as => :radio, :label_method => Proc.new { |author| fancy_label(author) }
  93
+    # @example `:member_label` can be used with a helper method (both examples have the same result)
  94
+    #   <%= f.input :author, :as => :radio, :member_label => method(:fancy_label)
  95
+    #   <%= f.input :author, :as => :radio, :member_label => Proc.new { |author| fancy_label(author) }
96 96
     #
97  
-    # @example The `:value_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
98  
-    #   <%= f.input :author, :as => :radio, :value_method => :login %>
99  
-    #   <%= f.input :author, :as => :radio, :value_method => Proc.new { |c| c.full_name.downcase.underscore }
  97
+    # @example The `:member_value` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
  98
+    #   <%= f.input :author, :as => :radio, :member_value => :login %>
  99
+    #   <%= f.input :author, :as => :radio, :member_value => Proc.new { |c| c.full_name.downcase.underscore }
100 100
     #
101  
-    # @example `:value_method` can be used with a helper method (both examples have the same result)
102  
-    #   <%= f.input :author, :as => :radio, :value_method => method(:some_helper)
103  
-    #   <%= f.input :author, :as => :radio, :value_method => Proc.new { |author| some_helper(author) }
  101
+    # @example `:member_value` can be used with a helper method (both examples have the same result)
  102
+    #   <%= f.input :author, :as => :radio, :member_value => method(:some_helper)
  103
+    #   <%= f.input :author, :as => :radio, :member_value => Proc.new { |author| some_helper(author) }
104 104
     #
105 105
     # @example Set HTML attributes on each `<input type="radio">` tag with `:input_html`
106 106
     #   <%= f.input :author, :as => :radio, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
18  lib/formtastic/inputs/select_input.rb
@@ -33,7 +33,7 @@ module Inputs
33 33
     # the `:collection` option (see examples).
34 34
     #
35 35
     # The way on which Formtastic renders the `value` attribute and content of each `<option>` tag
36  
-    # is customisable through the `:label_method` and `:value_method` options. When not provided,
  36
+    # is customisable through the `:member_label` and `:member_value` options. When not provided,
37 37
     # we fall back to a list of methods to try on each object such as `:to_label`, `:name` and
38 38
     # `:to_s`, which are defined in the configurations `collection_label_methods` and
39 39
     # `collection_value_methods` (see examples below).
@@ -106,14 +106,14 @@ module Inputs
106 106
     #   <%= f.input :author, :as => :select, :collection => grouped_options_for_select(...) %>
107 107
     #   <%= f.input :author, :as => :select, :collection => time_zone_options_for_select(...) %>
108 108
     #
109  
-    # @example The `:label_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
110  
-    #   <%= f.input :author, :as => :select, :label_method => :name %>
111  
-    #   <%= f.input :author, :as => :select, :label_method => :name_with_post_count
112  
-    #   <%= f.input :author, :as => :select, :label_method => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
  109
+    # @example The `:member_label` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
  110
+    #   <%= f.input :author, :as => :select, :member_label => :name %>
  111
+    #   <%= f.input :author, :as => :select, :member_label => :name_with_post_count
  112
+    #   <%= f.input :author, :as => :select, :member_label => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
113 113
     #
114  
-    # @example The `:value_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
115  
-    #   <%= f.input :author, :as => :select, :value_method => :login %>
116  
-    #   <%= f.input :author, :as => :select, :value_method => Proc.new { |c| c.full_name.downcase.underscore }
  114
+    # @example The `:member_value` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
  115
+    #   <%= f.input :author, :as => :select, :member_value => :login %>
  116
+    #   <%= f.input :author, :as => :select, :member_value => Proc.new { |c| c.full_name.downcase.underscore }
117 117
     #
118 118
     # @example Set HTML attributes on the `<select>` tag with `:input_html`
119 119
     #   <%= f.input :authors, :as => :select, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
@@ -126,7 +126,7 @@ module Inputs
126 126
     #   <%= f.input :author, :as => :select, :input_html => { :include_blank => true } %>
127 127
     #   <%= f.input :author, :as => :select, :input_html => { :prompt => "Please select an Author..." } %>
128 128
     #
129  
-    # @example Group options an `<optgroup>` with the `:group_by` and `:group_label_method` options (`belongs_to` associations only)
  129
+    # @example Group options an `<optgroup>` with the `:group_by` and `:group_label` options (`belongs_to` associations only)
130 130
     #   <%= f.input :author, :as => :select, :group_by => :continent %>
131 131
     #
132 132
     # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documetation of all possible options.
4  spec/inputs/check_boxes_input_spec.rb
@@ -332,7 +332,7 @@
332 332
   end
333 333
 
334 334
   describe 'for an association when a :collection is provided' do
335  
-    describe 'it should use the specified :value_method option' do
  335
+    describe 'it should use the specified :member_value option' do
336 336
       before do
337 337
         @output_buffer = ''
338 338
         mock_everything
@@ -345,7 +345,7 @@
345 345
         item.should_receive(:custom_value).exactly(3).times
346 346
         @new_post.author.should_receive(:custom_value).exactly(3).times
347 347
         concat(semantic_form_for(@new_post) do |builder|
348  
-          concat(builder.input(:author, :as => :check_boxes, :value_method => :custom_value, :collection => [item, item, item]))
  348
+          concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
349 349
         end)
350 350
         output_buffer.should have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
351 351
       end
4  spec/inputs/label_spec.rb
@@ -36,14 +36,14 @@
36 36
   describe 'when a collection is given' do
37 37
     it 'should use a supplied label_method for simple collections' do
38 38
       concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
39  
-        concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :value_method => :to_s, :label_method => proc {|f| ('Label_%s' % [f])}))
  39
+        concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => :to_s, :member_label => proc {|f| ('Label_%s' % [f])}))
40 40
       end)
41 41
       output_buffer.should have_tag('form li fieldset ol li label', /Label_[abc]/, :count => 3)
42 42
     end
43 43
 
44 44
     it 'should use a supplied value_method for simple collections' do
45 45
       concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
46  
-        concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :value_method => proc {|f| ('Value_%s' % [f.to_s])}))
  46
+        concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :member_value => proc {|f| ('Value_%s' % [f.to_s])}))
47 47
       end)
48 48
       output_buffer.should have_tag('form li fieldset ol li label input[value="Value_a"]')
49 49
       output_buffer.should have_tag('form li fieldset ol li label input[value="Value_b"]')
6  spec/inputs/select_input_spec.rb
@@ -243,9 +243,9 @@
243 243
 
244 244
       concat(semantic_form_for(@new_post) do |builder|
245 245
         concat(builder.input(:author, :as => :select, :group_by => :continent ) )
246  
-        concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label_method => :id ) )
247  
-        concat(builder.input(:author, :as => :select, :group_by => :continent, :label_method => :login ) )
248  
-        concat(builder.input(:author, :as => :select, :group_by => :continent, :label_method => :login, :group_label_method => :id ) )
  246
+        concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
  247
+        concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
  248
+        concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
249 249
       end)
250 250
     end
251 251
 
152  spec/support/custom_macros.rb
@@ -378,12 +378,12 @@ def it_should_use_the_collection_when_provided(as, countable)
378 378
 
379 379
         end
380 380
 
381  
-        describe 'when the :label_method option is provided' do
  381
+        describe 'when the :member_label option is provided' do
382 382
 
383 383
           describe 'as a symbol' do
384 384
             before do
385 385
               concat(semantic_form_for(@new_post) do |builder|
386  
-                concat(builder.input(:author, :as => as, :label_method => :login))
  386
+                concat(builder.input(:author, :as => as, :member_label => :login))
387 387
               end)
388 388
             end
389 389
 
@@ -397,7 +397,7 @@ def it_should_use_the_collection_when_provided(as, countable)
397 397
           describe 'as a proc' do
398 398
             before do
399 399
               concat(semantic_form_for(@new_post) do |builder|
400  
-                concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
  400
+                concat(builder.input(:author, :as => as, :member_label => Proc.new {|a| a.login.reverse }))
401 401
               end)
402 402
             end
403 403
 
@@ -414,7 +414,7 @@ def reverse_login(a)
414 414
                 a.login.reverse
415 415
               end
416 416
               concat(semantic_form_for(@new_post) do |builder|
417  
-                concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
  417
+                concat(builder.input(:author, :as => as, :member_label => method(:reverse_login)))
418 418
               end)
419 419
             end
420 420
 
@@ -426,7 +426,7 @@ def reverse_login(a)
426 426
           end
427 427
         end
428 428
 
429  
-        describe 'when the :label_method option is not provided' do
  429
+        describe 'when the :member_label option is not provided' do
430 430
           Formtastic::FormBuilder.collection_label_methods.each do |label_method|
431 431
 
432 432
             describe "when the collection objects respond to #{label_method}" do
@@ -449,12 +449,12 @@ def reverse_login(a)
449 449
           end
450 450
         end
451 451
 
452  
-        describe 'when the :value_method option is provided' do
  452
+        describe 'when the :member_value option is provided' do
453 453
 
454 454
           describe 'as a symbol' do
455 455
             before do
456 456
               concat(semantic_form_for(@new_post) do |builder|
457  
-                concat(builder.input(:author, :as => as, :value_method => :login))
  457
+                concat(builder.input(:author, :as => as, :member_value => :login))
458 458
               end)
459 459
             end
460 460
 
@@ -468,7 +468,7 @@ def reverse_login(a)
468 468
           describe 'as a proc' do
469 469
             before do
470 470
               concat(semantic_form_for(@new_post) do |builder|
471  
-                concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
  471
+                concat(builder.input(:author, :as => as, :member_value => Proc.new {|a| a.login.reverse }))
472 472
               end)
473 473
             end
474 474
 
@@ -485,7 +485,7 @@ def reverse_login(a)
485 485
                 a.login.reverse
486 486
               end
487 487
               concat(semantic_form_for(@new_post) do |builder|
488  
-                concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
  488
+                concat(builder.input(:author, :as => as, :member_value => method(:reverse_login)))
489 489
               end)
490 490
             end
491 491
 
@@ -497,6 +497,140 @@ def reverse_login(a)
497 497
           end
498 498
         end
499 499
 
  500
+        describe 'when the deprecated :label_method option is provided' do
  501
+          
  502
+          describe 'as a symbol' do
  503
+            before do
  504
+              with_deprecation_silenced do
  505
+                concat(semantic_form_for(@new_post) do |builder|
  506
+                  concat(builder.input(:author, :as => as, :label_method => :login))
  507
+                end)
  508
+              end
  509
+            end
  510
+
  511
+            it 'should have options with text content from the specified method' do
  512
+              ::Author.all.each do |author|
  513
+                output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
  514
+              end
  515
+            end
  516
+          end
  517
+
  518
+          describe 'as a proc' do
  519
+            
  520
+            before do
  521
+              with_deprecation_silenced do
  522
+                concat(semantic_form_for(@new_post) do |builder|
  523
+                  concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
  524
+                end)
  525
+              end
  526
+            end
  527
+
  528
+            it 'should have options with the proc applied to each' do
  529
+              ::Author.all.each do |author|
  530
+                output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
  531
+              end
  532
+            end
  533
+          end
  534
+
  535
+          describe 'as a method object' do
  536
+            before do
  537
+              def reverse_login(a)
  538
+                a.login.reverse
  539
+              end
  540
+              with_deprecation_silenced do 
  541
+                concat(semantic_form_for(@new_post) do |builder|
  542
+                  concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
  543
+                end)
  544
+              end
  545
+            end
  546
+
  547
+            it 'should have options with the proc applied to each' do
  548
+              ::Author.all.each do |author|
  549
+                output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
  550
+              end
  551
+            end
  552
+          end
  553
+        end
  554
+
  555
+        describe 'when the deprecated :label_method option is not provided' do
  556
+          Formtastic::FormBuilder.collection_label_methods.each do |label_method|
  557
+
  558
+            describe "when the collection objects respond to #{label_method}" do
  559
+              before do
  560
+                @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
  561
+                ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
  562
+
  563
+                with_deprecation_silenced do 
  564
+                  concat(semantic_form_for(@new_post) do |builder|
  565
+                    concat(builder.input(:author, :as => as))
  566
+                  end)
  567
+                end
  568
+              end
  569
+
  570
+              it "should render the options with #{label_method} as the label" do
  571
+                ::Author.all.each do |author|
  572
+                  output_buffer.should have_tag("form li.#{as}", /The Label Text/)
  573
+                end
  574
+              end
  575
+            end
  576
+
  577
+          end
  578
+        end
  579
+
  580
+        describe 'when the deprecated :value_method option is provided' do
  581
+
  582
+          describe 'as a symbol' do
  583
+            before do
  584
+              with_deprecation_silenced do 
  585
+                concat(semantic_form_for(@new_post) do |builder|
  586
+                  concat(builder.input(:author, :as => as, :value_method => :login))
  587
+                end)
  588
+              end
  589
+            end
  590
+
  591
+            it 'should have options with values from specified method' do
  592
+              ::Author.all.each do |author|
  593
+                output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
  594
+              end
  595
+            end
  596
+          end
  597
+
  598
+          describe 'as a proc' do
  599
+            before do
  600
+              with_deprecation_silenced do 
  601
+                concat(semantic_form_for(@new_post) do |builder|
  602
+                  concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
  603
+                end)
  604
+              end
  605
+            end
  606
+
  607
+            it 'should have options with the proc applied to each value' do
  608
+              ::Author.all.each do |author|
  609
+                output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
  610
+              end
  611
+            end
  612
+          end
  613
+
  614
+          describe 'as a method object' do
  615
+            before do
  616
+              def reverse_login(a)
  617
+                a.login.reverse
  618
+              end
  619
+              with_deprecation_silenced do 
  620
+                concat(semantic_form_for(@new_post) do |builder|
  621
+                  concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
  622
+                end)
  623
+              end
  624
+            end
  625
+
  626
+            it 'should have options with the proc applied to each value' do
  627
+              ::Author.all.each do |author|
  628
+                output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
  629
+              end
  630
+            end
  631
+          end
  632
+        end
  633
+
500 634
       end
501 635
     end
502 636
 

0 notes on commit 8d4d9ed

Please sign in to comment.
Something went wrong with that request. Please try again.