Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Deprecate :method, use :using instead.
  • Loading branch information
josevalim committed Jan 9, 2010
1 parent f95e2ee commit 0d7500d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Expand Up @@ -109,7 +109,7 @@ show_for also supports associations.

<% show_for @artwork do |a| %>
<%= a.association :artist %>
<%= a.association :artist, :method => :name_with_title %>
<%= a.association :artist, :using => :name_with_title %>

<%= a.association :tags %>
<%= a.association :tags, :to_sentence => true %>
Expand All @@ -125,7 +125,7 @@ show_for also supports associations.
The first is a has_one or belongs_to association, which works like an attribute
to show_for, except it will retrieve the artist association and try to find a
proper method from ShowFor.association_methods to be used. You can pass
the option :method to tell (and not guess) which method from the association
the option :using to tell (and not guess) which method from the association
to use.

:tags is a has_and_belongs_to_many association which will return a collection.
Expand Down
8 changes: 7 additions & 1 deletion lib/show_for/builder.rb
Expand Up @@ -91,7 +91,13 @@ def wrap_with(type, content, options, safe=false, concat=false) #:nodoc:

def retrieve_values_from_association(association, options) #:nodoc:
sample = association.is_a?(Array) ? association.first : association
method = options[:method] || ShowFor.association_methods.find { |m| sample.respond_to?(m) }

if options[:method]
options[:using] = options.delete(:method)
ActiveSupport::Deprecation.warn ":method is deprecated. Please use :using instead", caller
end

method = options.delete(:using) || ShowFor.association_methods.find { |m| sample.respond_to?(m) }
association.is_a?(Array) ? association.map(&method) : association.try(method)
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/builder_test.rb
Expand Up @@ -271,8 +271,8 @@ def with_content_for(object, value, options={})
assert_select "div.show_for p.wrapper", /PlataformaTec/
end

test "show_for accepts :method as option to tell how to retrieve association value" do
with_association_for @user, :company, :method => :alternate_name
test "show_for accepts :using as option to tell how to retrieve association value" do
with_association_for @user, :company, :using => :alternate_name
assert_select "div.show_for p.wrapper", /Alternate PlataformaTec/
end

Expand All @@ -284,8 +284,8 @@ def with_content_for(object, value, options={})
assert_select "div.show_for p.wrapper ul.collection li", "Tag 3"
end

test "show_for accepts :method as option to tell how to retrieve association values" do
with_association_for @user, :tags, :method => :alternate_name
test "show_for accepts :using as option to tell how to retrieve association values" do
with_association_for @user, :tags, :using => :alternate_name
assert_select "div.show_for p.wrapper ul.collection"
assert_select "div.show_for p.wrapper ul.collection li", "Alternate Tag 1"
assert_select "div.show_for p.wrapper ul.collection li", "Alternate Tag 2"
Expand Down

0 comments on commit 0d7500d

Please sign in to comment.