amee-data-abstraction 1.3.1 → 2.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.
- data/.rvmrc +1 -1
- data/CHANGELOG.txt +0 -3
- data/Gemfile +5 -7
- data/Gemfile.lock +20 -14
- data/README.txt +15 -28
- data/Rakefile +17 -16
- data/VERSION +1 -1
- data/amee-data-abstraction.gemspec +21 -24
- data/lib/amee-data-abstraction.rb +6 -0
- data/lib/amee-data-abstraction/calculation.rb +1 -1
- data/lib/amee-data-abstraction/calculation_set.rb +10 -152
- data/lib/amee-data-abstraction/drill.rb +6 -23
- data/lib/amee-data-abstraction/input.rb +0 -24
- data/lib/amee-data-abstraction/ongoing_calculation.rb +9 -13
- data/lib/amee-data-abstraction/term.rb +13 -31
- data/spec/amee-data-abstraction/calculation_set_spec.rb +11 -245
- data/spec/amee-data-abstraction/calculation_spec.rb +18 -23
- data/spec/amee-data-abstraction/drill_spec.rb +7 -34
- data/spec/amee-data-abstraction/input_spec.rb +73 -113
- data/spec/amee-data-abstraction/metadatum_spec.rb +1 -1
- data/spec/amee-data-abstraction/ongoing_calculation_spec.rb +29 -45
- data/spec/amee-data-abstraction/profile_spec.rb +2 -2
- data/spec/amee-data-abstraction/prototype_calculation_spec.rb +11 -18
- data/spec/amee-data-abstraction/term_spec.rb +8 -50
- data/spec/amee-data-abstraction/terms_list_spec.rb +12 -16
- data/spec/config/amee_units_spec.rb +2 -1
- data/spec/core-extensions/class_spec.rb +18 -18
- data/spec/core-extensions/hash_spec.rb +2 -1
- data/spec/core-extensions/ordered_hash_spec.rb +2 -1
- data/spec/core-extensions/proc_spec.rb +1 -1
- data/spec/fixtures/{config/electricity.rb → electricity.rb} +2 -2
- data/spec/fixtures/electricity_and_transport.rb +55 -0
- data/spec/fixtures/{config/calculations/transport.rb → transport.rb} +2 -2
- data/spec/spec_helper.rb +7 -43
- metadata +56 -61
- data/init.rb +0 -4
- data/rails/init.rb +0 -32
- data/spec/fixtures/config/calculations/electricity.rb +0 -35
- data/spec/fixtures/config/calculations/electricity_and_transport.rb +0 -53
@@ -35,29 +35,6 @@ module AMEE
|
|
35
35
|
choice_validation_message
|
36
36
|
end
|
37
37
|
|
38
|
-
# Returns the list of available choices for <tt>self</tt>. A custom list of
|
39
|
-
# choices can be provided as an argument, in which case these will override
|
40
|
-
# the list provided by the AMEE platform
|
41
|
-
#
|
42
|
-
def choices(*args)
|
43
|
-
if args.empty?
|
44
|
-
if @choices.blank?
|
45
|
-
drill_down = parent.amee_drill(:before=>label)
|
46
|
-
if single_choice = drill_down.selections[path]
|
47
|
-
disable!
|
48
|
-
[single_choice]
|
49
|
-
else
|
50
|
-
enable!
|
51
|
-
drill_down.choices
|
52
|
-
end
|
53
|
-
else
|
54
|
-
@choices
|
55
|
-
end
|
56
|
-
else
|
57
|
-
@choices = [args].flatten
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
38
|
private
|
62
39
|
|
63
40
|
# Returns <tt>true</tt> if the value set for <tt>self</tt> is one of the
|
@@ -67,6 +44,12 @@ module AMEE
|
|
67
44
|
super && (choices.include? value)
|
68
45
|
end
|
69
46
|
|
47
|
+
# Returns the list of available choices for <tt>self</tt>.
|
48
|
+
def choices
|
49
|
+
c=parent.amee_drill(:before=>label).choices
|
50
|
+
c.length==1 ? [value] : c #Intention is to get autodrilled, drill will result in a UID
|
51
|
+
end
|
52
|
+
|
70
53
|
# Returns <tt>true</tt> if <tt>self</tt> is the "first unset" drill, i.e.
|
71
54
|
# the one which should be set next
|
72
55
|
#
|
@@ -11,8 +11,6 @@ module AMEE
|
|
11
11
|
#
|
12
12
|
class Input < Term
|
13
13
|
|
14
|
-
attr_accessor :dirty
|
15
|
-
|
16
14
|
# Returns the valid choices for this input
|
17
15
|
# (Abstract, implemented only for subclasses of input.)
|
18
16
|
def choices
|
@@ -31,7 +29,6 @@ module AMEE
|
|
31
29
|
@validation = nil
|
32
30
|
validation_message {"#{name} is invalid."}
|
33
31
|
super
|
34
|
-
@dirty = false
|
35
32
|
end
|
36
33
|
|
37
34
|
# Configures the value of <tt>self</tt> to be fixed to <tt>val</tt>, i.e.
|
@@ -70,7 +67,6 @@ module AMEE
|
|
70
67
|
if args.first.to_s != @value.to_s
|
71
68
|
raise Exceptions::FixedValueInterference if fixed?
|
72
69
|
parent.dirty! if parent and parent.is_a? OngoingCalculation
|
73
|
-
mark_as_dirty
|
74
70
|
end
|
75
71
|
end
|
76
72
|
super
|
@@ -159,16 +155,6 @@ module AMEE
|
|
159
155
|
!optional?(usage)
|
160
156
|
end
|
161
157
|
|
162
|
-
# Manually set the term as optional
|
163
|
-
def optional!
|
164
|
-
@optional=true
|
165
|
-
end
|
166
|
-
|
167
|
-
# Manually set the term as compuslory
|
168
|
-
def compulsory!
|
169
|
-
@optional=false
|
170
|
-
end
|
171
|
-
|
172
158
|
# Check that the value of <tt>self</tt> is valid. If invalid, and is defined
|
173
159
|
# as part of a calculation, add the invalidity message to the parent
|
174
160
|
# calculation's error list. Otherwise, raise a <i>ChoiceValidation</i>
|
@@ -199,10 +185,6 @@ module AMEE
|
|
199
185
|
super || fixed?
|
200
186
|
end
|
201
187
|
|
202
|
-
def dirty?
|
203
|
-
@dirty
|
204
|
-
end
|
205
|
-
|
206
188
|
protected
|
207
189
|
# Returns <tt>true</tt> if the value set for <tt>self</tt> is either blank
|
208
190
|
# or passes custom validation criteria. Otherwise, returns <tt>false</tt>.
|
@@ -210,12 +192,6 @@ module AMEE
|
|
210
192
|
def valid?
|
211
193
|
validation.blank? || validation === @value_before_cast
|
212
194
|
end
|
213
|
-
|
214
|
-
def mark_as_dirty
|
215
|
-
@dirty = true
|
216
|
-
parent.dirty! if parent and parent.is_a? OngoingCalculation
|
217
|
-
end
|
218
|
-
|
219
195
|
end
|
220
196
|
end
|
221
197
|
end
|
@@ -235,10 +235,6 @@ module AMEE
|
|
235
235
|
reset_invalidity_messages
|
236
236
|
end
|
237
237
|
|
238
|
-
def clear_outputs
|
239
|
-
outputs.each {|output| output.value nil }
|
240
|
-
end
|
241
|
-
|
242
238
|
def ==(other_calc)
|
243
239
|
!terms.inject(false) do |boolean,term|
|
244
240
|
boolean || term != other_calc[term.label]
|
@@ -258,7 +254,7 @@ module AMEE
|
|
258
254
|
def load_outputs
|
259
255
|
outputs.each do |output|
|
260
256
|
res=nil
|
261
|
-
if output.path
|
257
|
+
if output.path==:default
|
262
258
|
res= profile_item.amounts.find{|x| x[:default] == true}
|
263
259
|
else
|
264
260
|
res= profile_item.amounts.find{|x| x[:type] == output.path}
|
@@ -287,7 +283,7 @@ module AMEE
|
|
287
283
|
# and units for any unset <i>Profile</i> terms (profile item values) from
|
288
284
|
# the AMEE platform
|
289
285
|
#
|
290
|
-
def load_profile_item_values
|
286
|
+
def load_profile_item_values
|
291
287
|
return unless profile_item
|
292
288
|
profiles.unset.each do |term|
|
293
289
|
ameeval=profile_item.values.find { |value| value[:path] == term.path }
|
@@ -309,7 +305,6 @@ module AMEE
|
|
309
305
|
def load_drills
|
310
306
|
return unless profile_item
|
311
307
|
drills.each do |term|
|
312
|
-
next unless term.value.nil? || term.dirty?
|
313
308
|
ameeval=data_item.value(term.path)
|
314
309
|
raise Exceptions::Syncronization if term.set? && ameeval!=term.value
|
315
310
|
term.value ameeval
|
@@ -330,7 +325,6 @@ module AMEE
|
|
330
325
|
load_drills
|
331
326
|
rescue Exceptions::Syncronization
|
332
327
|
delete_profile_item
|
333
|
-
clear_outputs
|
334
328
|
end
|
335
329
|
load_metadata
|
336
330
|
# We could create an unsatisfied PI, and just check drilled? here
|
@@ -457,8 +451,10 @@ module AMEE
|
|
457
451
|
# <i>Profile</i> term values and attributes
|
458
452
|
#
|
459
453
|
def set_profile_item_values
|
460
|
-
|
461
|
-
profile_options.merge(:get_item=>
|
454
|
+
AMEE::Profile::Item.update(connection,profile_item_path,
|
455
|
+
profile_options.merge(:get_item=>false))
|
456
|
+
#Clear the memoised profile item, to reload with updated values
|
457
|
+
@profile_item=nil
|
462
458
|
end
|
463
459
|
|
464
460
|
# Delete the profile item which is associated with <tt>self</tt> from the
|
@@ -467,7 +463,7 @@ module AMEE
|
|
467
463
|
#
|
468
464
|
def delete_profile_item
|
469
465
|
AMEE::Profile::Item.delete(connection,profile_item_path)
|
470
|
-
self.profile_item_uid=
|
466
|
+
self.profile_item_uid=false
|
471
467
|
@profile_item=nil
|
472
468
|
end
|
473
469
|
|
@@ -513,8 +509,6 @@ module AMEE
|
|
513
509
|
@profile_category||=AMEE::Profile::Category.get(connection, profile_category_path)
|
514
510
|
end
|
515
511
|
|
516
|
-
public
|
517
|
-
|
518
512
|
# Automatically set the value of a drill term if there is only one choice
|
519
513
|
def autodrill
|
520
514
|
|
@@ -535,6 +529,8 @@ module AMEE
|
|
535
529
|
end
|
536
530
|
end
|
537
531
|
|
532
|
+
public
|
533
|
+
|
538
534
|
# Instantiate an <tt>AMEE::Data::DrillDown</tt> object representing the
|
539
535
|
# drill down sequence defined by the drill terms associated with
|
540
536
|
# <tt>self</tt>. As with <tt>#drill_options</tt>, An optional hash argument
|
@@ -84,6 +84,16 @@ module AMEE
|
|
84
84
|
#
|
85
85
|
attr_property :path
|
86
86
|
|
87
|
+
# String representing an annotation for <tt>self</tt>. Set a value by
|
88
|
+
# passing an argument. Retrieve a value by calling without an argument,
|
89
|
+
# e.g.,
|
90
|
+
#
|
91
|
+
# my_term.note 'Enter the mass of cement produced in the reporting period'
|
92
|
+
#
|
93
|
+
# my_term.note #=> 'Enter the mass of cement ...'
|
94
|
+
#
|
95
|
+
attr_property :note
|
96
|
+
|
87
97
|
# Symbol representing the owning parent calculation of <tt>self</tt>. Set
|
88
98
|
# the owning calculation object by passing as an argument. Retrieve it by
|
89
99
|
# calling without an argument, e.g.,
|
@@ -201,19 +211,6 @@ module AMEE
|
|
201
211
|
end
|
202
212
|
@value
|
203
213
|
end
|
204
|
-
|
205
|
-
# String representing an annotation for <tt>self</tt>. Set a value by
|
206
|
-
# passing an argument. Retrieve a value by calling without an argument,
|
207
|
-
# e.g.,
|
208
|
-
#
|
209
|
-
# my_term.note 'Enter the mass of cement produced in the reporting period'
|
210
|
-
#
|
211
|
-
# my_term.note #=> 'Enter the mass of cement ...'
|
212
|
-
#
|
213
|
-
def note(string=nil)
|
214
|
-
instance_variable_set("@note",string.gsub('"',"'")) unless string.nil?
|
215
|
-
instance_variable_get("@note")
|
216
|
-
end
|
217
214
|
|
218
215
|
# Symbols representing the attributes of <tt>self</tt> which are concerned
|
219
216
|
# with quantity units.
|
@@ -267,33 +264,19 @@ module AMEE
|
|
267
264
|
end
|
268
265
|
|
269
266
|
[:unit,:per_unit].each do |field|
|
270
|
-
|
271
|
-
# If no argument provided, returns the alternative units which are valid
|
272
|
-
# for <tt>self</tt>. If a list of units are provided as an argument, these
|
273
|
-
# override the dynamically assigned alternative units for <tt>self</tt>.
|
274
|
-
#
|
275
267
|
define_method("alternative_#{field}s") do |*args|
|
276
268
|
ivar = "@alternative_#{field}s"
|
269
|
+
default = send("default_#{field}".to_sym)
|
277
270
|
unless args.empty?
|
271
|
+
args << default if default
|
278
272
|
units = args.map {|arg| Unit.for(arg) }
|
279
273
|
Term.validate_dimensional_equivalence?(*units)
|
280
274
|
instance_variable_set(ivar, units)
|
281
275
|
else
|
282
276
|
return instance_variable_get(ivar) if instance_variable_get(ivar)
|
283
|
-
|
284
|
-
return instance_variable_set(ivar, (default.alternatives)) if default
|
277
|
+
return instance_variable_set(ivar, (default.alternatives << default)) if default
|
285
278
|
end
|
286
279
|
end
|
287
|
-
|
288
|
-
# Returns the list of unit choices for <tt>self</tt>, including both the
|
289
|
-
# default unit and all alternative units.
|
290
|
-
#
|
291
|
-
define_method("#{field}_choices") do |*args|
|
292
|
-
choices = send("alternative_#{field}s".to_sym)
|
293
|
-
default = send("default_#{field}".to_sym)
|
294
|
-
choices = [default] + choices if default
|
295
|
-
return choices
|
296
|
-
end
|
297
280
|
end
|
298
281
|
|
299
282
|
# Returns <tt>true</tt> if <tt>self</tt> has a populated value attribute.
|
@@ -520,7 +503,6 @@ module AMEE
|
|
520
503
|
else value
|
521
504
|
end
|
522
505
|
end
|
523
|
-
|
524
506
|
end
|
525
507
|
end
|
526
508
|
end
|
@@ -1,264 +1,32 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
|
3
2
|
class CalculationSet
|
4
3
|
def call_me
|
5
4
|
#stub, because flexmock doesn't work for new instances during constructor
|
6
5
|
@@called=true
|
7
6
|
end
|
8
|
-
|
7
|
+
def self.called
|
8
|
+
@@called
|
9
|
+
end
|
9
10
|
end
|
10
11
|
describe CalculationSet do
|
11
|
-
|
12
|
-
before :all do
|
13
|
-
CalculationSet.sets.clear
|
14
|
-
@calc_set = CalculationSet.find("electricity_and_transport")
|
15
|
-
end
|
16
|
-
|
17
12
|
it 'can create an instance' do
|
18
|
-
|
13
|
+
ElectricityAndTransport.should be_a CalculationSet
|
19
14
|
end
|
20
|
-
|
21
15
|
it 'can create an instance' do
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
it "can access class sets hash" do
|
26
|
-
CalculationSet.sets[:electricity_and_transport].should be_a CalculationSet
|
27
|
-
end
|
28
|
-
|
29
|
-
it "is included in class sets hash if initialised by find method" do
|
30
|
-
CalculationSet.sets[:electricity_and_transport].should be_a CalculationSet
|
31
|
-
end
|
32
|
-
|
33
|
-
it "has file attribute if initialised by find method" do
|
34
|
-
CalculationSet.sets[:electricity_and_transport].file.should eql "#{Rails.root}/config/calculations/electricity_and_transport.rb"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has name attribute if initialised by find method" do
|
38
|
-
CalculationSet.sets[:electricity_and_transport].name.should eql "electricity_and_transport"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "is included in class sets hash if initialised manually" do
|
42
|
-
CalculationSet.new('my_set') {calculation {label :mycalc}}
|
43
|
-
CalculationSet.sets[:my_set].should be_a CalculationSet
|
16
|
+
ElectricityAndTransport.calculations.should be_a ActiveSupport::OrderedHash
|
44
17
|
end
|
45
|
-
|
46
|
-
it "has name" do
|
47
|
-
CalculationSet.new('my_set') {calculation {label :mycalc}}.name.should eql "my_set"
|
48
|
-
end
|
49
|
-
|
50
18
|
it 'can access a calculation by key' do
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "initialising from file" do
|
55
|
-
|
56
|
-
after(:each) do
|
57
|
-
CalculationSet.sets.clear
|
58
|
-
delete_lock_files
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should find config file in default Rails location using just file name" do
|
62
|
-
CalculationSet.find_config_file("electricity").should eql "#{Rails.root}/config/calculations/electricity.rb"
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should find config file in default Rails location using file name and extension" do
|
66
|
-
CalculationSet.find_config_file("electricity.rb").should eql "#{Rails.root}/config/calculations/electricity.rb"
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should find config file in other Rails location using relative path" do
|
70
|
-
CalculationSet.find_config_file("config/electricity.rb").should eql "#{Rails.root}/config/electricity.rb"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should raise error if config file not found" do
|
74
|
-
lambda{CalculationSet.find_config_file("fuel")}.should raise_error
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should call load_set if no set exists in class hash" do
|
78
|
-
CalculationSet.sets[:transport].should be_nil
|
79
|
-
flexmock(AMEE::DataAbstraction::CalculationSet) do |mock|
|
80
|
-
mock.should_receive(:load_set).once
|
81
|
-
end
|
82
|
-
set = CalculationSet.find('transport')
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should not call load_set if set exists in class hash" do
|
86
|
-
CalculationSet.sets[:transport].should be_nil
|
87
|
-
set = CalculationSet.find('transport')
|
88
|
-
CalculationSet.sets[:transport].should be_a CalculationSet
|
89
|
-
flexmock(AMEE::DataAbstraction::CalculationSet) do |mock|
|
90
|
-
mock.should_receive(:load_set).never
|
91
|
-
end
|
92
|
-
set = CalculationSet.find('transport')
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should generate set from file name using find method" do
|
96
|
-
CalculationSet.sets[:transport].should be_nil
|
97
|
-
set = CalculationSet.find('transport')
|
98
|
-
set.should be_a CalculationSet
|
99
|
-
CalculationSet.sets[:transport].should be_a CalculationSet
|
100
|
-
set.name.should eql 'transport'
|
101
|
-
set.file.should eql "#{Rails.root}/config/calculations/transport.rb"
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should regenerate lock file at default location" do
|
105
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
106
|
-
File.exist?(lock_file).should be_false
|
107
|
-
CalculationSet.sets[:transport].should be_nil
|
108
|
-
set = CalculationSet.find('transport')
|
109
|
-
File.exist?(lock_file).should be_false
|
110
|
-
CalculationSet.sets[:transport].should be_a CalculationSet
|
111
|
-
|
112
|
-
set.generate_lock_file
|
113
|
-
File.exist?(lock_file).should be_true
|
114
|
-
|
115
|
-
# lock file content
|
116
|
-
content = File.open(lock_file).read
|
117
|
-
|
118
|
-
# clear lock file to test for regenerated data
|
119
|
-
File.open(lock_file,'w') {|file| file.write "overwrite content"}
|
120
|
-
File.open(lock_file).read.should eql "overwrite content"
|
121
|
-
File.exist?(lock_file).should be_true
|
122
|
-
|
123
|
-
# regenerate and test content matches original
|
124
|
-
CalculationSet.regenerate_lock_file('transport')
|
125
|
-
File.exist?(lock_file).should be_true
|
126
|
-
File.open(lock_file).read.should eql content
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should regenerate lock file at custom location" do
|
130
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
131
|
-
File.exist?(lock_file).should be_false
|
132
|
-
CalculationSet.sets[:transport].should be_nil
|
133
|
-
set = CalculationSet.find('transport')
|
134
|
-
File.exist?(lock_file).should be_false
|
135
|
-
CalculationSet.sets[:transport].should be_a CalculationSet
|
136
|
-
|
137
|
-
set.generate_lock_file
|
138
|
-
File.exist?(lock_file).should be_true
|
139
|
-
|
140
|
-
content = File.open(lock_file).read
|
141
|
-
File.open(lock_file,'w') {|file| file.write "overwrite content"}
|
142
|
-
File.open(lock_file).read.should eql "overwrite content"
|
143
|
-
File.exist?(lock_file).should be_true
|
144
|
-
|
145
|
-
CalculationSet.regenerate_lock_file('transport', "#{Rails.root}/transport.lock.rb")
|
146
|
-
File.exist?(lock_file).should be_true
|
147
|
-
File.exist?("#{Rails.root}/transport.lock.rb").should be_true
|
148
|
-
File.open(lock_file).read.should eql "overwrite content"
|
149
|
-
File.open("#{Rails.root}/transport.lock.rb").read.should eql content
|
150
|
-
|
151
|
-
File.delete("#{Rails.root}/transport.lock.rb")
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should return a lock file path based on master config file" do
|
155
|
-
set = CalculationSet.find('transport')
|
156
|
-
set.lock_file_path.should eql "#{Rails.root}/config/calculations/transport.lock.rb"
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should return lock file path if lock file exists" do
|
160
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
161
|
-
File.exist?(lock_file).should be_false
|
162
|
-
set = CalculationSet.find('transport')
|
163
|
-
File.exist?(lock_file).should be_false
|
164
|
-
set.generate_lock_file
|
165
|
-
File.exist?(lock_file).should be_true
|
166
|
-
set.config_path.should eql lock_file
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should return master file path if lock file does not exist" do
|
170
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
171
|
-
File.exist?(lock_file).should be_false
|
172
|
-
set = CalculationSet.find('transport')
|
173
|
-
File.exist?(lock_file).should be_false
|
174
|
-
set.config_path.should eql "#{Rails.root}/config/calculations/transport.rb"
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should know if lock file exists" do
|
178
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
179
|
-
File.exist?(lock_file).should be_false
|
180
|
-
set = CalculationSet.find('transport')
|
181
|
-
File.exist?(lock_file).should be_false
|
182
|
-
set.generate_lock_file
|
183
|
-
File.exist?(lock_file).should be_true
|
184
|
-
set.lock_file_exists?.should be_true
|
185
|
-
File.delete(lock_file)
|
186
|
-
File.exist?(lock_file).should be_false
|
187
|
-
set.lock_file_exists?.should be_false
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should generate lock file" do
|
191
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
192
|
-
File.exist?(lock_file).should be_false
|
193
|
-
|
194
|
-
set = CalculationSet.find('transport')
|
195
|
-
File.exist?(lock_file).should be_false
|
196
|
-
set.lock_file_exists?.should be_false
|
197
|
-
|
198
|
-
set.generate_lock_file
|
199
|
-
File.exist?(lock_file).should be_true
|
200
|
-
set.lock_file_exists?.should be_true
|
201
|
-
|
202
|
-
content = File.open(lock_file).read
|
203
|
-
|
204
|
-
File.delete(lock_file)
|
205
|
-
File.exist?(lock_file).should be_false
|
206
|
-
set.lock_file_exists?.should be_false
|
207
|
-
|
208
|
-
set.generate_lock_file
|
209
|
-
File.exist?(lock_file).should be_true
|
210
|
-
set.lock_file_exists?.should be_true
|
211
|
-
File.open(lock_file).read.should eql content
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should generate lock file at custom location" do
|
215
|
-
lock_file = "#{Rails.root}/config/calculations/transport.lock.rb"
|
216
|
-
File.exist?(lock_file).should be_false
|
217
|
-
|
218
|
-
set = CalculationSet.find('transport')
|
219
|
-
File.exist?(lock_file).should be_false
|
220
|
-
set.lock_file_exists?.should be_false
|
221
|
-
|
222
|
-
set.generate_lock_file("#{Rails.root}/transport.lock.rb")
|
223
|
-
File.exist?(lock_file).should be_false
|
224
|
-
set.lock_file_exists?.should be_false
|
225
|
-
|
226
|
-
File.exist?("#{Rails.root}/transport.lock.rb").should be_true
|
227
|
-
|
228
|
-
File.delete("#{Rails.root}/transport.lock.rb")
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
it "can find a prototype calc without calc set" do
|
234
|
-
CalculationSet.new('my_set') {
|
235
|
-
calculation {label :my_calc}
|
236
|
-
calculation {label :my_other_calc}
|
237
|
-
}
|
238
|
-
CalculationSet.new('your_set') {
|
239
|
-
calculation {label :your_calc}
|
240
|
-
calculation {label :your_other_calc}
|
241
|
-
}
|
242
|
-
CalculationSet.find_prototype_calculation(:transport).should be_a PrototypeCalculation
|
243
|
-
CalculationSet.find_prototype_calculation(:your_calc).should be_a PrototypeCalculation
|
244
|
-
CalculationSet.find_prototype_calculation(:my_other_calc).should be_a PrototypeCalculation
|
245
|
-
end
|
246
|
-
|
247
|
-
it "returns nil where no prototype calcualtion is found" do
|
248
|
-
CalculationSet.find_prototype_calculation(:fuel).should be_nil
|
19
|
+
ElectricityAndTransport[:transport].should be_a PrototypeCalculation
|
249
20
|
end
|
250
|
-
|
251
21
|
it 'can construct a calculation' do
|
252
|
-
CalculationSet.new
|
22
|
+
CalculationSet.new {calculation {label :mycalc}}[:mycalc].should be_a PrototypeCalculation
|
253
23
|
end
|
254
|
-
|
255
24
|
it 'can be initialized with a DSL block' do
|
256
|
-
CalculationSet.new
|
25
|
+
CalculationSet.new {call_me}
|
257
26
|
CalculationSet.called.should be_true
|
258
27
|
end
|
259
|
-
|
260
28
|
it 'can have terms added to all calculations' do
|
261
|
-
cs=CalculationSet.new
|
29
|
+
cs=CalculationSet.new {
|
262
30
|
all_calculations {
|
263
31
|
drill {label :energetic}
|
264
32
|
}
|
@@ -269,7 +37,6 @@ describe CalculationSet do
|
|
269
37
|
}
|
270
38
|
cs[:mycalc].drills.labels.should eql [:remarkably,:energetic]
|
271
39
|
end
|
272
|
-
|
273
40
|
it 'can make multiple calculations quickly, one for each usage' do
|
274
41
|
mocker=AMEEMocker.new(self,:path=>'something')
|
275
42
|
mocker.item_value_definitions.usages(['bybob','byfrank']).
|
@@ -277,7 +44,7 @@ describe CalculationSet do
|
|
277
44
|
item_value_definition('first',['bybob'],[],'byfrank',[],nil,nil,true,false,nil,"TEXT").
|
278
45
|
item_value_definition('second',['bybob'],[],'byfrank',[],nil,nil,true,false,nil,"TEXT").
|
279
46
|
item_value_definition('third',['byfrank'],[],['bybob'],[],nil,nil,true,false,nil,"TEXT")
|
280
|
-
cs=CalculationSet.new
|
47
|
+
cs=CalculationSet.new {
|
281
48
|
calculations_all_usages('/something') { |usage|
|
282
49
|
label usage.to_sym
|
283
50
|
profiles_from_usage usage
|
@@ -286,5 +53,4 @@ describe CalculationSet do
|
|
286
53
|
cs[:bybob].profiles.labels.should eql [:first,:second]
|
287
54
|
cs[:byfrank].profiles.labels.should eql [:third]
|
288
55
|
end
|
289
|
-
|
290
56
|
end
|