test/nested_test.rb in representable-1.7.6 vs test/nested_test.rb in representable-1.7.7

- old
+ new

@@ -1,97 +1,79 @@ require 'test_helper' class NestedTest < MiniTest::Spec - Album = Struct.new(:label, :owner) + Album = Struct.new(:label, :owner, :amount) for_formats( - :hash => [Representable::Hash, {"label" => {"label"=>"Epitaph", "owner"=>"Brett Gurewitz"}}], + :hash => [Representable::Hash, {"label" => {"label"=>"Epitaph", "owner"=>"Brett Gurewitz", "releases"=>{"amount"=>19}}}], # :xml => [Representable::XML, "<open_struct></open_struct>"], - :yaml => [Representable::YAML, "---\nlabel:\n label: Epitaph\n owner: Brett Gurewitz\n"] + :yaml => [Representable::YAML, "---\nlabel:\n label: Epitaph\n owner: Brett Gurewitz\n releases:\n amount: 19\n"] ) do |format, mod, output, input| - # describe "::nested with inline representer" do - # let (:format) { format } + [false, true].each do |is_decorator| + describe "::nested with (inline representer|decorator): #{is_decorator}" do + let (:format) { format } - # representer!(:module => mod) do - # nested :label do - # property :label - # property :owner + representer!(:module => mod, :decorator => is_decorator) do + nested :label do + property :label + property :owner - # # self.representation_wrap = nil if format == :xml - # end + # self.representation_wrap = nil if format == :xml + nested :releases do + property :amount + end + end + # self.representation_wrap = :album if format == :xml + end - # self.representation_wrap = :album if format == :xml - # end + let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) } - # let (:album) { Album.new("Epitaph", "Brett Gurewitz").extend(representer) } + it "renders nested Album-properties in separate section" do + render(album).must_equal_document output + end - # it "renders nested Album-properties in separate section" do - # render(album).must_equal_document output - # end + it "parses nested properties to Album instance" do + album = parse(representer.prepare(Album.new), output) + album.label.must_equal "Epitaph" + album.owner.must_equal "Brett Gurewitz" + end + end + end - # it "parses nested properties to Album instance" do - # album = parse(Album.new.extend(representer), output) - # album.label.must_equal "Epitaph" - # album.owner.must_equal "Brett Gurewitz" - # end - # end describe "Decorator ::nested with extend:" do let (:format) { format } representer!(:name => :label_rpr) do include mod property :label property :owner + + nested :releases do # DISCUSS: do we need to test this? + property :amount + end end representer!(:module => mod, :decorator => true, :inject => :label_rpr) do nested :label, :extend => label_rpr self.representation_wrap = :album if format == :xml end - let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz")) } + let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz", 19)) } # TODO: shared example with above. it "renders nested Album-properties in separate section" do render(album).must_equal_document output end it "parses nested properties to Album instance" do album = parse(representer.prepare(Album.new), output) album.label.must_equal "Epitaph" album.owner.must_equal "Brett Gurewitz" - end - end - - describe "Decorator ::nested" do - let (:format) { format } - - representer!(:module => mod, :decorator => true) do - nested :label do - property :label - property :owner - - # self.representation_wrap = nil if format == :xml - end - - - self.representation_wrap = :album if format == :xml - end - - let (:album) { representer.prepare(Album.new("Epitaph", "Brett Gurewitz")) } - - it "renders nested Album-properties in separate section" do - render(album).must_equal_document output - end - - it "parses nested properties to Album instance" do - album = parse(representer.prepare(Album.new), output) - album.label.must_equal "Epitaph" - album.owner.must_equal "Brett Gurewitz" + album.amount.must_equal 19 end end end end \ No newline at end of file