test/xml_test.rb in representable-0.9.0 vs test/xml_test.rb in representable-0.9.1
- old
+ new
@@ -20,10 +20,19 @@
class XmlTest < MiniTest::Spec
XML = Representable::XML
Def = Representable::Definition
describe "Xml module" do
+ before do
+ @Band = Class.new do
+ include Representable::XML
+ self.representation_name= :band
+ representable_property :name
+ representable_property :label
+ end
+ end
+
class Band
include Representable::XML
representable_property :href, :from => "@href"
representable_property :title, :from => "@title"
end
@@ -32,22 +41,37 @@
assert_equal XML::Definition, Band.definition_class
end
describe "#binding_for_definition" do
it "returns AttributeBinding" do
- assert_kind_of XML::AttributeBinding, XML.binding_for_definition(Def.new(:band, :from => "@band"))
+ assert_kind_of XML::AttributeBinding, Band.binding_for_definition(Def.new(:band, :from => "@band"))
end
it "returns ObjectBinding" do
- assert_kind_of XML::ObjectBinding, XML.binding_for_definition(Def.new(:band, :as => Hash))
+ assert_kind_of XML::ObjectBinding, Band.binding_for_definition(Def.new(:band, :as => Hash))
end
- #it "returns NamespaceBinding" do
- # assert_kind_of Xml::AttributeBinding, Xml.binding_for_definition(Def.new(:band, :from => "@band"))
- #end
-
it "returns TextBinding" do
- assert_kind_of XML::TextBinding, XML.binding_for_definition(Def.new(:band, :from => :content))
+ assert_kind_of XML::TextBinding, Band.binding_for_definition(Def.new(:band, :from => :content))
+ end
+ end
+
+ describe "#from_xml" do
+ before do
+ @band = @Band.new
+ end
+
+ it "accepts xml string" do
+ @band.from_xml(%{<band><name>Nofx</name><label>NOFX</label></band>})
+ assert_equal ["Nofx", "NOFX"], [@band.name, @band.label]
+ end
+
+ it "forwards block to #update_properties_from" do
+ @band.from_xml(%{<band><name>Nofx</name><label>NOFX</label></band>}) do |binding|
+ binding.definition.name == "name"
+ end
+
+ assert_equal ["Nofx", nil], [@band.name, @band.label]
end
end
end
end