spec/happymapper_spec.rb in happymapper-0.2.5 vs spec/happymapper_spec.rb in happymapper-0.3.0

- old
+ new

@@ -5,11 +5,11 @@ module Analytics class Property include HappyMapper tag 'property' - namespace 'dxp' + namespace 'http://schemas.google.com/analytics/2009' attribute :name, String attribute :value, String end class Entry @@ -17,11 +17,11 @@ tag 'entry' element :id, String element :updated, DateTime element :title, String - element :table_id, String, :namespace => 'dxp', :tag => 'tableId' + element :table_id, String, :namespace => 'http://schemas.google.com/analytics/2009', :tag => 'tableId' has_many :properties, Property end class Feed include HappyMapper @@ -82,11 +82,11 @@ module FedEx class Address include HappyMapper tag 'Address' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :city, String, :tag => 'City' element :state, String, :tag => 'StateOrProvinceCode' element :zip, String, :tag => 'PostalCode' element :countrycode, String, :tag => 'CountryCode' element :residential, Boolean, :tag => 'Residential' @@ -94,31 +94,31 @@ class Event include HappyMapper tag 'Events' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :timestamp, String, :tag => 'Timestamp' element :eventtype, String, :tag => 'EventType' element :eventdescription, String, :tag => 'EventDescription' has_one :address, Address end class PackageWeight include HappyMapper tag 'PackageWeight' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :units, String, :tag => 'Units' element :value, Integer, :tag => 'Value' end class TrackDetails include HappyMapper tag 'TrackDetails' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :tracking_number, String, :tag => 'TrackingNumber' element :status_code, String, :tag => 'StatusCode' element :status_desc, String, :tag => 'StatusDescription' element :carrier_code, String, :tag => 'CarrierCode' element :service_info, String, :tag => 'ServiceInfo' @@ -129,11 +129,11 @@ class Notification include HappyMapper tag 'Notifications' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :severity, String, :tag => 'Severity' element :source, String, :tag => 'Source' element :code, Integer, :tag => 'Code' element :message, String, :tag => 'Message' element :localized_message, String, :tag => 'LocalizedMessage' @@ -141,19 +141,19 @@ class TransactionDetail include HappyMapper tag 'TransactionDetail' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :cust_tran_id, String, :tag => 'CustomerTransactionId' end class TrackReply include HappyMapper tag 'TrackReply' - namespace 'v2' + namespace 'http://fedex.com/ws/track/v2' element :highest_severity, String, :tag => 'HighestSeverity' element :more_data, Boolean, :tag => 'MoreData' has_many :notifications, Notification, :tag => 'Notifications' has_many :trackdetails, TrackDetails, :tag => 'TrackDetails' has_one :tran_detail, TransactionDetail, :tab => 'TransactionDetail' @@ -213,11 +213,11 @@ class CurrentWeather include HappyMapper tag 'ob' - namespace 'aws' + namespace 'http://www.aws.com/aws' element :temperature, Integer, :tag => 'temp' element :feels_like, Integer, :tag => 'feels-like' element :current_condition, String, :tag => 'current-condition', :attributes => {:icon => String} end @@ -241,11 +241,11 @@ tag 'Item' # if you put class in module you need tag element :asin, String, :tag => 'ASIN' element :detail_page_url, URI, :tag => 'DetailPageURL', :parser => :parse element :manufacturer, String, :tag => 'Manufacturer', :deep => true - element :point, String, :tag => 'point', :namespace => 'georss' + element :point, String, :tag => 'point', :namespace => 'http://www.georss.org/georss' element :product_group, ProductGroup, :tag => 'ProductGroup', :deep => true, :parser => :new, :raw => true end class Items include HappyMapper @@ -576,6 +576,52 @@ # tree.people.size.should == 1 # tree.people.first.version.should == '1199378491000' # tree.people.first.modified.should == Time.utc(2008, 1, 3, 16, 41, 31) # 2008-01-03T09:41:31-07:00 # tree.people.first.id.should == 'KWQS-BBQ' end + + describe 'nested elements with namespaces' do + module Namespaces + class Info + include HappyMapper + namespace 'http://schemas.google.com/analytics/2009' + element :category, String + end + + class Alert + include HappyMapper + namespace 'http://schemas.google.com/analytics/2009' + + element :identifier, String + element :severity, String, :namespace => false + has_one :info, Info + end + class Distribution + include HappyMapper + + tag 'EDXLDistribution' + has_one :alert, Alert + end + end + + def mapping + @mapping ||= Namespaces::Distribution.parse(fixture_file('nested_namespaces.xml')) + end + + it "should parse elements with inline namespace" do + lambda { mapping }.should_not raise_error + end + + it "should map elements with inline namespace" do + mapping.alert.identifier.should == 'CDC-2006-183' + end + + it "should map sub elements of with nested namespace" do + mapping.alert.info.category.should == 'Health' + end + + it "should map elements without a namespace" do + mapping.alert.severity.should == 'Severe' + end + end + end