amee 3.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/CHANGELOG.txt +1 -24
  2. data/Gemfile +7 -8
  3. data/Gemfile.lock +33 -14
  4. data/README.txt +33 -15
  5. data/Rakefile +15 -29
  6. data/VERSION +1 -1
  7. data/amee.gemspec +21 -24
  8. data/lib/amee.rb +11 -0
  9. data/lib/amee/connection.rb +1 -1
  10. data/lib/amee/logger.rb +10 -5
  11. data/lib/amee/rails.rb +12 -16
  12. data/lib/amee/v3.rb +2 -0
  13. data/lib/amee/v3/collection.rb +4 -6
  14. data/lib/amee/v3/connection.rb +0 -5
  15. data/lib/amee/v3/item_definition.rb +12 -19
  16. data/lib/amee/v3/item_value_definition.rb +6 -7
  17. data/lib/amee/v3/item_value_definition_list.rb +3 -3
  18. data/lib/amee/v3/return_value_definition.rb +4 -4
  19. data/spec/amee_spec.rb +1 -1
  20. data/spec/cache_spec.rb +1 -1
  21. data/spec/connection_spec.rb +1 -1
  22. data/spec/data_category_spec.rb +4 -4
  23. data/spec/data_item_spec.rb +5 -5
  24. data/spec/data_item_value_history_spec.rb +1 -1
  25. data/spec/data_item_value_spec.rb +1 -1
  26. data/spec/data_object_spec.rb +1 -1
  27. data/spec/drill_down_spec.rb +1 -1
  28. data/spec/fixtures/itemdef.xml +1 -6
  29. data/spec/fixtures/itemdef_441BF4BEA15B.xml +12 -20
  30. data/spec/item_definition_spec.rb +7 -7
  31. data/spec/item_value_definition_spec.rb +9 -9
  32. data/spec/logger_spec.rb +1 -1
  33. data/spec/object_spec.rb +1 -1
  34. data/spec/parse_helper_spec.rb +1 -1
  35. data/spec/profile_category_spec.rb +19 -19
  36. data/spec/profile_item_spec.rb +16 -16
  37. data/spec/profile_item_value_spec.rb +1 -1
  38. data/spec/profile_object_spec.rb +1 -1
  39. data/spec/profile_spec.rb +1 -1
  40. data/spec/rails_spec.rb +1 -6
  41. data/spec/spec_helper.rb +3 -4
  42. data/spec/user_spec.rb +7 -7
  43. data/spec/v3/connection_spec.rb +11 -11
  44. data/spec/v3/item_definition_spec.rb +13 -15
  45. data/spec/v3/item_value_definition_spec.rb +6 -6
  46. data/spec/v3/return_value_definition_spec.rb +10 -9
  47. metadata +87 -79
  48. data/init.rb +0 -4
  49. data/lib/amee/config.rb +0 -37
  50. data/lib/amee/core-extensions/hash.rb +0 -43
  51. data/rails/init.rb +0 -18
  52. data/spec/fixtures/rails_config.yml +0 -13
  53. data/spec/spec_amee_config.rb +0 -46
data/lib/amee/rails.rb CHANGED
@@ -12,23 +12,23 @@ module AMEE
12
12
  def self.global(options = {})
13
13
  unless @connection
14
14
  $AMEE_CONFIG ||= {} # Make default values nil
15
- if $AMEE_CONFIG[:ssl] == false
15
+ if $AMEE_CONFIG['ssl'] == false
16
16
  options.merge! :ssl => false
17
17
  end
18
- if $AMEE_CONFIG[:retries]
19
- options.merge! :retries => $AMEE_CONFIG[:retries].to_i
18
+ if $AMEE_CONFIG['retries']
19
+ options.merge! :retries => $AMEE_CONFIG['retries'].to_i
20
20
  end
21
- if $AMEE_CONFIG[:timeout]
22
- options.merge! :timeout => $AMEE_CONFIG[:timeout].to_i
21
+ if $AMEE_CONFIG['timeout']
22
+ options.merge! :timeout => $AMEE_CONFIG['timeout'].to_i
23
23
  end
24
- if $AMEE_CONFIG[:cache] == 'rails'
24
+ if $AMEE_CONFIG['cache'] == 'rails'
25
25
  # Pass in the rails cache store
26
26
  options[:cache_store] = ActionController::Base.cache_store
27
27
  else
