spec/earth/industry/mecs_ratio_spec.rb in earth-1.0.0 vs spec/earth/industry/mecs_ratio_spec.rb in earth-1.0.1
- old
+ new
@@ -1,59 +1,63 @@
require 'spec_helper'
-require 'earth/industry/mecs_ratio'
-require 'earth/industry/industry' # MecsRatio's custom find by method calls an Industry method
+require "#{Earth::FACTORY_DIR}/mecs_ratio"
describe MecsRatio do
- describe 'verify imported data', :sanity => true do
- it 'should have all the data' do
- MecsRatio.count.should == 395
- end
- it 'spot checks the data' do
- apparel = MecsRatio.find_by_naics_code '315'
- apparel.census_region_number.should be_nil
- apparel.energy_per_dollar_of_shipments.should be_within(5e-6).of(0.5.kbtus.to(:megajoules))
- apparel.energy_per_dollar_of_shipments_units.should == 'megajoules'
- end
- end
-
describe '.find_by_naics_code_and_census_region_number' do
it 'finds an exact match' do
- MecsRatio.find_by_naics_code_and_census_region_number('311221', 2).
- name.should == '311221-2'
+ ratio = FactoryGirl.create :mecs_ratio, :r1111c1
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
end
it 'finds a parent category when exact code is not present' do
- MecsRatio.find_by_naics_code_and_census_region_number('3117', 2).
- name.should == '311-2'
+ ratio = FactoryGirl.create :mecs_ratio, :r111c1
+ MecsRatio.find_by_naics_code_and_census_region_number('111', 1).should == ratio
end
it 'finds same category nationwide when census region is not present' do
- MecsRatio.find_by_naics_code_and_census_region_number('311221', 5).
- name.should == '311221-'
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
end
- it 'looks nationwide and at parent codes if energy per dollar of shipments is missing' do
- MecsRatio.find_by_naics_code_and_census_region_number('313', 4).
- name.should == '313-'
+ it 'keeps looking if energy per dollar of shipments is missing' do
+ FactoryGirl.create :mecs_ratio, :r1111c2
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 2).should == ratio
end
it 'finds a parent category rather than a sibling category' do
- MecsRatio.find_by_naics_code_and_census_region_number('311225', 2).
- name.should == '3112-2'
+ FactoryGirl.create :mecs_ratio, :r1112c1
+ ratio = FactoryGirl.create :mecs_ratio, :r11c1
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
end
it 'returns nil if no match found' do
- MecsRatio.find_by_naics_code_and_census_region_number('543211', 2).
- should be_nil
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should be_nil
end
end
describe '.find_by_naics_code' do
it 'finds an exact match' do
- MecsRatio.find_by_naics_code('311221').name.should == '311221-'
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
+ MecsRatio.find_by_naics_code('1111').should == ratio
end
it 'finds a parent category when exact code is not present' do
- MecsRatio.find_by_naics_code('3117').name.should == '311-'
+ ratio = FactoryGirl.create :mecs_ratio, :r111
+ MecsRatio.find_by_naics_code('1111').should == ratio
end
it 'finds a parent category rather than a sibling category' do
- MecsRatio.find_by_naics_code('311225').name.should == '3112-'
+ FactoryGirl.create :mecs_ratio, :r1112
+ ratio = FactoryGirl.create :mecs_ratio, :r11
+ MecsRatio.find_by_naics_code('1111').should == ratio
end
it 'returns nil if no match found' do
- MecsRatio.find_by_naics_code('543211').should be_nil
+ MecsRatio.find_by_naics_code('1111').should be_nil
+ end
+ end
+
+ describe 'Sanity check', :sanity => true do
+ it 'should have all the data' do
+ MecsRatio.count.should == 395
+ end
+ it 'spot checks the data' do
+ apparel = MecsRatio.find_by_naics_code '315'
+ apparel.census_region_number.should be_nil
+ apparel.energy_per_dollar_of_shipments.should be_within(5e-6).of(0.5.kbtus.to(:megajoules))
+ apparel.energy_per_dollar_of_shipments_units.should == 'megajoules'
end
end
end