Skip to content

Commit

Permalink
make sure Representer::representable_attrs is overridden so we have C…
Browse files Browse the repository at this point in the history
…onfig#inheritable_arrays everywhere. time to extract that to a separate gem. hopefully fixes #66 (@Nerian ???).
  • Loading branch information
apotonick committed Apr 30, 2013
1 parent 03a76b0 commit 7b56318
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/roar/representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def inheritable_arrays

def inherit(parent)
super

parent.inheritable_arrays.keys.each do |k|
inheritable_array(k).push *parent.inheritable_array(k).clone
end
Expand All @@ -30,11 +30,13 @@ def inherit(parent)
def self.included(base)
base.class_eval do
include Representable
extend InheritableArray # this adds InheritableArray::representable_attrs to the module, e.g. when a representer includes a representer, we don't work with the instance method, yet.
end
end

include InheritableArray


private
def before_serialize(*)
end
Expand Down
29 changes: 19 additions & 10 deletions test/hypermedia_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,32 @@ def representer_for(modules=[Roar::Representer::Feature::Hypermedia, Representab
end)

parent.representable_attrs.inheritable_array(:links) << "park" # modify parent array.

end.representable_attrs.inheritable_array(:links).must_equal(["bar", "stadium"])
end

it "doesn't mess up with inheritable_array" do # FIXME: remove this test when uber is out.
OpenStruct.new.extend( Module.new do
include Roar::Representer::JSON
include Module.new do
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia

property :bla

link( :self) {"bo"}
end
include(Module.new do
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia

property :bla

link( :self) {"bo"}

#puts "hey ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
#puts representable_attrs.inheritable_array(:links).inspect
end)


#puts representable_attrs.inheritable_array(:links).inspect

property :blow
end).to_json
include Roar::Representer::Feature::Hypermedia
link(:bla) { "boo" }
end).to_hash.must_equal({"links"=>[{:rel=>:self, :href=>"bo"}, {:rel=>:bla, :href=>"boo"}]})


end
Expand Down

0 comments on commit 7b56318

Please sign in to comment.