28
- options[:cache] ||= $AMEE_CONFIG[:cache] if $AMEE_CONFIG[:cache].present?
28
+ options[:cache] ||= $AMEE_CONFIG['cache'] if $AMEE_CONFIG['cache'].present?
29
29
  end
30
- options[:enable_debug] ||= $AMEE_CONFIG[:debug] if $AMEE_CONFIG[:debug].present?
31
- @connection = self.connect($AMEE_CONFIG[:server], $AMEE_CONFIG[:username], $AMEE_CONFIG[:password], options)
30
+ options[:enable_debug] ||= $AMEE_CONFIG['debug'] if $AMEE_CONFIG['debug'].present?
31
+ @connection = self.connect($AMEE_CONFIG['server'], $AMEE_CONFIG['username'], $AMEE_CONFIG['password'], options)
32
32
  # Also store as $amee for backwards compatibility, though this is now deprecated
33
33
  $amee = @connection
34
34
  end
@@ -52,20 +52,16 @@ module AMEE
52
52
  # Include the instance methods for creation and desctruction
53
53
  include InstanceMethods
54
54
  # Install callbacks
55
- before_validation_on_create :amee_create
56
- alias_method_chain :save, :amee
55
+ before_validation :amee_create, :on => :create
56
+ after_save :amee_save
57
57
  before_destroy :amee_destroy
58
58
  # Check that this object has an AMEE profile UID when saving
59
- validates_presence_of :amee_profile
59
+ validates :amee_profile, :presence => true
60
60
  end
61
61
  end
62
62
 
63
63
  module InstanceMethods
64
64
 
65
- def save_with_amee
66
- save_without_amee && amee_save
67
- end
68
-
69
65
  def amee_create
70
66
  # Create profile
71
67
  profile = AMEE::Profile::Profile.create(amee_connection)
data/lib/amee/v3.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
+ AMEE_API_VERSION = '3.3'
5
+
4
6
  require 'amee/v3/meta_helper'
5
7
  require 'amee/v3/collection'
6
8
  require 'amee/v3/connection'
@@ -8,7 +8,8 @@ module AMEE
8
8
  collectionpath=~/^\/3/
9
9
  end
10
10
 
11
- def fetch_with_v3
11
+ alias_method :fetch_without_v3, :fetch
12
+ def fetch
12
13
  @options.merge! @pager.options if @pager
13
14
  retries = [1] * connection.retries
14
15
  begin
@@ -33,9 +34,9 @@ module AMEE
33
34
  end
34
35
  end
35
36
  end
36
- alias_method_chain :fetch, :v3
37
37
 
38
- def each_page_with_v3
38
+ alias_method :each_page_without_v3, :each_page
39
+ def each_page
39
40
  @pager=AMEE::Limiter.new(@options) if v3
40
41
  # in v3 need to specify limit to start with, not in v2
41
42
  begin
@@ -54,8 +55,5 @@ module AMEE
54
55
  end while @pager && @pager.next! #pager is nil if no pager in response,
55
56
  # pager.next! is false if @pager said current=last.
56
57
  end
57
- alias_method_chain :each_page, :v3
58
-
59
58
  end
60
59
  end
61
-
@@ -3,11 +3,6 @@
3
3
 
4
4
  module AMEE
5
5
  class Connection
6
-
7
- def self.api_version
8
- '3'
9
- end
10
-
11
6
  def v3_connection
12
7
  @v3_http ||= begin
13
8
  @v3_http = Net::HTTP.new(v3_hostname, @port)
@@ -7,14 +7,13 @@ module AMEE
7
7
 
8
8
  include ParseHelper
9
9
 
10
- def initialize_with_v3(data = {})
10
+ alias_method :initialize_without_v3, :initialize
11
+ def initialize(data = {})
11
12
  @usages = data[:usages] || []
12
- @algorithms = data[:algorithms] || {}
13
13
  initialize_without_v3(data)
14
14
  end
15
- alias_method_chain :initialize, :v3
16
15
 
17
- attr_accessor :usages, :algorithms
16
+ attr_accessor :usages
18
17
 
19
18
  def self.metaxmlpathpreamble
20
19
  '/Representation/ItemDefinition/'
@@ -26,7 +25,7 @@ module AMEE
26
25
 
27
26
  def self.v3_get(connection, uid, options={})
28
27
  # Load data from path
29
- response = connection.v3_get("/#{AMEE::Connection.api_version}/definitions/#{uid};full", options)
28
+ response = connection.v3_get("/#{AMEE_API_VERSION}/definitions/#{uid};full", options)
30
29
  # Parse response
