spec/profile_item_spec.rb in amee-3.2.1 vs spec/profile_item_spec.rb in amee-4.0.0
- old
+ new
@@ -1,9 +1,9 @@
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper.rb'
describe AMEE::Profile::Item do
before(:each) do
@item = AMEE::Profile::Item.new
@@ -36,11 +36,11 @@
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :'[]' => nil))
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2009-01-28 23:35:00.0" modified="2009-01-28 23:35:00.0" uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/><Profile uid="E54C5525AA3E"/></ProfileItem><Path>/home/energy/quantity/62BCC8C84D0C</Path><Profile uid="E54C5525AA3E"/></ProfileItemResource></Resources>'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
item.value("kWhPerMonth").should eql "10"
- item.total_amount.should be_close(2.06, 1e-9)
+ item.total_amount.should be_within(1.0e-09).of(2.06)
item.total_amount_unit.should == "kg/month"
end
it "should be able to create new profile items (JSON)" do
connection = flexmock "connection"
@@ -49,11 +49,11 @@
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '{"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"profileItem":{"validFrom":"20090101","amountPerMonth":2.06,"itemValues":[{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}}],"end":"false","uid":"8C7BD1AB69D3","dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}', :'[]' => nil))
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/8C7BD1AB69D3","profile":{"uid":"E54C5525AA3E"},"profileItem":{"created":"2009-01-29 00:11:33.0","itemValues":[{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"8C7BD1AB69D3","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"E54C5525AA3E"},"modified":"2009-01-29 00:11:33.0","validFrom":"20090101","amountPerMonth":2.06,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
item.value("kWhPerMonth").should eql "10"
- item.total_amount.should be_close(2.06, 1e-9)
+ item.total_amount.should be_within(1.0e-09).of(2.06)
item.total_amount_unit.should == "kg/month"
end
it "should be able to create new profile items (V2 XML)" do
connection = flexmock "connection"
@@ -61,11 +61,11 @@
connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="7V1FQMSWX64O"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.xml'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/62BCC8C84D0C'))
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
item.value("energyConsumption").should eql "10"
- item.total_amount.should be_close(2.037, 1e-9)
+ item.total_amount.should be_within(1.0e-09).of(2.037)
item.total_amount_unit.should == "kg/year"
end
it "should be able to create new profile items (V2 JSON)" do
connection = flexmock "connection"
@@ -73,11 +73,11 @@
connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"7V1FQMSWX64O"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.json'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/8C7BD1AB69D3'))
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
item.value("energyConsumption").should eql "10"
- item.total_amount.should be_close(2.037, 1e-9)
+ item.total_amount.should be_within(1.0e-09).of(2.037)
item.total_amount_unit.should == "kg/year"
end
it "should be able to create new profile items and just get location of new resource (XML)" do
connection = flexmock "connection"
@@ -150,11 +150,11 @@
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.profile_uid.should == "92C8DB30F46B"
@item.uid.should == "6E9B1517D753"
@item.name.should == "6E9B1517D753"
@item.path.should == "/home/energy/quantity/6E9B1517D753"
- @item.total_amount.should be_close(25.2, 1e-9)
+ @item.total_amount.should be_within(1.0e-09).of(25.2)
@item.total_amount_unit.should == "kg/month"
@item.valid_from.should == DateTime.new(2008, 9, 1)
@item.end.should be_false
@item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
end
@@ -194,11 +194,11 @@
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.profile_uid.should == "9BFB0C1CD78A"
@item.uid.should == "30C00AD33033"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/30C00AD33033"
- @item.total_amount.should be_close(302.4, 1e-9)
+ @item.total_amount.should be_within(1.0e-09).of(302.4)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
end
@@ -223,20 +223,20 @@
it "should parse multiple return values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8" standalone="no"?><Resources xmlns="http://schemas.amee.cc/2.0"><ProfileItemResource><ProfileItem created="2010-07-16T14:44:43Z" modified="2010-07-16T14:45:03Z" uid="3BCDB0BB2B96"><Name>gas</Name><ItemValues><ItemValue uid="06F553CED9F7"><Path>currentReading</Path><Name>Current Reading</Name><Value>0</Value><Unit>kWh</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="67B7476423C0"><Path>currentReading</Path><Name>Current Reading</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="4CF7691084DB"><Path>energyConsumption</Path><Name>Energy Consumption</Name><Value>13</Value><Unit>kWh</Unit><PerUnit>month</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="068A0D6D03F7"><Path>energyConsumption</Path><Name>Energy Consumption</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="1CA0D40208F0"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="1ACEB4784A42"><Path>season</Path><Name>Season</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="036262B5D69D"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="A568643CD1D7"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><Unit/><PerUnit/><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="990F69A6BD48"><Path>massPerTime</Path><Name>Mass Per Time</Name><Value>0</Value><Unit>kg</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="CF12B3EBAD02"><Path>massPerTime</Path><Name>Mass Per Time</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kg</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="A5BB73E6CBD2"><Path>lastReading</Path><Name>Last Reading</Name><Value>0</Value><Unit>kWh</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="40AB7E90980C"><Path>lastReading</Path><Name>Last Reading</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>kWh</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="DA93374B62C2"><Path>volumePerTime</Path><Name>Volume Per Time</Name><Value>0</Value><Unit>L</Unit><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="324EC808AC30"><Path>volumePerTime</Path><Name>Volume Per Time</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><Unit>L</Unit><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue><ItemValue uid="FA09F1FF043D"><Path>deliveries</Path><Name>Number of deliveries</Name><Value/><Unit/><PerUnit>year</PerUnit><StartDate>2010-07-16T10:44:00-04:00</StartDate><ItemValueDefinition uid="177D4642A07A"><Path>deliveries</Path><Name>Number of deliveries</Name><ValueDefinition created="2007-07-27 08:30:44.0" modified="2007-07-27 08:30:44.0" uid="45433E48B39F"><Name>amount</Name><ValueType>DECIMAL</ValueType><Description/><Environment uid="5F5887BCF726"/></ValueDefinition><PerUnit>year</PerUnit><FromProfile>true</FromProfile><FromData>false</FromData><DrillDown>false</DrillDown></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path><Deprecated>false</Deprecated></DataCategory><Amount unit="kg/year">31.7772</Amount><Amounts><Amount default="true" perUnit="year" type="CO2" unit="kg">31.7772</Amount><Amount type="CH4" unit="kg">4.2</Amount><Note type="comment">This is a text node</Note><Note type="comment">This is another text node</Note></Amounts><StartDate>2010-07-16T10:44:00-04:00</StartDate><EndDate/><DataItem uid="66056991EE23"><Label>gas</Label></DataItem><Profile uid="F8C2D1052BF7"/></ProfileItem><Path>/home/energy/quantity/3BCDB0BB2B96</Path><Profile uid="F8C2D1052BF7"/></ProfileItemResource></Resources>'))
@item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
- @item.total_amount.should be_close(31.7772, 1e-4)
+ @item.total_amount.should be_within(0.0001).of(31.7772)
@item.total_amount_unit.should == 'kg/year'
@item.amounts.size.should be(2)
@item.amounts[0][:type].should == "CO2"
- @item.amounts[0][:value].should be_close(31.7772, 1e-4)
+ @item.amounts[0][:value].should be_within(0.0001).of(31.7772)
@item.amounts[0][:unit].should == 'kg'
@item.amounts[0][:per_unit].should == 'year'
@item.amounts[0][:default].should be_true
@item.amounts[1][:type].should == "CH4"
- @item.amounts[1][:value].should be_close(4.2, 1e-2)
+ @item.amounts[1][:value].should be_within(0.01).of(4.2)
@item.amounts[1][:unit].should == 'kg'
@item.amounts[1][:per_unit].should be_nil
@item.notes.size.should be(2)
@item.notes[0][:type].should == 'comment'
@item.notes[0][:value].should == 'This is a text node'
@@ -263,11 +263,11 @@
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.profile_uid.should == "9BFB0C1CD78A"
@item.uid.should == "30C00AD33033"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/30C00AD33033"
- @item.total_amount.should be_close(302.4, 1e-9)
+ @item.total_amount.should be_within(1.0e-09).of(302.4)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
end
@@ -308,11 +308,11 @@
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.profile_uid.should == "92C8DB30F46B"
@item.uid.should == "6E9B1517D753"
@item.name.should == "6E9B1517D753"
@item.path.should == "/home/energy/quantity/6E9B1517D753"
- @item.total_amount.should be_close(25.2, 1e-9)
+ @item.total_amount.should be_within(1.0e-09).of(25.2)
@item.total_amount_unit.should == "kg/month"
@item.valid_from.should == DateTime.new(2008, 9, 1)
@item.end.should be_false
@item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
end
@@ -351,11 +351,11 @@
@item = AMEE::Profile::Item.get(connection, "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D")
@item.profile_uid.should == "447C40EB29FB"
@item.uid.should == "4A69B256D62D"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/4A69B256D62D"
- @item.total_amount.should be_close(32.058, 1e-9)
+ @item.total_amount.should be_within(1.0e-09).of(32.058)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D"
end
@@ -380,19 +380,19 @@
it "should parse multiple return values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"3BCDB0BB2B96","itemValues":[{"itemValueDefinition":{"perUnit":"year","uid":"67B7476423C0","unit":"kWh","name":"Current Reading","fromData":false,"path":"currentReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"06F553CED9F7","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"068A0D6D03F7","unit":"kWh","name":"Energy Consumption","fromData":false,"path":"energyConsumption","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"month","uid":"4CF7691084DB","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","fromData":false,"path":"includesHeating","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1CA0D40208F0","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","fromData":false,"path":"season","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1ACEB4784A42","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","fromData":false,"path":"greenTariff","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"036262B5D69D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","fromData":false,"path":"paymentFrequency","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"A568643CD1D7","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"perUnit":"year","uid":"CF12B3EBAD02","unit":"kg","name":"Mass Per Time","fromData":false,"path":"massPerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"990F69A6BD48","startDate":"2010-07-16T10:44:00-04:00","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"40AB7E90980C","unit":"kWh","name":"Last Reading","fromData":false,"path":"lastReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"A5BB73E6CBD2","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"324EC808AC30","unit":"L","name":"Volume Per Time","fromData":false,"path":"volumePerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"DA93374B62C2","startDate":"2010-07-16T10:44:00-04:00","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"177D4642A07A","name":"Number of deliveries","fromData":false,"path":"deliveries","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"FA09F1FF043D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","deprecated":false,"name":"Quantity","path":"quantity"},"startDate":"2010-07-16T10:44:00-04:00","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2010-07-16T14:45:03Z","amount":{"unit":"kg/year","value":31.7772},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"amounts":{"amount":[{"perUnit":"year","unit":"kg","default":"true","value":31.7772,"type":"CO2"},{"type":"CH4","unit":"kg","value":4.2}],"note":[{"type" : "comment","value" : "This is a text node"},{"type" : "comment","value" : "This is another text node"}]},"created":"2010-07-16T14:44:43Z","name":"gas","profile":{"uid":"F8C2D1052BF7"}},"path":"/home/energy/quantity/3BCDB0BB2B96","profile":{"uid":"F8C2D1052BF7"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
- @item.total_amount.should be_close(31.7772, 1e-4)
+ @item.total_amount.should be_within(0.0001).of(31.7772)
@item.total_amount_unit.should == 'kg/year'
@item.amounts.size.should be(2)
@item.amounts[0][:type].should == "CO2"
- @item.amounts[0][:value].should be_close(31.7772, 1e-4)
+ @item.amounts[0][:value].should be_within(0.0001).of(31.7772)
@item.amounts[0][:unit].should == 'kg'
@item.amounts[0][:per_unit].should == 'year'
@item.amounts[0][:default].should be_true
@item.amounts[1][:type].should == "CH4"
- @item.amounts[1][:value].should be_close(4.2, 1e-2)
+ @item.amounts[1][:value].should be_within(0.01).of(4.2)
@item.amounts[1][:unit].should == 'kg'
@item.amounts[1][:per_unit].should be_nil
@item.notes.size.should be(2)
@item.notes[0][:type].should == 'comment'
@item.notes[0][:value].should == 'This is a text node'
\ No newline at end of file