diff --git a/lib/usda_nutrient_database/import/base.rb b/lib/usda_nutrient_database/import/base.rb index 4908ab5..aa19702 100644 --- a/lib/usda_nutrient_database/import/base.rb +++ b/lib/usda_nutrient_database/import/base.rb @@ -19,7 +19,7 @@ def import attr_reader :directory def extract_row(row) - build_object(apply_typecasts(row)).save! + build_object(apply_typecasts(row)).save end def build_object(row) diff --git a/spec/lib/usda_nutrient_database/importer_spec.rb b/spec/lib/usda_nutrient_database/importer_spec.rb index 4971f70..9950d21 100644 --- a/spec/lib/usda_nutrient_database/importer_spec.rb +++ b/spec/lib/usda_nutrient_database/importer_spec.rb @@ -7,7 +7,6 @@ let(:sr_file) { File.read('spec/support/sr25.zip') } before do stub_request(:head, "https://www.ars.usda.gov/SP2UserFiles/Place/12354500/Data/SR25/dnload/sr25.zip"). - with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Faraday v0.9.1'}). to_return(:status => 200, :body => "", :headers => {}) stub_request(:get, /.*/). to_return(body: sr_file) @@ -20,9 +19,13 @@ expect(UsdaNutrientDatabase::Nutrient.count).to eql(15) expect(UsdaNutrientDatabase::FoodsNutrient.count).to eql(12) expect(UsdaNutrientDatabase::Weight.count).to eql(11) - expect(UsdaNutrientDatabase::Footnote.count).to eql(7) + expect(UsdaNutrientDatabase::Footnote.count).to eql(9) end + # NOTE Not sure how this one got past code review o.O. Need to clean up both + # the zip files in spec support to only have a few records and remove the + # PDF. Don't want people having to download megabytes of useless spec + # support files just to install this gem. context 'with sr27' do let(:sr_file) { File.read('spec/support/sr27.zip') } it 'should import the right number of records' do @@ -31,7 +34,7 @@ expect(UsdaNutrientDatabase::Nutrient.count).to eql(150) expect(UsdaNutrientDatabase::FoodsNutrient.count).to eql(476) expect(UsdaNutrientDatabase::Weight.count).to eql(18) - expect(UsdaNutrientDatabase::Footnote.count).to eql(362) + expect(UsdaNutrientDatabase::Footnote.count).to eql(531) end end @@ -44,7 +47,7 @@ expect(UsdaNutrientDatabase::Nutrient.count).to eql(15) expect(UsdaNutrientDatabase::FoodsNutrient.count).to eql(12) expect(UsdaNutrientDatabase::Weight.count).to eql(11) - expect(UsdaNutrientDatabase::Footnote.count).to eql(7) + expect(UsdaNutrientDatabase::Footnote.count).to eql(9) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 448528f..d8dc881 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,7 @@ UsdaNutrientDatabase.configure do |config| config.perform_logging = false + config.usda_version = 'sr25' end Shoulda::Matchers.configure do |config| @@ -57,7 +58,7 @@ begin ActiveRecord::Base.establish_connection(db_name.to_sym) ActiveRecord::Base.connection - rescue PG::ConnectionBad + rescue PG::ConnectionBad, ActiveRecord::NoDatabaseError ActiveRecord::Base.establish_connection db_config.merge('database' => nil) ActiveRecord::Base.connection.create_database db_config['database'] ActiveRecord::Base.establish_connection db_config @@ -75,6 +76,7 @@ end config.before do + DatabaseCleaner.clean DatabaseCleaner.start end