31
30
  item_definition = ItemDefinition.parse(connection, response, false)
32
31
  # Done
@@ -35,7 +34,10 @@ module AMEE
35
34
  raise AMEE::BadData.new("Couldn't load ItemDefinition. Check that your URL is correct.\n#{$!}\n#{response}")
36
35
  end
37
36
 
38
- def self.from_xml_with_v3(xml, is_list = true)
37
+ class << self
38
+ alias_method :from_xml_without_v3, :from_xml
39
+ end
40
+ def self.from_xml(xml, is_list = true)
39
41
  return self.from_xml_without_v3(xml, is_list) if xml.include?('<Resources>')
40
42
  # Parse data from response into hash
41
43
  doc = load_xml_doc(xml)
@@ -46,34 +48,25 @@ module AMEE
46
48
  data[:name] = x 'Name', :doc => doc, :meta => true
47
49
  data[:drillDown] = x('DrillDown', :doc => doc, :meta => true).split(",") rescue nil
48
50
  data[:usages] = [(x 'Usages/Usage/Name', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
49
- data[:algorithms] = begin
50
- names = [(x 'Algorithms/Algorithm/Name', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
51
- uids = [(x 'Algorithms/Algorithm/@uid', :doc => doc, :meta => true)].flatten.delete_if{|x| x.nil?}
52
- Hash[names.zip(uids)]
53
- end
54
51
  # Create object
55
52
  ItemDefinition.new(data)
56
53
  rescue
57
54
  raise AMEE::BadData.new("Couldn't load ItemDefinition from XML. Check that your URL is correct.\n#{$!}\n#{xml}")
58
55
  end
59
- class << self
60
- alias_method_chain :from_xml, :v3
61
- end
62
56
 
63
57
  def save!
64
58
  save_options = {
65
59
  :usages => @usages.join(','),
66
60
  :name => @name
67
61
  }
68
- @connection.v3_put("/#{AMEE::Connection.api_version}/definitions/#{@uid}",save_options)
62
+ @connection.v3_put("/#{AMEE_API_VERSION}/definitions/#{@uid}",save_options)
69
63
  end
70
64
 
71
- def expire_cache_with_v3
72
- @connection.expire_matching("/#{AMEE::Connection.api_version}/definitions/#{@uid}.*")
65
+ alias_method :expire_cache_without_v3, :expire_cache
66
+ def expire_cache
67
+ @connection.expire_matching("/#{AMEE_API_VERSION}/definitions/#{@uid}.*")
73
68
  expire_cache_without_v3
74
69
  end
75
- alias_method_chain :expire_cache, :v3
76
-
77
70
  end
78
71
  end
79
72
  end
@@ -6,14 +6,14 @@ module AMEE
6
6
  class ItemValueDefinition
7
7
  include MetaHelper
8
8
 
9
- def initialize_with_v3(data = {})
9
+ alias_method :initialize_without_v3, :initialize
10
+ def initialize(data = {})
10
11
  storemeta(data[:meta]) if data[:meta]
11
12
  initialize_without_v3(data)
12
13
  end
13
- alias_method_chain :initialize, :v3
14
14
 
15
15
  def metapath
16
- "/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/values/#{uid};wikiDoc;usages"
16
+ "/#{AMEE_API_VERSION}/definitions/#{itemdefuid}/values/#{uid};wikiDoc;usages"
17
17
  end
18
18
  def metaxmlpathpreamble
19
19
  '/Representation/ItemValueDefinition/'
@@ -88,12 +88,11 @@ EOF
88
88
  end
89
89
  end
90
90
 
91
- def expire_cache_with_v3
92
- @connection.expire_matching("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/values/#{uid}.*")
91
+ alias_method :expire_cache_without_v3, :expire_cache
92
+ def expire_cache
93
+ @connection.expire_matching("/#{AMEE_API_VERSION}/definitions/#{itemdefuid}/values/#{uid}.*")
93
94
  expire_cache_without_v3
94
95
  end
95
- alias_method_chain :expire_cache, :v3
96
-
97
96
  end
98
97
  end
99
98
  end
@@ -6,14 +6,14 @@ module AMEE
6
6
 
7
7
  class ItemValueDefinitionList < AMEE::Collection
8
8
 
9
- def initialize_with_v3(connection,uid,options={}, &block)
9
+ alias_method :initialize_without_v3, :initialize
10
+ def initialize(connection,uid,options={}, &block)
10
11
  @use_v3_connection = true
11
12
  initialize_without_v3(connection, uid, options, &block)
12
13
  end
13
- alias_method_chain :initialize, :v3
14
14
 
15
15
  def collectionpath
16
- "/#{AMEE::Connection.api_version}/definitions/#{@uid}/values;full"
16
+ "/#{AMEE_API_VERSION}/definitions/#{@uid}/values;full"
17
17
  end
18
18
 
19
19
  def xmlcollectorpath
@@ -15,7 +15,7 @@ module AMEE
15
15
  ReturnValueDefinition
16
16
  end
17
17
  def collectionpath
18
- "/#{AMEE::Connection.api_version}/definitions/#{@uid}/returnvalues;full"
18
+ "/#{AMEE_API_VERSION}/definitions/#{@uid}/returnvalues;full"
19
19
  end
20
20
 
21
21
  def jsoncollector
@@ -138,7 +138,7 @@ module AMEE
138
138
 
139
139
 
140
140
  def self.load(connection,itemdefuid,ivduid,options={})
141
- ReturnValueDefinition.get(connection,"/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues/#{ivduid};full",options)
141
+ ReturnValueDefinition.get(connection,"/#{AMEE_API_VERSION}/definitions/#{itemdefuid}/returnvalues/#{ivduid};full",options)
142
142
  end
143
143
 
144
144
  def reload(connection)
@@ -178,7 +178,7 @@ module AMEE
178
178
  end
179
179
 
180
180
  options.merge!(:returnobj=>true)
181
- response = connection.v3_post("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues", options)
181
+ response = connection.v3_post("/#{AMEE_API_VERSION}/definitions/#{itemdefuid}/returnvalues", options)
182
182
  return ReturnValueDefinition.load(connection,itemdefuid , response['Location'].split('/')[7])
183
183
  rescue
184
184
  raise AMEE::BadData.new("Couldn't create ReturnValueDefinition. Check that your information is correct.\n#{response}")
@@ -189,7 +189,7 @@ module AMEE
189
189
  # Deleting takes a while... up the timeout to 120 seconds temporarily
190
190
  t = connection.timeout
191
191
  connection.timeout = 120
192
- connection.v3_delete("/#{AMEE::Connection.api_version}/definitions/#{itemdefuid}/returnvalues/" + return_value_definition.uid)
192
+ connection.v3_delete("/#{AMEE_API_VERSION}/definitions/#{itemdefuid}/returnvalues/" + return_value_definition.uid)
193
193
  connection.timeout = t
194
194
  rescue
195
195
  raise AMEE::BadData.new("Couldn't delete ReturnValueDefinition. Check that your information is correct.")
data/spec/amee_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe "AMEE module" do
7
7
 
data/spec/cache_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
  require 'ostruct'
6
6
 
7
7
  describe AMEE::Connection do
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe AMEE::Connection do
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe AMEE::Data::Category do
7
7
 
@@ -127,7 +127,7 @@ describe AMEE::Data::Category, "with an authenticated XML connection" do
127
127
  connection = flexmock "connection"
128
128
  connection.should_receive(:retries).and_return(0)
129
129
  connection.should_receive(:get).with("/data/transport/plane/generic", {:itemsPerPage => 10}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><DataCategoryResource><Path>/transport/plane/generic</Path><DataCategory created="2007-08-01 09:00:23.0" modified="2007-08-01 09:00:23.0" uid="FBA97B70DBDF"><Name>Generic</Name><Path>generic</Path><Environment uid="5F5887BCF726"/><DataCategory uid="6F3692D81CD9"><Name>Plane</Name><Path>plane</Path></DataCategory><ItemDefinition uid="441BF4BEA15B"/></DataCategory><Children><DataCategories/><DataItems><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="AD63A83B4D41"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>domestic</type><label>domestic</label><size>-</size><path>AD63A83B4D41</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.158</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="FFC7A05D54AD"><kgCO2PerPassengerJourney>73</kgCO2PerPassengerJourney><type>domestic</type><label>domestic, one way</label><size>one way</size><path>FFC7A05D54AD</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="F5498AD6FC75"><kgCO2PerPassengerJourney>146</kgCO2PerPassengerJourney><type>domestic</type><label>domestic, return</label><size>return</size><path>F5498AD6FC75</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="7D4220DF72F9"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>long haul</type><label>long haul</label><size>-</size><path>7D4220DF72F9</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.105</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="46117F6C0B7E"><kgCO2PerPassengerJourney>801</kgCO2PerPassengerJourney><type>long haul</type><label>long haul, one way</label><size>one way</size><path>46117F6C0B7E</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="96D538B1B246"><kgCO2PerPassengerJourney>1602</kgCO2PerPassengerJourney><type>long haul</type><label>long haul, return</label><size>return</size><path>96D538B1B246</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="9DA419052FDF"><kgCO2PerPassengerJourney>0</kgCO2PerPassengerJourney><type>short haul</type><label>short haul</label><size>-</size><path>9DA419052FDF</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0.13</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="84B4A14C7424"><kgCO2PerPassengerJourney>170</kgCO2PerPassengerJourney><type>short haul</type><label>short haul, one way</label><size>one way</size><path>84B4A14C7424</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="8DA1BEAA1013"><kgCO2PerPassengerJourney>340</kgCO2PerPassengerJourney><type>short haul</type><label>short haul, return</label><size>return</size><path>8DA1BEAA1013</path><source>DfT INAS Division, 29 March 2007</source><kgCO2PerPassengerKm>0</kgCO2PerPassengerKm></DataItem></DataItems><Pager><Start>0</Start><From>1</From><To>9</To><Items>9</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>9</ItemsFound></Pager></Children></DataCategoryResource></Resources>'))
130
- connection.should_receive(:v3_get).with("/#{AMEE::Connection.api_version}/definitions/441BF4BEA15B;full",{}).and_return(fixture('itemdef_441BF4BEA15B.xml')).once
130
+ connection.should_receive(:v3_get).with("/3.3/definitions/441BF4BEA15B;full",{}).and_return(fixture('itemdef_441BF4BEA15B.xml')).once
131
131
  @data = AMEE::Data::Category.get(connection, "/data/transport/plane/generic")
132
132
  @data.uid.should == "FBA97B70DBDF"
133
133
  @data.itemdef.should == "441BF4BEA15B"
@@ -138,7 +138,7 @@ describe AMEE::Data::Category, "with an authenticated XML connection" do
138
138
  it "should fail gracefully with bad XML" do
139
139
  connection = flexmock "connection"
140
140
  connection.should_receive(:retries).and_return(0)
141
- connection.should_receive(:get).with("/data", {:itemsPerPage => 10}).and_return(flexmock(:body => fixture('data.xml').first(12)))
141
+ connection.should_receive(:get).with("/data", {:itemsPerPage => 10}).and_return(flexmock(:body => fixture('data.xml')[0,12]))
142
142
  connection.should_receive(:expire).with("/data").once
143
143
  lambda{AMEE::Data::Category.get(connection, "/data")}.should raise_error(REXML::ParseException)
144
144
  end
@@ -146,7 +146,7 @@ describe AMEE::Data::Category, "with an authenticated XML connection" do
146
146
  it "should retry if bad XML is received first time" do
147
147
  connection = flexmock "connection"
148
148
  connection.should_receive(:retries).and_return(2)
149
- connection.should_receive(:get).with("/data", {:itemsPerPage => 10}).and_return(flexmock(:body => fixture('data.xml').first(12))).twice
149
+ connection.should_receive(:get).with("/data", {:itemsPerPage => 10}).and_return(flexmock(:body => fixture('data.xml')[0,12])).twice
150
150
  connection.should_receive(:expire).with("/data").twice
151
151
  connection.should_receive(:get).with("/data", {:itemsPerPage => 10}).and_return(flexmock(:body => fixture('data.xml'))).once
152
152
  lambda{AMEE::Data::Category.get(connection, "/data")}.should_not raise_error
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe AMEE::Data::Item do
7
7
 
@@ -127,7 +127,7 @@ describe AMEE::Data::Item, "with an authenticated connection" do
127
127
  it "should fail gracefully with bad XML" do
128
128
  connection = flexmock "connection"
129
129
  connection.should_receive(:retries).and_return(0)
130
- connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.xml').first(12)))
130
+ connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.xml')[0,12]))
131
131
  connection.should_receive(:expire).with("/data/transport/plane/generic/AD63A83B4D41").once
132
132
  lambda{AMEE::Data::Item.get(connection, "/data/transport/plane/generic/AD63A83B4D41")}.should raise_error(REXML::ParseException)
133
133
  end
@@ -135,7 +135,7 @@ describe AMEE::Data::Item, "with an authenticated connection" do
135
135
  it "should retry if bad XML is received first time" do
136
136
  connection = flexmock "connection"
137
137
  connection.should_receive(:retries).and_return(2)
138
- connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.xml').first(12))).twice
138
+ connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.xml')[0,12])).twice
139
139
  connection.should_receive(:expire).with("/data/transport/plane/generic/AD63A83B4D41").twice
140
140
  connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.xml'))).once
141
141
  lambda{AMEE::Data::Item.get(connection, "/data/transport/plane/generic/AD63A83B4D41")}.should_not raise_error
@@ -152,7 +152,7 @@ describe AMEE::Data::Item, "with an authenticated connection" do
152
152
  it "should fail gracefully with bad JSON" do
153
153
  connection = flexmock "connection"
154
154
  connection.should_receive(:retries).and_return(0)
155
- connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.json').first(12)))
155
+ connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.json')[0,12]))
156
156
  connection.should_receive(:expire).with("/data/transport/plane/generic/AD63A83B4D41").once
157
157
  lambda{AMEE::Data::Item.get(connection, "/data/transport/plane/generic/AD63A83B4D41")}.should raise_error(JSON::ParserError)
158
158
  end
@@ -160,7 +160,7 @@ describe AMEE::Data::Item, "with an authenticated connection" do
160
160
  it "should retry if bad JSON is received first time" do
161
161
  connection = flexmock "connection"
162
162
  connection.should_receive(:retries).and_return(2)
163
- connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.json').first(12))).twice
163
+ connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.json')[0,12])).twice
164
164
  connection.should_receive(:expire).with("/data/transport/plane/generic/AD63A83B4D41").twice
165
165
  connection.should_receive(:get).with("/data/transport/plane/generic/AD63A83B4D41", {}).and_return(flexmock(:body => fixture('AD63A83B4D41.json'))).once
166
166
  lambda{AMEE::Data::Item.get(connection, "/data/transport/plane/generic/AD63A83B4D41")}.should_not raise_error
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  TestSeriesOne=[[AMEE::Epoch,1],[AMEE::Epoch+1,2],[AMEE::Epoch+3,4]]
7
7
  TestSeriesTwo=[[AMEE::Epoch,2],[AMEE::Epoch+1,6],[AMEE::Epoch+5,7],[AMEE::Epoch+9,11]]
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
 
7
7
  MockResourceShortPath="/transport/plane/generic/AD63A83B4D41/kgCO2PerPassengerJourney"
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe AMEE::Data::Object do
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'spec_helper.rb'
5
5
 
6
6
  describe AMEE::Data::DrillDown do
7
7
 
@@ -14,12 +14,7 @@
14
14
  <Name>usageOther</Name>
15
15
  </Usage>
16
16
  </Usages>
17
- <Algorithms>
18
- <Algorithm uid="D4E4779CA7AB">
19
- <Name>default</Name>
20
- </Algorithm>
21
- </Algorithms>
22
17
  </ItemDefinition>
23
18
  <Status>OK</Status>
24
- <Version>3.6.0</Version>
19
+ <Version>3.1.0</Version>
25
20
  </Representation>
@@ -1,22 +1,14 @@
1
1
  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
2
  <Representation>
3
- <ItemDefinition created="2007-07-27T07:30:44Z" modified="2011-08-17T08:09:06Z" status="ACTIVE" uid="441BF4BEA15B">
4
- <Name>Plane Generic</Name>
5
- <DrillDown>type,size</DrillDown>
6
- <Usages>
7
- <Usage present="true">
8
- <Name>default</Name>
9
- </Usage>
10
- </Usages>
11
- <Algorithms>
12
- <Algorithm uid="EC4B78451B43">
13
- <Name>default</Name>
14
- </Algorithm>
15
- <Algorithm uid="595AF9E4E1E5">
16
- <Name>perMonth</Name>
17
- </Algorithm>
18
- </Algorithms>
19
- </ItemDefinition>
20
- <Status>OK</Status>
21
- <Version>3.6.0</Version>
22
- </Representation>
3
+ <ItemDefinition created="2007-07-27T07:30:44Z" modified="2010-08-24T17:17:01Z" status="ACTIVE" uid="441BF4BEA15B">
4
+ <Name>Plane Generic</Name>
5
+ <DrillDown>type,size</DrillDown>
6
+ <Usages>
7
+ <Usage present="true">
8
+ <Name>default</Name>
9
+ </Usage>
10
+ </Usages>
11
+ </ItemDefinition>
12
+ <Status>OK</Status>
13
+ <Version>3.1.0</Version>
14
+ </Representation>