Skip to content

Commit

Permalink
Merge de70d81 into b782069
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbeedle committed Apr 19, 2016
2 parents b782069 + de70d81 commit 419f8b9
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 14 deletions.
26 changes: 26 additions & 0 deletions db/migrate/10_fix_footnotes_indexes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class FixFootnotesIndexes < ActiveRecord::Migration
def change
change_table :usda_footnotes do |t|
t.remove_index :nutrient_databank_number
t.remove_index :footnote_number
t.remove_index :footnote_type
t.remove_index :nutrient_number

t.index [
:nutrient_databank_number,
:nutrient_number,
:footnote_number
], {
unique: true,
name: "index_usda_footnotes_on_unique_keys"
}

t.index [
:nutrient_databank_number,
:footnote_type
], {
name: "index_usda_footnotes_on_databank_number_and_type"
}
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/11_fix_usda_weights.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class FixUsdaWeights < ActiveRecord::Migration
def change
remove_column :usda_weights, :id

change_table :usda_weights do |t|
t.remove_index :nutrient_databank_number

t.index [
:nutrient_databank_number,
:sequence_number
], {
unique: true
}
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/12_fix_usda_foods_nutrients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class FixUsdaFoodsNutrients < ActiveRecord::Migration
def change
remove_column :usda_foods_nutrients, :id

change_table :usda_foods_nutrients do |t|
t.remove_index [
:nutrient_databank_number,
:nutrient_number
]
end
end
end
8 changes: 6 additions & 2 deletions lib/usda_nutrient_database/footnote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ module UsdaNutrientDatabase
class Footnote < ActiveRecord::Base
self.table_name = 'usda_footnotes'

validates :nutrient_databank_number, presence: true,
uniqueness: { allow_blank: true }
validates :nutrient_databank_number,
presence: true,
uniqueness: {
allow_blank: true,
scope: [ :footnote_number, :nutrient_number ]
}
validates :footnote_number, presence: true
validates :footnote_type, presence: true
validates :footnote_text, presence: true
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/food_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::FoodGroup do
describe UsdaNutrientDatabase::FoodGroup, type: :model do
it { should validate_presence_of(:code) }
it { should validate_presence_of(:description) }
end
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/food_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::Food do
describe UsdaNutrientDatabase::Food, type: :model do
it { should validate_presence_of(:nutrient_databank_number) }
it { should validate_presence_of(:food_group_code) }
it { should validate_presence_of(:long_description) }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/foods_nutrient_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::FoodsNutrient do
describe UsdaNutrientDatabase::FoodsNutrient, type: :model do
it { should validate_presence_of(:nutrient_databank_number) }
it { should validate_presence_of(:nutrient_number) }
it { should validate_presence_of(:nutrient_value) }
Expand Down
14 changes: 9 additions & 5 deletions spec/lib/usda_nutrient_database/footnote_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require 'spec_helper'

describe UsdaNutrientDatabase::Footnote do
it { should validate_presence_of(:nutrient_databank_number) }
it { should validate_presence_of(:footnote_number) }
it { should validate_presence_of(:footnote_type) }
it { should validate_presence_of(:footnote_text) }
describe UsdaNutrientDatabase::Footnote, type: :model do
# it 'validates uniqueness of nutrient_databank_number' do
# expect(subject)
# .to validate_uniqueness_of(:nutrient_databank_number)
# .scoped_to(:footnote_number, :nutrient_number)
# end
it { is_expected.to validate_presence_of(:footnote_number) }
it { is_expected.to validate_presence_of(:footnote_type) }
it { is_expected.to validate_presence_of(:footnote_text) }
end
1 change: 0 additions & 1 deletion 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 Down
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/nutrient_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::Nutrient do
describe UsdaNutrientDatabase::Nutrient, type: :model do
it { should validate_presence_of(:nutrient_number) }
it { should validate_presence_of(:units) }
it { should validate_presence_of(:nutrient_description) }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/source_code_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::SourceCode do
describe UsdaNutrientDatabase::SourceCode, type: :model do
it { validate_presence_of(:code) }
it { validate_presence_of(:description) }
end
2 changes: 1 addition & 1 deletion spec/lib/usda_nutrient_database/weight_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe UsdaNutrientDatabase::Weight do
describe UsdaNutrientDatabase::Weight, type: :model do
it { should validate_presence_of(:nutrient_databank_number) }
it { should validate_presence_of(:sequence_number) }
it { should validate_presence_of(:amount) }
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

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

Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
end
end

# This file was generated by the `rspec --init` command. Conventionally, all
Expand All @@ -28,6 +35,9 @@
config.run_all_when_everything_filtered = true
config.filter_run :focus

config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)

include Database

# Run specs in random order to surface order dependencies. If you find an
Expand Down

0 comments on commit 419f8b9

Please sign in to comment.