Skip to content

Commit

Permalink
Merge pull request #8 from shekibobo/feature/handle-null-hrefs
Browse files Browse the repository at this point in the history
Don't add invalid link relations to HAL output
  • Loading branch information
Ismael Celis committed Jan 26, 2014
2 parents 5fea9f9 + 43c658d commit d4433b5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/oat/adapters/hal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Oat
module Adapters
class HAL < Oat::Adapter
def link(rel, opts = {})
data[:_links][rel] = opts
data[:_links][rel] = opts if opts[:href]
end

def properties(&block)
Expand Down
2 changes: 2 additions & 0 deletions spec/adapters/hal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
h[:controller_name].should == 'some_controller'
# links
h[:_links][:self][:href].should == "http://foo.bar.com/#{user.id}"
# HAL Spec says href is REQUIRED
h[:_links].should_not include(:empty)
# embedded manager
h[:_embedded][:manager].tap do |m|
m[:id].should == manager.id
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.included(base)
schema do
type 'user'
link :self, href: url_for(item.id)
link :empty, href: nil

property :id, item.id
map_properties :name, :age
Expand Down

0 comments on commit d4433b5

Please sign in to comment.