Skip to content

Commit

Permalink
Removed deprecated :label_method, :value_method & :group_label_method…
Browse files Browse the repository at this point in the history
… options.
  • Loading branch information
justinfrench committed Oct 25, 2011
1 parent 8228f1f commit b926118
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 148 deletions.
11 changes: 1 addition & 10 deletions lib/formtastic/helpers/input_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,9 @@ module InputHelper
# @option options :member_label [Symbol, Proc, Method]
# 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)
#
# @option options :label_method [Symbol, Proc, Method]
# Deprecated, renamed to :member_label
#
# @option options :member_value [Symbol, Proc, Method]
# 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)
#
# @option options :value_method [Symbol, Proc, Method]
# Deprecated, renamed to :member_value
#
# @option options :hint_class [String]
# Override the `class` attribute applied to the `<p>` tag used when a `:hint` is rendered for an input
#
Expand All @@ -164,9 +158,6 @@ module InputHelper
# @option options :find_options [Symbol]
# TODO will probably be deprecated
#
# @option options :group_label_method [Symbol]
# Deprecated, use `:group_label`
#
# @option options :group_label [Symbol]
# TODO will probably be deprecated
#
Expand All @@ -177,7 +168,7 @@ module InputHelper
# Specify the text in the first ('blank') `:select` input `<option>` to prompt a user to make a selection (implicitly sets `:include_blank` to `true`)
#
# @todo Can we kill `:hint_class` & `:error_class`? What's the use case for input-by-input? Shift to config or burn!
# @todo Can we kill `:group_by` & `:group_label`/`:group_label_method`? Should be done with :collection => grouped_options_for_select(...)
# @todo Can we kill `:group_by` & `:group_label`? Should be done with :collection => grouped_options_for_select(...)
# @todo Can we kill `:find_options`? Should be done with MyModel.some_scope.where(...).order(...).whatever_scope
# @todo Can we kill `:label`, `:hint` & `:prompt`? All strings could be shifted to i18n!
#
Expand Down
12 changes: 9 additions & 3 deletions lib/formtastic/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ def initialize(builder, template, object, object_name, method, options)
@method = method
@options = options.dup

warn_and_correct_option!(:label_method, :member_label)
warn_and_correct_option!(:value_method, :member_value)
warn_and_correct_option!(:group_label_method, :group_label)
removed_option!(:label_method)
removed_option!(:value_method)
removed_option!(:group_label_method)
end

# Usefull for deprecating options.
def warn_and_correct_option!(old_option_name, new_option_name)
if options.key?(old_option_name)
::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")
options[new_option_name] = options.delete(old_option_name)
end
end

# Usefull for raising an error on previously supported option.
def removed_option!(old_option_name)
raise ArgumentError, ":#{old_option_name} is no longer available" if options.key?(old_option_name)
end

extend ActiveSupport::Autoload

autoload :Associations
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/base/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def input_options
end

def formtastic_options
[: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]
[:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
end

end
Expand Down
134 changes: 0 additions & 134 deletions spec/support/custom_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,140 +521,6 @@ def reverse_login(a)
end
end

describe 'when the deprecated :label_method option is provided' do

describe 'as a symbol' do
before do
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :label_method => :login))
end)
end
end

it 'should have options with text content from the specified method' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
end
end
end

describe 'as a proc' do

before do
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
end)
end
end

it 'should have options with the proc applied to each' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
end
end
end

describe 'as a method object' do
before do
def reverse_login(a)
a.login.reverse
end
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
end)
end
end

it 'should have options with the proc applied to each' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
end
end
end
end

describe 'when the deprecated :label_method option is not provided' do
Formtastic::FormBuilder.collection_label_methods.each do |label_method|

describe "when the collection objects respond to #{label_method}" do
before do
@fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }

with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as))
end)
end
end

it "should render the options with #{label_method} as the label" do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as}", /The Label Text/)
end
end
end

end
end

describe 'when the deprecated :value_method option is provided' do

describe 'as a symbol' do
before do
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :value_method => :login))
end)
end
end

it 'should have options with values from specified method' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
end
end
end

describe 'as a proc' do
before do
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
end)
end
end

it 'should have options with the proc applied to each value' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
end
end
end

describe 'as a method object' do
before do
def reverse_login(a)
a.login.reverse
end
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
end)
end
end

it 'should have options with the proc applied to each value' do
::Author.all.each do |author|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
end
end
end
end

end
end

Expand Down

0 comments on commit b926118

Please sign in to comment.