diff --git a/lib/oat/adapters/hal.rb b/lib/oat/adapters/hal.rb index cafdac0..c8801fb 100644 --- a/lib/oat/adapters/hal.rb +++ b/lib/oat/adapters/hal.rb @@ -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) diff --git a/spec/adapters/hal_spec.rb b/spec/adapters/hal_spec.rb index d7e557e..4aa76ca 100644 --- a/spec/adapters/hal_spec.rb +++ b/spec/adapters/hal_spec.rb @@ -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 diff --git a/spec/fixtures.rb b/spec/fixtures.rb index 7916acd..b3ffe0b 100644 --- a/spec/fixtures.rb +++ b/spec/fixtures.rb @@ -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