spec/happymapper_item_spec.rb in happymapper-0.1.7 vs spec/happymapper_item_spec.rb in happymapper-0.2.0

- old
+ new

@@ -2,72 +2,93 @@ describe HappyMapper::Item do describe "new instance" do before do - @attr = HappyMapper::Item.new(:foo, String, :tag => 'foobar') + @item = HappyMapper::Item.new(:foo, String, :tag => 'foobar') end it "should accept a name" do - @attr.name.should == 'foo' + @item.name.should == 'foo' end it 'should accept a type' do - @attr.type.should == String + @item.type.should == String end it 'should accept :tag as an option' do - @attr.tag.should == 'foobar' + @item.tag.should == 'foobar' end - it 'should provide #name' do - @attr.should respond_to(:name) + it "should have a method_name" do + @item.method_name.should == 'foo' end + end + + describe "#method_name" do + it "should convert dashes to underscores" do + item = HappyMapper::Item.new(:'foo-bar', String, :tag => 'foobar') + item.method_name.should == 'foo_bar' + end + end + + describe "#xpath" do + it "should default to tag" do + item = HappyMapper::Item.new(:foo, String, :tag => 'foobar') + item.xpath.should == 'foobar' + end - it 'should provide #type' do - @attr.should respond_to(:type) + it "should prepend with .// if options[:deep] true" do + item = HappyMapper::Item.new(:foo, String, :tag => 'foobar', :deep => true) + item.xpath.should == './/foobar' end + + it "should prepend namespace if namespace exists" do + item = HappyMapper::Item.new(:foo, String, :tag => 'foobar') + item.namespace = 'v2:' + item.xpath.should == 'v2:foobar' + end end describe "typecasting" do it "should work with Strings" do - attribute = HappyMapper::Item.new(:foo, String) + item = HappyMapper::Item.new(:foo, String) [21, '21'].each do |a| - attribute.typecast(a).should == '21' + item.typecast(a).should == '21' end end it "should work with Integers" do - attribute = HappyMapper::Item.new(:foo, Integer) + item = HappyMapper::Item.new(:foo, Integer) [21, 21.0, '21'].each do |a| - attribute.typecast(a).should == 21 + item.typecast(a).should == 21 end end it "should work with Floats" do - attribute = HappyMapper::Item.new(:foo, Float) + item = HappyMapper::Item.new(:foo, Float) [21, 21.0, '21'].each do |a| - attribute.typecast(a).should == 21.0 + item.typecast(a).should == 21.0 end end it "should work with Times" do - attribute = HappyMapper::Item.new(:foo, Time) - attribute.typecast('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123456) + item = HappyMapper::Item.new(:foo, Time) + item.typecast('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123456) end it "should work with Dates" do - attribute = HappyMapper::Item.new(:foo, Date) - attribute.typecast('2000-01-01').should == Date.new(2000, 1, 1) + item = HappyMapper::Item.new(:foo, Date) + item.typecast('2000-01-01').should == Date.new(2000, 1, 1) end it "should work with DateTimes" do - attribute = HappyMapper::Item.new(:foo, DateTime) - attribute.typecast('2000-01-01 00:00:00').should == DateTime.new(2000, 1, 1, 0, 0, 0) + item = HappyMapper::Item.new(:foo, DateTime) + item.typecast('2000-01-01 00:00:00').should == DateTime.new(2000, 1, 1, 0, 0, 0) end it "should work with Boolean" do - attribute = HappyMapper::Item.new(:foo, Boolean) - attribute.typecast('false').should == false + item = HappyMapper::Item.new(:foo, Boolean) + item.typecast('false').should == false end end end \ No newline at end of file