Skip to content

Commit

Permalink
skip rendering of links that are nil/false.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Mar 22, 2012
1 parent 7cdfd8e commit f20aa08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/roar/representer/feature/hypermedia.rb
Expand Up @@ -44,7 +44,7 @@ def prepare_links!

links_def.rel2block.each do |config| # config is [{..}, block]
options = config.first
options[:href] = run_link_block(config.last)
options[:href] = run_link_block(config.last) or next

links.update_link(Feature::Hypermedia::Hyperlink.new(options))
end
Expand Down
11 changes: 11 additions & 0 deletions test/json_representer_test.rb
Expand Up @@ -120,6 +120,17 @@ class JsonHypermediaTest
it "renders link: correctly in JSON" do
assert_equal "{\"id\":1,\"links\":[{\"rel\":\"self\",\"href\":\"http://self\"},{\"rel\":\"next\",\"href\":\"http://next/1\"}]}", @c.new(:id => 1).to_json
end

it "doesn't render links when empty" do
assert_equal("{\"links\":[]}", Class.new do
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia

link :self do nil end
link :next do false end
end.new.to_json)
end

end
end

0 comments on commit f20aa08

Please sign in to comment.