Skip to content

Commit

Permalink
make import spec pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbeedle committed Apr 19, 2016
1 parent 3633fa3 commit 4703557
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/usda_nutrient_database/import/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions spec/lib/usda_nutrient_database/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

UsdaNutrientDatabase.configure do |config|
config.perform_logging = false
config.usda_version = 'sr25'
end

Shoulda::Matchers.configure do |config|
Expand Down Expand Up @@ -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
Expand All @@ -75,6 +76,7 @@
end

config.before do
DatabaseCleaner.clean
DatabaseCleaner.start
end

Expand Down

0 comments on commit 4703557

Please sign in to comment.