spec/happymapper_spec.rb in nokogiri-happymapper-0.3.3 vs spec/happymapper_spec.rb in nokogiri-happymapper-0.3.4
- old
+ new
@@ -376,24 +376,34 @@
has_many :definitions, Definition
has_many :variants, Variant, :tag => 'var'
end
end
+module AmbigousItems
+ class Item
+ include HappyMapper
+
+ tag 'item'
+ element :name, String
+ element :item, String
+ end
+end
+
describe HappyMapper do
describe "being included into another class" do
before do
@klass = Class.new do
include HappyMapper
def self.to_s
- 'Foo'
+ 'Boo'
end
end
end
- class Foo; include HappyMapper end
+ class Boo; include HappyMapper end
it "should set attributes to an array" do
@klass.attributes.should == []
end
@@ -451,11 +461,11 @@
element.type.should == User
element.options[:single] = false
end
it "should default tag name to lowercase class" do
- @klass.tag_name.should == 'foo'
+ @klass.tag_name.should == 'boo'
end
it "should default tag name of class in modules to the last constant lowercase" do
module Bar; class Baz; include HappyMapper; end; end
Bar::Baz.tag_name.should == 'baz'
@@ -465,11 +475,11 @@
@klass.tag('FooBar')
@klass.tag_name.should == 'FooBar'
end
it "should allow setting a namespace" do
- @klass.namespace(namespace = "foo")
+ @klass.namespace(namespace = "boo")
@klass.namespace.should == namespace
end
it "should provide #parse" do
@klass.should respond_to(:parse)
@@ -729,7 +739,13 @@
@records.first.variants.first.xml_content.should ==
'white <tag>cockatoo</tag>'
@records.first.variants.last.to_html.should ==
'<em>white</em> cockatoo'
end
+ end
+
+ it "should parse ambigous items" do
+ items = AmbigousItems::Item.parse(fixture_file('ambigous_items.xml'),
+ :xpath => '/ambigous/my-items')
+ items.map(&:name).should == %w(first second third).map{|s| "My #{s} item" }
end
end