spec/v3/item_definition_spec.rb in amee-3.2.1 vs spec/v3/item_definition_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::Admin::ItemDefinition do before(:each) do @item_definition = AMEE::Admin::ItemDefinition.new @@ -17,41 +17,39 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated v3 connection" do it "should parse XML correctly" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')) + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')) @data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E") @data.uid.should == "472D78F6584E" @data.created.should == DateTime.new(2009,8,31,12,41,18) @data.modified.should == DateTime.new(2010,8,13,14,54,33) @data.name.should == "Power Stations And Stuff" @data.drill_downs.should == %w{state county metroArea city zipCode plantName powWowWow} @data.usages.should == ['usageOne', 'usageThree', 'usageOther'] - @data.algorithms['default'].should eql "D4E4779CA7AB" end - it "should parse XML correctly if there are no usages or algorithms" do + it "should parse XML correctly if there are no usages" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_no_usages.xml')) + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_no_usages.xml')) @data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E") @data.usages.should == [] - @data.algorithms.should == {} end it "should parse XML correctly if there is just one usage" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_one_usage.xml')) + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_one_usage.xml')) @data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E") @data.usages.should == ['usageOne'] end it "should be able to load an item value definition list" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')).once + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')).once connection.should_receive(:retries).and_return(0).once - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E/values;full", {:resultStart => 0, :resultLimit => 10}).and_return(fixture('ivdlist.xml')).once + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E/values;full", {:resultStart => 0, :resultLimit => 10}).and_return(fixture('ivdlist.xml')).once @data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E") @data.uid.should == "472D78F6584E" @list=@data.item_value_definition_list @list.length.should==29 @list.first.uid.should=='C531CA64DD72' @@ -77,24 +75,24 @@ end it "should fail gracefully with incorrect data" do connection = flexmock "connection" xml = '<?xml version="1.0" encoding="UTF-8"?><Resources>' - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return(xml) + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(xml) lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData) end it "should fail gracefully on other errors" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_raise("unidentified error") + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_raise("unidentified error") lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData) end it "should support updating" do connection = flexmock "connection" - connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E;full", {}).and_return('<?xml version="1.0" encoding="UTF-8" standalone="no"?><Representation><ItemDefinition created="2009-08-31T12:41:18Z" modified="2010-08-13T14:54:33Z" status="ACTIVE" uid="472D78F6584E"><Name>Power Stations And Stuff</Name><DrillDown>state,county,metroArea,city,zipCode,plantName,powWowWow</DrillDown><Usages><Usage present="true"><Name>usageOne</Name></Usage><Usage present="true"><Name>usageThree</Name></Usage><Usage present="false"><Name>usageOther</Name></Usage></Usages></ItemDefinition><Status>OK</Status><Version>#{AMEE::Connection.api_version}.0</Version></Representation>').once - connection.should_receive(:v3_put).with("/#{AMEE::Connection.api_version}/definitions/472D78F6584E", :usages => 'usageOther,usageThree,usageOne', :name => 'Power Stations And Stuff').once + connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return('<?xml version="1.0" encoding="UTF-8" standalone="no"?><Representation><ItemDefinition created="2009-08-31T12:41:18Z" modified="2010-08-13T14:54:33Z" status="ACTIVE" uid="472D78F6584E"><Name>Power Stations And Stuff</Name><DrillDown>state,county,metroArea,city,zipCode,plantName,powWowWow</DrillDown><Usages><Usage present="true"><Name>usageOne</Name></Usage><Usage present="true"><Name>usageThree</Name></Usage><Usage present="false"><Name>usageOther</Name></Usage></Usages></ItemDefinition><Status>OK</Status><Version>#{AMEE_API_VERSION}.0</Version></Representation>').once + connection.should_receive(:v3_put).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E", :usages => 'usageOther,usageThree,usageOne', :name => 'Power Stations And Stuff').once @data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E") @data.usages.should == ['usageOne', 'usageThree', 'usageOther'] @data.usages.reverse! @data.save! end @@ -282,11 +280,11 @@ it "Should retry on parse failures" do connection = flexmock "connection" connection.should_receive(:retries).and_return(2).once connection.should_receive(:get).with("/definitions/itemDefinitions",{}).twice. - and_return flexmock(:body =>DefinitionsListResponse.first(12)) + and_return flexmock(:body =>DefinitionsListResponse[0,12]) connection.should_receive(:expire).with("/definitions/itemDefinitions").twice connection.should_receive(:get).with("/definitions/itemDefinitions",{}).once. and_return flexmock(:body =>DefinitionsListResponse) @list=AMEE::Admin::ItemDefinitionList.new(connection) @list.first.should be_a AMEE::Admin::ItemDefinition @@ -297,10 +295,10 @@ it "Should retry on parse failures and bubble up failure if never successful" do connection = flexmock "connection" connection.should_receive(:retries).and_return(2).once connection.should_receive(:get).with("/definitions/itemDefinitions",{}).times(3). - and_return flexmock(:body =>DefinitionsListResponse.first(12)) + and_return flexmock(:body =>DefinitionsListResponse[0,12]) connection.should_receive(:expire).with("/definitions/itemDefinitions").times(3) lambda { AMEE::Admin::ItemDefinitionList.new(connection) }.should raise_error(Nokogiri::XML::SyntaxError) end \ No newline at end of file