Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate :method, use :using instead.

  • Loading branch information...
commit 0d7500d2c3a83cf0d33a0e568c3f4aad9521e8ba 1 parent f95e2ee
@josevalim josevalim authored
Showing with 13 additions and 7 deletions.
  1. +2 −2 README.rdoc
  2. +7 −1 lib/show_for/builder.rb
  3. +4 −4 test/builder_test.rb
View
4 README.rdoc
@@ -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 %>
@@ -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.
View
8 lib/show_for/builder.rb
@@ -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
View
8 test/builder_test.rb
@@ -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
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.