1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
require 'test_helper'
require 'representable/xml/hash'
class XMLBindingTest < Minitest::Spec
module SongRepresenter
include Representable::XML
property :name
self.representation_wrap = :song
end
class SongWithRepresenter < ::Song
include Representable
include SongRepresenter
self.representation_wrap = :song
end
before do
@doc = Nokogiri::XML::Document.new
@song = SongWithRepresenter.new("Thinning the Herd")
end
describe "AttributeBinding" do
describe "with plain text items" do
before do
@property = Representable::XML::Binding::Attribute.new(Representable::Definition.new(:name, :attribute => true))
end
it "extracts with #read" do
assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song name=\"The Gargoyle\" />").root, "name")
end
it "inserts with #write" do
parent = Nokogiri::XML::Node.new("song", @doc)
@property.write(parent, "The Gargoyle", "name")
assert_xml_equal("<song name=\"The Gargoyle\" />", parent.to_s)
end
end
end
describe "ContentBinding" do
before do
@property = Representable::XML::Binding::Content.new(Representable::Definition.new(:name, :content => true))
end
it "extracts with #read" do
assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song>The Gargoyle</song>").root, "song")
end
it "inserts with #write" do
parent = Nokogiri::XML::Node.new("song", @doc)
@property.write(parent, "The Gargoyle", "song")
assert_xml_equal("<song>The Gargoyle</song>", parent.to_s)
end
end
end
|