spec/happymapper_spec.rb in happymapper-0.1.2 vs spec/happymapper_spec.rb in happymapper-0.1.3
- old
+ new
@@ -38,10 +38,19 @@
element :in_reply_to_user_id, Integer
element :favorited, Boolean
has_one :user, User
end
+class CurrentWeather
+ include HappyMapper
+ tag 'aws:ob'
+ element :temperature, Integer, :tag => 'aws:temp'
+ element :feels_like, Integer, :tag => 'aws:feels-like'
+ element :current_condition, String, :tag => 'aws:current-condition', :attributes => {:icon => String}
+end
+
+
module PITA
class Item
include HappyMapper
tag 'Item' # if you put class in module you need tag
@@ -209,8 +218,23 @@
first.asin.should == '0321480791'
first.detail_page_url.should == 'http://www.amazon.com/gp/redirect.html%3FASIN=0321480791%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321480791%253FSubscriptionId=dontbeaswoosh'
first.manufacturer.should == 'Addison-Wesley Professional'
second.asin.should == '047022388X'
second.manufacturer.should == 'Wrox'
+ end
+ end
+
+ describe "#parse (with xml that has attributes of elements)" do
+ before do
+ file_contents = File.read(File.dirname(__FILE__) + '/fixtures/current_weather.xml')
+ @items = CurrentWeather.parse(file_contents)
+ end
+
+ it "should properly create objects" do
+ @first = @items[0]
+ @first.temperature.should == 51
+ @first.feels_like.should == 51
+ @first.current_condition.should == 'Sunny'
+ @first.current_condition.icon.should == 'http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif'
end
end
end
\ No newline at end of file