test/xml_bindings_test.rb in representable-2.0.4 vs test/xml_bindings_test.rb in representable-2.1.0

- old
+ new

@@ -21,124 +21,17 @@ before do @doc = Nokogiri::XML::Document.new @song = SongWithRepresenter.new("Thinning the Herd") end - describe "PropertyBinding" do - describe "with plain text" do - before do - @property = Representable::XML::PropertyBinding.new(Representable::Definition.new(:song), nil, nil, {:doc => @doc}) - end - it "extracts with #read" do - assert_equal "Thinning the Herd", @property.read(Nokogiri::XML("<song>Thinning the Herd</song>")) - end - it "inserts with #write" do - @property.write(@doc, "Thinning the Herd") - assert_xml_equal "<song>Thinning the Herd</song>", @doc.to_s - end - end - describe "with an object" do - before do - @property = Representable::XML::PropertyBinding.new(Representable::Definition.new(:song, :class => SongWithRepresenter), nil, nil, {:doc => @doc}) - end - - it "extracts with #read" do - assert_equal @song, @property.read(Nokogiri::XML("<song><name>Thinning the Herd</name></song>")) - end - - it "inserts with #write" do - @property.write(@doc, @song) - assert_xml_equal("<song><name>Thinning the Herd</name></song>", @doc.to_s) - end - end - - describe "with an object and :extend" do - before do - @property = Representable::XML::PropertyBinding.new(Representable::Definition.new(:song, :class => Song, :extend => SongRepresenter), nil, nil, {:doc => @doc}) - end - - it "extracts with #read" do - assert_equal @song, @property.read(Nokogiri::XML("<song><name>Thinning the Herd</name></song>")) - end - - it "inserts with #write" do - @property.write(@doc, @song) - assert_xml_equal("<song><name>Thinning the Herd</name></song>", @doc.to_s) - end - end - end - - - describe "CollectionBinding" do - describe "with plain text items" do - before do - @property = Representable::XML::CollectionBinding.new(Representable::Definition.new(:song, :collection => true), Struct.new(:song).new, nil) - end - - it "extracts with #read" do - assert_equal ["The Gargoyle", "Bronx"], @property.read(Nokogiri::XML("<doc><song>The Gargoyle</song><song>Bronx</song></doc>").root) - end - - it "inserts with #write" do - parent = Nokogiri::XML::Node.new("parent", @doc) - @property.write(parent, ["The Gargoyle", "Bronx"]) - assert_xml_equal("<songs><song>The Gargoyle</song><song>Bronx</song></songs>", parent.to_s) - end - end - - describe "with objects" do - before do - @property = Representable::XML::PropertyBinding.new(Representable::Definition.new(:song, :collection => true, :class => SongWithRepresenter), nil, nil, {:doc => @doc}) - end - - it "extracts with #read" do - assert_equal @song, @property.read(Nokogiri::XML("<song><name>Thinning the Herd</name></song>")) - end - - it "inserts with #write" do - @property.write(@doc, @song) - assert_xml_equal("<song><name>Thinning the Herd</name></song>", @doc.to_s) - assert_kind_of Nokogiri::XML::Node, @doc.children.first - assert_equal "song", @doc.children.first.name - assert_equal "name", @doc.children.first.children.first.name - end - end - end - - - describe "HashBinding" do - describe "with plain text items" do - before do - @property = Representable::XML::HashBinding.new(Representable::Definition.new(:songs, :hash => true), nil, nil) - end - - it "extracts with #read" do - assert_equal({"first" => "The Gargoyle", "second" => "Bronx"} , @property.read(Nokogiri::XML("<songs><first>The Gargoyle</first><second>Bronx</second></songs>"))) - end - - it "inserts with #write" do - parent = Nokogiri::XML::Node.new("parent", @doc) - @property.write(parent, {"first" => "The Gargoyle", "second" => "Bronx"}) - assert_xml_equal("<songs><first>The Gargoyle</first><second>Bronx</second></songs>", parent.to_s) - end - end - - describe "with objects" do - before do - @property = Representable::XML::HashBinding.new(Representable::Definition.new(:songs, :hash => true, :class => Song, :extend => SongRepresenter), nil) - end - end - end - - describe "AttributeBinding" do describe "with plain text items" do before do - @property = Representable::XML::AttributeBinding.new(Representable::Definition.new(:name, :attribute => true), nil, nil) + @property = Representable::XML::Binding::Attribute.new(Representable::Definition.new(:name, :attribute => true), nil, nil) end it "extracts with #read" do assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song name=\"The Gargoyle\" />").root) end @@ -151,10 +44,10 @@ end end describe "ContentBinding" do before do - @property = Representable::XML::ContentBinding.new(Representable::Definition.new(:name, :content => true), nil, nil) + @property = Representable::XML::Binding::Content.new(Representable::Definition.new(:name, :content => true), nil, nil) end it "extracts with #read" do assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song>The Gargoyle</song>").root) end