Skip to content

Commit

Permalink
Merge pull request #52 from nashby/fix-issue-50
Browse files Browse the repository at this point in the history
handle belongs_to association with a block
  • Loading branch information
rafaelfranca committed Oct 15, 2012
2 parents 4b124fe + 2bca8c9 commit e76283d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/show_for/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def content(value, options={}, apply_options=true, &block)
when NilClass, Numeric
value.to_s
else
value
if block
template.capture(value, &block)
else
value
end
end

options[:content_html] = options.except(:content_tag) if apply_options
Expand Down
8 changes: 8 additions & 0 deletions test/association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def @user.tags
end
end

test "show_for accepts a block with an argument in belongs_to associations" do
with_association_for @user, :company do |company|
company.name.upcase
end

assert_select "div.show_for p.wrapper", /PLATAFORMATEC/
end

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"
Expand Down

0 comments on commit e76283d

Please sign in to comment.