amee-data-abstraction 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,58 +1,53 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
|
3
2
|
describe Calculation do
|
4
3
|
|
5
|
-
before :all do
|
6
|
-
@calc = CalculationSet.find("transport")[:transport]
|
7
|
-
end
|
8
|
-
|
9
4
|
it 'can create an instance' do
|
10
|
-
|
5
|
+
Transport.should be_a Calculation
|
11
6
|
end
|
12
7
|
it 'should have ordered terms, with labels' do
|
13
|
-
|
8
|
+
Transport.terms.labels.should eql [:fuel,:size,:distance,:co2]
|
14
9
|
end
|
15
10
|
it 'should have amee paths for the terms' do
|
16
|
-
|
11
|
+
Transport.terms.paths.should eql ['fuel','size','distance',:default]
|
17
12
|
end
|
18
13
|
it 'should have human names for the terms' do
|
19
|
-
|
14
|
+
Transport.terms.names.
|
20
15
|
should eql ['Fuel Type','Vehicle Size','Distance Driven','Carbon Dioxide']
|
21
16
|
end
|
22
17
|
it 'should return the inputs' do
|
23
|
-
|
18
|
+
Transport.inputs.labels.should eql [:fuel,:size,:distance]
|
24
19
|
end
|
25
20
|
it 'should return the outputs' do
|
26
|
-
|
21
|
+
Transport.outputs.labels.should eql [:co2]
|
27
22
|
end
|
28
23
|
it 'should generate an discover URL' do
|
29
|
-
|
24
|
+
Transport.discover_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
|
30
25
|
end
|
31
26
|
it 'should redirect to discover URL' do
|
32
|
-
|
27
|
+
Transport.explorer_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
|
33
28
|
end
|
34
29
|
it 'can return a term via []' do
|
35
|
-
|
30
|
+
Transport[:co2].label.should eql :co2
|
36
31
|
end
|
37
32
|
it 'when copied, should deep copy the values' do
|
38
|
-
x
|
33
|
+
x=Transport.clone
|
39
34
|
x[:co2].value :somevalue
|
40
35
|
x[:co2].value.should eql :somevalue
|
41
|
-
|
36
|
+
Transport[:co2].value.should be_nil
|
42
37
|
end
|
43
38
|
it 'knows to get terms that come before or after others' do
|
44
|
-
t
|
39
|
+
t=Transport.clone
|
45
40
|
t.before(:distance).labels.
|
46
41
|
should eql [:fuel,:size]
|
47
42
|
t.after(:distance).map(&:label).
|
48
43
|
should eql [:co2]
|
49
44
|
end
|
50
45
|
it 'delegates selectors to terms list' do
|
51
|
-
t
|
46
|
+
t=Transport.clone
|
52
47
|
t.drills.labels.should eql [:fuel,:size]
|
53
48
|
end
|
54
49
|
it 'can find its amee data category' do
|
55
|
-
t
|
50
|
+
t=Transport.clone
|
56
51
|
mocker=AMEEMocker.new self,:path=>'transport/car/generic'
|
57
52
|
mocker.data_category
|
58
53
|
t.send(:amee_data_category).path.should eql '/data/transport/car/generic'
|
@@ -60,18 +55,18 @@ describe Calculation do
|
|
60
55
|
it 'can find its amee item definition' do
|
61
56
|
mocker=AMEEMocker.new self,:path=>'transport/car/generic'
|
62
57
|
mocker.item_definition(:my_itemdef_name).data_category
|
63
|
-
t
|
58
|
+
t=Transport.clone
|
64
59
|
t.send(:amee_item_definition).name.should eql :my_itemdef_name
|
65
60
|
end
|
66
61
|
it 'can give item value definition list' do
|
67
62
|
mocker=AMEEMocker.new self,:path=>'transport/car/generic'
|
68
63
|
mocker.item_value_definition('distance').item_value_definitions.
|
69
64
|
item_definition.data_category
|
70
|
-
t
|
65
|
+
t=Transport.clone
|
71
66
|
t.send(:amee_ivds).first.path.should eql 'distance'
|
72
67
|
end
|
73
68
|
it 'can memoise access to AMEE' do
|
74
|
-
t
|
69
|
+
t=Transport.clone
|
75
70
|
#AMEE::Data::Category.get(connection, "/data#{path}")
|
76
71
|
flexmock(AMEE::Data::Category).should_receive(:get).
|
77
72
|
with(AMEE::DataAbstraction.connection,'/data/transport/car/generic').
|
@@ -1,30 +1,21 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
|
3
2
|
describe Drill do
|
4
|
-
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
@calc = CalculationSet.find("transport")[:transport]
|
8
|
-
end
|
9
|
-
|
10
3
|
it 'knows its options when it is the first choice' do
|
11
4
|
AMEEMocker.new(self,:path=>'transport/car/generic',
|
12
5
|
:selections=>[],
|
13
6
|
:choices=>['diesel','petrol']).drill
|
14
|
-
|
7
|
+
Transport.begin_calculation[:fuel].send(:choices).should eql ['diesel','petrol']
|
15
8
|
end
|
16
|
-
|
17
9
|
it 'knows its options when it is a later choice' do
|
18
10
|
AMEEMocker.new(self,:path=>'transport/car/generic',
|
19
11
|
:selections=>[['fuel','diesel']],
|
20
12
|
:choices=>['large','small']).drill
|
21
|
-
t
|
13
|
+
t=Transport.begin_calculation
|
22
14
|
t[:fuel].value 'diesel'
|
23
15
|
t[:size].send(:choices).should eql ['large','small']
|
24
16
|
end
|
25
|
-
|
26
|
-
|
27
|
-
t=@calc.begin_calculation
|
17
|
+
it 'is enabled iff it is the next choice or has been chosen' do
|
18
|
+
t=Transport.begin_calculation
|
28
19
|
t[:fuel].enabled?.should be_true
|
29
20
|
t[:size].enabled?.should be_false
|
30
21
|
t[:fuel].value 'diesel'
|
@@ -34,32 +25,14 @@ describe Drill do
|
|
34
25
|
t[:fuel].enabled?.should be_true
|
35
26
|
t[:size].enabled?.should be_true
|
36
27
|
end
|
37
|
-
|
38
|
-
it 'is valid if assigned a choice in the choices' do
|
28
|
+
it 'is valid iff assigned a choice in the choices' do
|
39
29
|
AMEEMocker.new(self,:path=>'transport/car/generic',
|
40
30
|
:selections=>[],
|
41
31
|
:choices=>['diesel','petrol']).drill
|
42
|
-
t
|
32
|
+
t=Transport.begin_calculation
|
43
33
|
t[:fuel].value 'diesel'
|
44
34
|
t[:fuel].send(:valid?).should be_true
|
45
35
|
t[:fuel].value 'banana'
|
46
36
|
t[:fuel].send(:valid?).should be_false
|
47
37
|
end
|
48
|
-
|
49
|
-
it "should set and get custom choices" do
|
50
|
-
t=@calc.begin_calculation
|
51
|
-
t[:fuel].choices 'anthracite', 'lignite'
|
52
|
-
t[:fuel].choices.should eql ['anthracite', 'lignite']
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'is sets correct single choice if AMEE skips during drill' do
|
56
|
-
mocker = AMEEMocker.new(self,:path=>'transport/car/generic',
|
57
|
-
:selections=>[['fuel','diesel']])
|
58
|
-
mocker.drill_with_skip('size'=>'small')
|
59
|
-
t=@calc.begin_calculation
|
60
|
-
t[:fuel].value 'diesel'
|
61
|
-
t[:fuel].should_not be_disabled
|
62
|
-
t[:size].choices.should eql ['small']
|
63
|
-
t[:size].should be_disabled
|
64
|
-
end
|
65
38
|
end
|
@@ -1,117 +1,77 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe Input do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
it 'can be given a fixed value' do
|
5
|
+
i=Input.new{fixed 6}
|
6
|
+
i.value.should eql 6
|
7
|
+
i.fixed?.should be_true
|
8
|
+
lambda{i.value 7}.should raise_error Exceptions::FixedValueInterference
|
9
|
+
end
|
10
|
+
it 'raises exception when invalid' do
|
11
|
+
i=Input.new{validation /bark/}
|
12
|
+
i.value 'barking'
|
13
|
+
lambda{i.validate!}.should_not raise_error
|
14
|
+
i.value.should eql 'barking'
|
15
|
+
i.value 'marking'
|
16
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
17
|
+
j=Input.new{}
|
18
|
+
j.value 'marking'
|
19
|
+
j.value.should eql 'marking'
|
20
|
+
end
|
21
|
+
it "can accept a numeric symbol validation" do
|
22
|
+
i=Input.new{validation :numeric}
|
23
|
+
i.value 3
|
24
|
+
lambda{i.validate!}.should_not raise_error
|
25
|
+
i.value '3'
|
26
|
+
lambda{i.validate!}.should_not raise_error
|
27
|
+
i.value 'e'
|
28
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
29
|
+
end
|
30
|
+
it "can accept a date symbol validation" do
|
31
|
+
i=Input.new{validation :date}
|
32
|
+
i.value Date.today
|
33
|
+
lambda{i.validate!}.should_not raise_error
|
34
|
+
i.value '2011-01-01'
|
35
|
+
lambda{i.validate!}.should_not raise_error
|
36
|
+
i.value 'e'
|
37
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
38
|
+
end
|
11
39
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
lambda{i.validate!}.should_not raise_error
|
50
|
-
i.value 'e'
|
51
|
-
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
52
|
-
end
|
53
|
-
|
54
|
-
it "can accept a date symbol validation" do
|
55
|
-
i=Input.new{validation :date}
|
56
|
-
i.value Date.today
|
57
|
-
lambda{i.validate!}.should_not raise_error
|
58
|
-
i.value '2011-01-01'
|
59
|
-
lambda{i.validate!}.should_not raise_error
|
60
|
-
i.value 'e'
|
61
|
-
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can accept a time symbol validation" do
|
65
|
-
i=Input.new{validation :datetime}
|
66
|
-
i.value DateTime.now
|
67
|
-
lambda{i.validate!}.should_not raise_error
|
68
|
-
i.value '2011-01-01 09:00:00'
|
69
|
-
lambda{i.validate!}.should_not raise_error
|
70
|
-
i.value 'e'
|
71
|
-
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should start with dirty set as false" do
|
75
|
-
i=Input.new{fixed 5}
|
76
|
-
i.dirty?.should eql false
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should be dirty when the value is changed" do
|
80
|
-
i=Input.new
|
81
|
-
i.value 5
|
82
|
-
i.dirty?.should eql true
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'can have custom validation message' do
|
86
|
-
i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
|
87
|
-
i.value 'marking'
|
88
|
-
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
|
89
|
-
j=Input.new{}
|
90
|
-
j.value 'marking'
|
91
|
-
j.value.should eql 'marking'
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'can have default validation message' do
|
95
|
-
i=Input.new{label :woof; validation /bark/}
|
96
|
-
i.value 'barking'
|
97
|
-
lambda{i.validate!}.should_not raise_error
|
98
|
-
i.value.should eql 'barking'
|
99
|
-
i.value 'marking'
|
100
|
-
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
|
101
|
-
j=Input.new{}
|
102
|
-
j.value 'marking'
|
103
|
-
j.value.should eql 'marking'
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'is always valid if it is fixed' do
|
107
|
-
i=Input.new{fixed 5; validation /7/}
|
108
|
-
lambda{i.validate!}.should_not raise_error
|
109
|
-
i.value.should eql 5
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'is always disabled if it is fixed' do
|
113
|
-
i=Input.new{fixed 5}
|
114
|
-
i.disabled?.should eql true
|
115
|
-
end
|
116
|
-
|
40
|
+
it "can accept a time symbol validation" do
|
41
|
+
i=Input.new{validation :datetime}
|
42
|
+
i.value DateTime.now
|
43
|
+
lambda{i.validate!}.should_not raise_error
|
44
|
+
i.value '2011-01-01 09:00:00'
|
45
|
+
lambda{i.validate!}.should_not raise_error
|
46
|
+
i.value 'e'
|
47
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
|
48
|
+
end
|
49
|
+
it 'can have custom validation message' do
|
50
|
+
i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
|
51
|
+
i.value 'marking'
|
52
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
|
53
|
+
j=Input.new{}
|
54
|
+
j.value 'marking'
|
55
|
+
j.value.should eql 'marking'
|
56
|
+
end
|
57
|
+
it 'can have default validation message' do
|
58
|
+
i=Input.new{label :woof; validation /bark/}
|
59
|
+
i.value 'barking'
|
60
|
+
lambda{i.validate!}.should_not raise_error
|
61
|
+
i.value.should eql 'barking'
|
62
|
+
i.value 'marking'
|
63
|
+
lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
|
64
|
+
j=Input.new{}
|
65
|
+
j.value 'marking'
|
66
|
+
j.value.should eql 'marking'
|
67
|
+
end
|
68
|
+
it 'is always valid if it is fixed' do
|
69
|
+
i=Input.new{fixed 5; validation /7/}
|
70
|
+
lambda{i.validate!}.should_not raise_error
|
71
|
+
i.value.should eql 5
|
72
|
+
end
|
73
|
+
it 'is always disabled if it is fixed' do
|
74
|
+
i=Input.new{fixed 5}
|
75
|
+
i.disabled?.should eql true
|
76
|
+
end
|
117
77
|
end
|
@@ -1,15 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
|
3
2
|
describe OngoingCalculation do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
@elec = CalculationSet.find("electricity")[:electricity]
|
7
|
-
@transport = CalculationSet.find("transport")[:transport]
|
8
|
-
@elec_and_transport = CalculationSet.find("electricity_and_transport")
|
9
|
-
end
|
10
|
-
|
11
3
|
it 'can return set and unset inputs' do
|
12
|
-
d
|
4
|
+
d=Electricity.begin_calculation
|
13
5
|
d.inputs.set.labels.should eql [:country]
|
14
6
|
d.inputs.unset.labels.should eql [:energy_used]
|
15
7
|
d[:energy_used].value :somevalue
|
@@ -17,7 +9,7 @@ describe OngoingCalculation do
|
|
17
9
|
d.inputs.unset.labels.should eql []
|
18
10
|
end
|
19
11
|
it 'can return set and unset terms' do
|
20
|
-
d
|
12
|
+
d=Electricity.begin_calculation
|
21
13
|
d.set.labels.should eql [:country]
|
22
14
|
d.unset.labels.should eql [:energy_used,:co2]
|
23
15
|
d[:energy_used].value :somevalue
|
@@ -25,27 +17,19 @@ describe OngoingCalculation do
|
|
25
17
|
d.unset.labels.should eql [:co2]
|
26
18
|
end
|
27
19
|
it 'can return set and unset outputs' do
|
28
|
-
d
|
20
|
+
d=Electricity.begin_calculation
|
29
21
|
d.outputs.set.labels.should eql []
|
30
22
|
d.outputs.unset.labels.should eql [:co2]
|
31
23
|
d[:co2].value 5
|
32
24
|
d.outputs.set.labels.should eql [:co2]
|
33
25
|
d.outputs.unset.labels.should eql []
|
34
26
|
end
|
35
|
-
it 'can clear outputs' do
|
36
|
-
d=@elec.begin_calculation
|
37
|
-
d.outputs.unset.labels.should eql [:co2]
|
38
|
-
d[:co2].value 5
|
39
|
-
d[:co2].value.should eql 5
|
40
|
-
d.clear_outputs
|
41
|
-
d[:co2].value.should be_nil
|
42
|
-
end
|
43
27
|
it 'can have values chosen' do
|
44
28
|
AMEEMocker.new(self,:path=>'business/energy/electricity/grid',
|
45
29
|
:selections=>[['country','argentina']],
|
46
30
|
:choices=>[]).drill
|
47
31
|
|
48
|
-
d
|
32
|
+
d=Electricity.begin_calculation
|
49
33
|
|
50
34
|
d.inputs.set.values.should eql ['argentina']
|
51
35
|
d.inputs.unset.values.should eql [nil]
|
@@ -59,7 +43,7 @@ describe OngoingCalculation do
|
|
59
43
|
AMEEMocker.new(self,:path=>'business/energy/electricity/grid',
|
60
44
|
:selections=>[['country','argentina']],
|
61
45
|
:choices=>[]).drill
|
62
|
-
d
|
46
|
+
d=Electricity.begin_calculation
|
63
47
|
d.satisfied?.should be_false
|
64
48
|
d.choose!(:energy_used=>5.0)
|
65
49
|
d.satisfied?.should be_true
|
@@ -74,7 +58,7 @@ describe OngoingCalculation do
|
|
74
58
|
mocker.select('size'=>'large')
|
75
59
|
mocker.choices=[]
|
76
60
|
mocker.drill
|
77
|
-
t
|
61
|
+
t=Transport.begin_calculation
|
78
62
|
t.terms.labels.should eql [:fuel,:size,:distance,:co2]
|
79
63
|
t.satisfied?.should be_false
|
80
64
|
|
@@ -83,13 +67,13 @@ describe OngoingCalculation do
|
|
83
67
|
t.inputs.unset.labels.should eql [:size,:distance]
|
84
68
|
t.satisfied?.should be_false
|
85
69
|
|
86
|
-
t2
|
70
|
+
t2=Transport.begin_calculation
|
87
71
|
t2.choose!('fuel'=>'diesel','size'=>'large')
|
88
72
|
t2.inputs.set.labels.should eql [:fuel,:size]
|
89
73
|
t2.inputs.unset.labels.should eql [:distance]
|
90
74
|
t2.satisfied?.should be_false
|
91
75
|
|
92
|
-
t3
|
76
|
+
t3=Transport.begin_calculation
|
93
77
|
t3.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
94
78
|
t3.inputs.set.labels.should eql [:fuel,:size,:distance]
|
95
79
|
t3.inputs.unset.labels.should eql []
|
@@ -108,7 +92,7 @@ describe OngoingCalculation do
|
|
108
92
|
mocker.choices=[]
|
109
93
|
mocker.drill
|
110
94
|
mocker.profile_list.profile_category.timestamp.create_and_get
|
111
|
-
mycalc
|
95
|
+
mycalc=Transport.begin_calculation
|
112
96
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
113
97
|
mycalc.calculate!
|
114
98
|
mycalc.outputs.first.value.should eql :somenumber
|
@@ -126,7 +110,7 @@ describe OngoingCalculation do
|
|
126
110
|
mocker.choices=[]
|
127
111
|
mocker.drill
|
128
112
|
mocker.profile_list.profile_category.timestamp.create_and_get
|
129
|
-
mycalc
|
113
|
+
mycalc=ElectricityAndTransport[:transport].begin_calculation
|
130
114
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5,'department'=>'stuff')
|
131
115
|
mycalc.calculate!
|
132
116
|
mycalc.outputs.first.value.should eql :somenumber
|
@@ -150,7 +134,7 @@ describe OngoingCalculation do
|
|
150
134
|
#end
|
151
135
|
|
152
136
|
it 'can be supplied just a UID, and recover PIVs and drill values from AMEE' do
|
153
|
-
mycalc
|
137
|
+
mycalc=Transport.begin_calculation
|
154
138
|
mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
|
155
139
|
:result=>:somenumber,
|
156
140
|
:existing=>{'distance'=>5},:choices=>['petrol','diesel'])
|
@@ -167,7 +151,7 @@ describe OngoingCalculation do
|
|
167
151
|
end
|
168
152
|
|
169
153
|
it 'refuses to load values from AMEE which conflict with local drill values' do
|
170
|
-
mycalc
|
154
|
+
mycalc=Transport.begin_calculation
|
171
155
|
mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
|
172
156
|
:result=>:somenumber,
|
173
157
|
:existing=>{'distance'=>7},
|
@@ -203,7 +187,7 @@ describe OngoingCalculation do
|
|
203
187
|
mocker.choices=[]
|
204
188
|
mocker.drill
|
205
189
|
mocker.profile_list.update.get(true)
|
206
|
-
mycalc
|
190
|
+
mycalc=Transport.begin_calculation
|
207
191
|
mycalc.choose!(:profile_item_uid=>mocker.uid,'fuel'=>'diesel','size'=>'large','distance'=>9)
|
208
192
|
mycalc.calculate!
|
209
193
|
mycalc[:distance].value.should eql 9
|
@@ -227,7 +211,7 @@ describe OngoingCalculation do
|
|
227
211
|
mocker.params={'distance'=>9}
|
228
212
|
mocker.update.get(true)
|
229
213
|
|
230
|
-
mycalc
|
214
|
+
mycalc=Transport.begin_calculation
|
231
215
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
232
216
|
mycalc.calculate!
|
233
217
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>9)
|
@@ -252,7 +236,7 @@ describe OngoingCalculation do
|
|
252
236
|
mocker.select('size'=>'small')
|
253
237
|
mocker.drill.create_and_get
|
254
238
|
|
255
|
-
mycalc
|
239
|
+
mycalc=Transport.begin_calculation
|
256
240
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
257
241
|
mycalc.calculate!
|
258
242
|
mycalc.choose!('fuel'=>'diesel','size'=>'small')
|
@@ -261,7 +245,7 @@ describe OngoingCalculation do
|
|
261
245
|
end
|
262
246
|
|
263
247
|
it 'memoizes profile information, but not across a pass' do
|
264
|
-
mycalc
|
248
|
+
mycalc=Transport.begin_calculation
|
265
249
|
mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
|
266
250
|
:result=>:somenumber,
|
267
251
|
:existing=>{'distance'=>5},:choices=>['petrol','diesel'])
|
@@ -293,7 +277,7 @@ describe OngoingCalculation do
|
|
293
277
|
mocker.choices=[]
|
294
278
|
mocker.drill
|
295
279
|
mocker.profile_list.profile_category.timestamp.create_and_get
|
296
|
-
myproto
|
280
|
+
myproto=Transport.clone
|
297
281
|
myproto.instance_eval{
|
298
282
|
start_and_end_dates
|
299
283
|
}
|
@@ -316,7 +300,7 @@ describe OngoingCalculation do
|
|
316
300
|
mocker.select('size'=>'large')
|
317
301
|
mocker.choices=[]
|
318
302
|
mocker.drill
|
319
|
-
myproto
|
303
|
+
myproto=Transport.clone
|
320
304
|
myproto.instance_eval{
|
321
305
|
start_and_end_dates
|
322
306
|
}
|
@@ -326,7 +310,7 @@ describe OngoingCalculation do
|
|
326
310
|
end
|
327
311
|
|
328
312
|
it 'starts off dirty' do
|
329
|
-
mycalc
|
313
|
+
mycalc=Transport.begin_calculation
|
330
314
|
mycalc.should be_dirty
|
331
315
|
end
|
332
316
|
|
@@ -343,7 +327,7 @@ describe OngoingCalculation do
|
|
343
327
|
mocker.choices=[]
|
344
328
|
mocker.drill
|
345
329
|
mocker.profile_list.profile_category.timestamp.create_and_get
|
346
|
-
mycalc
|
330
|
+
mycalc=Transport.begin_calculation
|
347
331
|
mycalc.should be_dirty
|
348
332
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
349
333
|
mycalc.calculate!
|
@@ -365,7 +349,7 @@ describe OngoingCalculation do
|
|
365
349
|
mocker.choices=[]
|
366
350
|
mocker.drill
|
367
351
|
mocker.profile_list.profile_category.timestamp.create_and_get
|
368
|
-
mycalc
|
352
|
+
mycalc=Transport.begin_calculation
|
369
353
|
mycalc.should be_dirty
|
370
354
|
mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
|
371
355
|
mycalc.calculate!
|
@@ -388,7 +372,7 @@ describe OngoingCalculation do
|
|
388
372
|
mocker.select('size'=>'marge')
|
389
373
|
mocker.choices=[]
|
390
374
|
mocker.drill
|
391
|
-
mycalc
|
375
|
+
mycalc=Transport.begin_calculation
|
392
376
|
lambda{mycalc.choose!('fuel'=>'diesel','size'=>'marge','distance'=>5)}.should raise_error Exceptions::ChoiceValidation
|
393
377
|
mycalc.invalidity_messages.keys.should eql [:size]
|
394
378
|
end
|
@@ -405,7 +389,7 @@ describe OngoingCalculation do
|
|
405
389
|
mocker.select('size'=>'marge')
|
406
390
|
mocker.choices=[]
|
407
391
|
mocker.drill
|
408
|
-
mycalc
|
392
|
+
mycalc=Transport.begin_calculation
|
409
393
|
mycalc.choose('fuel'=>'diesel','size'=>'marge','distance'=>5).should be_false
|
410
394
|
mycalc.invalidity_messages.keys.should eql [:size]
|
411
395
|
end
|
@@ -422,12 +406,12 @@ describe OngoingCalculation do
|
|
422
406
|
mocker.select('size'=>'large')
|
423
407
|
mocker.choices=[]
|
424
408
|
mocker.drill
|
425
|
-
mycalc
|
409
|
+
mycalc=Transport.begin_calculation
|
426
410
|
mycalc.choose('fuel'=>'diesel','size'=>'large','distance'=>5).should be_true
|
427
411
|
end
|
428
412
|
|
429
413
|
it 'can blank individual term attributes with empty string' do
|
430
|
-
myproto
|
414
|
+
myproto=Transport.clone
|
431
415
|
mycalc=myproto.begin_calculation
|
432
416
|
mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
|
433
417
|
mycalc['fuel'].value.should eql 'diesel'
|
@@ -442,7 +426,7 @@ describe OngoingCalculation do
|
|
442
426
|
end
|
443
427
|
|
444
428
|
it 'can blank individual term attributes with nil' do
|
445
|
-
myproto
|
429
|
+
myproto=Transport.clone
|
446
430
|
mycalc=myproto.begin_calculation
|
447
431
|
mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
|
448
432
|
mycalc['fuel'].value.should eql 'diesel'
|
@@ -457,7 +441,7 @@ describe OngoingCalculation do
|
|
457
441
|
end
|
458
442
|
|
459
443
|
it 'can update individual term attributes without nullifying others' do
|
460
|
-
myproto
|
444
|
+
myproto=Transport.clone
|
461
445
|
mycalc=myproto.begin_calculation
|
462
446
|
mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
|
463
447
|
mycalc['fuel'].value.should eql 'diesel'
|
@@ -498,7 +482,7 @@ describe OngoingCalculation do
|
|
498
482
|
mocker.select('size'=>'marge')
|
499
483
|
mocker.choices=[]
|
500
484
|
mocker.drill
|
501
|
-
mycalc
|
485
|
+
mycalc=Transport.begin_calculation
|
502
486
|
mycalc.choose('fuel'=>'diesel','size'=>'marge','distance'=>5).should be_false
|
503
487
|
mycalc.invalidity_messages.keys.should eql [:size]
|
504
488
|
mycalc[:size].value.should eql 'marge'
|