Skip to content

Commit

Permalink
Rename update predictions methods to have !
Browse files Browse the repository at this point in the history
  • Loading branch information
Br3nda committed Apr 19, 2018
1 parent 3ed90b8 commit 279c922
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/harvests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def update_crop_medians
# if this harvest is not linked to a planting, then do nothing
return if @harvest.planting.nil?

@harvest.planting.update_harvest_days
@harvest.planting.update_harvest_days!
@harvest.crop.update_harvest_medians
end
end
2 changes: 1 addition & 1 deletion app/controllers/plantings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def update_crop_medians
end

def update_planting_medians
@planting.update_harvest_days
@planting.update_harvest_days!
end

def planting_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/crop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def rejection_explanation
end

def update_medians
plantings.each(&:update_harvest_days)
plantings.each(&:update_harvest_days!)
update_lifespan_medians
update_harvest_medians
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20171105011017_set_prediction_data.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SetPredictionData < ActiveRecord::Migration
def up
say "Updating all plantings time to first harvest"
Planting.all.each(&:update_harvest_days)
Planting.all.each(&:update_harvest_days!)
say "Updating crop median time to first harvest, and lifespan"
Crop.all.each do |crop|
crop.update_lifespan_medians
Expand Down
8 changes: 4 additions & 4 deletions spec/models/planting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def one_hundred_day_old_planting
FactoryBot.create(:harvest, harvested_at: 90.days.ago, crop: planting.crop,
planting: one_hundred_day_old_planting)

planting.crop.plantings.each(&:update_harvest_days)
planting.crop.plantings.each(&:update_harvest_days!)
planting.crop.update_lifespan_medians
planting.crop.update_harvest_medians
end
Expand All @@ -138,7 +138,7 @@ def one_hundred_day_old_planting
describe 'planting has no harvests' do
let(:planting) { FactoryBot.create :planting }
before do
planting.update_harvest_days
planting.update_harvest_days!
planting.crop.update_harvest_medians
end
it { expect(planting.days_to_first_harvest).to eq(nil) }
Expand All @@ -152,7 +152,7 @@ def one_hundred_day_old_planting
planting: planting,
crop: planting.crop,
harvested_at: 10.days.ago)
planting.update_harvest_days
planting.update_harvest_days!
planting.crop.update_harvest_medians
end
it { expect(planting.days_to_first_harvest).to eq(90) }
Expand All @@ -166,7 +166,7 @@ def one_hundred_day_old_planting
before do
FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 90.days.ago
FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 10.days.ago
planting.update_harvest_days
planting.update_harvest_days!
planting.crop.update_harvest_medians
end
it { expect(planting.days_to_first_harvest).to eq(10) }
Expand Down

0 comments on commit 279c922

Please sign in to comment.