Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changes for calc set

  • Loading branch information...
commit 8a85a713150d73a14f908b94a550da78e422fd03 1 parent d88fcf8
@spatchcock spatchcock authored
View
2  lib/amee-data-persistence.rb
@@ -7,7 +7,7 @@
require 'amee-data-abstraction'
require 'amee/data_abstraction/calculation_collection'
-require 'amee/data_abstraction/persistence_support'
+require 'amee/data_abstraction/ongoing_calculation_persistence_support'
require 'amee/db/calculation'
require 'amee/db/term'
require 'amee/db/config'
View
2  lib/amee/data_abstraction/persistence_support.rb → ...action/ongoing_calculation_persistence_support.rb
@@ -223,7 +223,7 @@ def initialize_from_db_record(record)
unless record.is_a? AMEE::Db::Calculation
raise ArgumentError.new("Argument is not of class AMEE::Db::Calculation")
end
- calc = Calculations.calculations[record.type].begin_calculation
+ calc = AMEE::DataAbstraction::CalculationSet.find_prototype_calculation(record.type).begin_calculation
calc.db_calculation = record
# Means that validation needs to occur before calcs are saved
calc.choose_without_validation!(record.to_hash)
View
2  lib/amee/db/config.rb
@@ -39,7 +39,7 @@ def store_everything?
private
def load_storage_method
- m = YAML.load_file("#{RAILS_ROOT}/config/persistence.yml")['method'].to_sym rescue nil
+ m = YAML.load_file("#{::Rails.root}/config/persistence.yml")['method'].to_sym rescue nil
raise "amee-data-persistence: Invalid storage method" unless [:metadata, :outputs, :everything].include? m
m
end
View
6 spec/amee/db/persistence_support_spec.rb → ...b/ongoing_calculation_persistence_support_spec.rb
@@ -4,7 +4,7 @@
before(:each) do
populate_db
- initialize_calculation_set
+ AMEE::DataAbstraction::CalculationSet.find("electricity")
end
after(:each) do
@@ -133,8 +133,8 @@
it "should give nil id, if not saved" do
- Calculations[:electricity].begin_calculation.db_calculation.should be_nil
- Calculations[:electricity].begin_calculation.id.should be_nil
+ AMEE::DataAbstraction::CalculationSet.find("electricity")[:electricity].begin_calculation.db_calculation.should be_nil
+ AMEE::DataAbstraction::CalculationSet.find("electricity")[:electricity].begin_calculation.id.should be_nil
end
end
View
25 spec/amee/fixtures/config/calculations/electricity.rb
@@ -0,0 +1,25 @@
+calculation {
+
+ name 'Electricity'
+ label :electricity
+ path '/business/energy/electricity/grid'
+
+ drill {
+ label :country
+ path 'country'
+ fixed 'Argentina'
+ }
+
+ profile {
+ label :usage
+ name 'Electricity Used'
+ path 'energyPerTime'
+ }
+
+ output {
+ label :co2
+ name 'Carbon Dioxide'
+ path 'default'
+ }
+
+}
View
33 spec/spec_helper.rb
@@ -8,7 +8,11 @@
config.mock_with :flexmock
end
-RAILS_ROOT = '.'
+class Rails
+ def self.root
+ File.dirname(__FILE__) + '/amee/fixtures'
+ end
+end
DB_CONFIG = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
DB_MIGRATION = File.join(File.dirname(__FILE__), '..','lib','generators','persistence','templates','db','migrate')
@@ -57,29 +61,4 @@ def populate_db
[ calculation_one, calculation_two, calculation_three ].each do |attr|
AMEE::Db::Calculation.new { |calc| calc.update_calculation! attr }
end
-end
-
-def initialize_calculation_set
- eval "Calculations = AMEE::DataAbstraction::CalculationSet.new {
- calculation{
- name 'Electricity'
- label :electricity
- path '/business/energy/electricity/grid'
- drill {
- label :country
- path 'country'
- fixed 'Argentina'
- }
- profile {
- label :usage
- name 'Electricity Used'
- path 'energyPerTime'
- }
- output {
- label :co2
- name 'Carbon Dioxide'
- path :default
- }
- }
- }"
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.