From 809dd813784c841aa4031bc8da01dd2b62241f4a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 8 Nov 2017 17:17:58 +1300 Subject: [PATCH] "Changed last_harvest" to "days_to_last_harvest" --- app/models/crop.rb | 2 +- app/models/planting.rb | 6 +++--- app/views/crops/_index_card.html.haml | 4 ++-- app/views/crops/_predictions.html.haml | 4 ++-- app/views/plantings/show.html.haml | 4 ++-- .../20171022032108_all_the_predictions.rb | 4 ++-- db/schema.rb | 18 +++++++++--------- spec/models/planting_spec.rb | 14 +++++++------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index d0c6044c5..44251ec36 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -222,7 +222,7 @@ class Crop < ActiveRecord::Base def update_harvest_medians update(median_days_to_first_harvest: Planting.where(crop: self).median(:days_to_first_harvest)) - update(median_last_harvest: Planting.where(crop: self).median(:last_harvest)) + update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest)) end private diff --git a/app/models/planting.rb b/app/models/planting.rb index 2f43818fb..8cc7eb921 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -116,14 +116,14 @@ class Planting < ActiveRecord::Base def update_harvest_days harvests_with_dates = harvests.where.not(harvested_at: nil) days_to_first_harvest = nil - last_harvest = nil + days_to_last_harvest = nil if planted_at.present? && harvests_with_dates.size.positive? days_to_first_harvest = (harvests_with_dates.order(harvested_at: :asc).first.harvested_at - planted_at).to_i if finished? - last_harvest = (harvests_with_dates.order(harvested_at: :desc).first.harvested_at - planted_at).to_i + days_to_last_harvest = (harvests_with_dates.order(harvested_at: :desc).first.harvested_at - planted_at).to_i end end - update(days_to_first_harvest: days_to_first_harvest, last_harvest: last_harvest) + update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest) end private diff --git a/app/views/crops/_index_card.html.haml b/app/views/crops/_index_card.html.haml index ae2146ae2..39b9e8da4 100644 --- a/app/views/crops/_index_card.html.haml +++ b/app/views/crops/_index_card.html.haml @@ -24,10 +24,10 @@ %b= crop.median_days_to_first_harvest days after planting - - if crop.annual? && crop.median_last_harvest.present? + - if crop.annual? && crop.median_days_to_last_harvest.present? %p Last harvest expected - %b= crop.median_last_harvest + %b= crop.median_days_to_last_harvest days after planting - if can? :create, Planting diff --git a/app/views/crops/_predictions.html.haml b/app/views/crops/_predictions.html.haml index 982b18898..86aaf8f43 100644 --- a/app/views/crops/_predictions.html.haml +++ b/app/views/crops/_predictions.html.haml @@ -22,8 +22,8 @@ %b= crop.median_days_to_first_harvest days after planting -- if crop.perennial == false && crop.median_last_harvest.present? +- if crop.perennial == false && crop.median_days_to_last_harvest.present? %p Last harvest expected - %b= crop.median_last_harvest + %b= crop.median_days_to_last_harvest days after planting diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 54e8a9abe..099571218 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -59,9 +59,9 @@ - if @planting.days_to_first_harvest.present? %dt First Harvest: %dd #{@planting.days_to_first_harvest} days after planting - - if @planting.last_harvest.present? + - if @planting.days_to_last_harvest.present? %dt Last Harvest: - %dd #{@planting.last_harvest} days after planting + %dd #{@planting.days_to_last_harvest} days after planting %p= render 'plantings/harvests', planting: @planting %p= render 'plantings/progress', planting: @planting, show_explanation: true diff --git a/db/migrate/20171022032108_all_the_predictions.rb b/db/migrate/20171022032108_all_the_predictions.rb index 70b28db28..ca1098491 100644 --- a/db/migrate/20171022032108_all_the_predictions.rb +++ b/db/migrate/20171022032108_all_the_predictions.rb @@ -7,12 +7,12 @@ class AllThePredictions < ActiveRecord::Migration # how old was planting at first harvest add_column :plantings, :days_to_first_harvest, :integer - add_column :plantings, :last_harvest, :integer + add_column :plantings, :days_to_last_harvest, :integer # Keep the median values for the crop add_column :crops, :median_lifespan, :integer add_column :crops, :median_days_to_first_harvest, :integer - add_column :crops, :median_last_harvest, :integer + add_column :crops, :median_days_to_last_harvest, :integer create_table :median_functions do |t| end diff --git a/db/schema.rb b/db/schema.rb index 6427edbd7..5bc01e1fa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -181,23 +181,23 @@ ActiveRecord::Schema.define(version: 20171105011017) do end create_table "crops", force: :cascade do |t| - t.string "name", null: false + t.string "name", null: false t.string "en_wikipedia_url" t.datetime "created_at" t.datetime "updated_at" t.string "slug" t.integer "parent_id" - t.integer "plantings_count", default: 0 + t.integer "plantings_count", default: 0 t.integer "creator_id" t.integer "requester_id" - t.string "approval_status", default: "approved" + t.string "approval_status", default: "approved" t.text "reason_for_rejection" t.text "request_notes" t.text "rejection_notes" - t.boolean "perennial", default: false + t.boolean "perennial", default: false t.integer "median_lifespan" t.integer "median_days_to_first_harvest" - t.integer "median_last_harvest" + t.integer "median_days_to_last_harvest" end add_index "crops", ["name"], name: "index_crops_on_name", using: :btree @@ -416,8 +416,8 @@ ActiveRecord::Schema.define(version: 20171105011017) do end create_table "plantings", force: :cascade do |t| - t.integer "garden_id", null: false - t.integer "crop_id", null: false + t.integer "garden_id", null: false + t.integer "crop_id", null: false t.date "planted_at" t.integer "quantity" t.text "description" @@ -427,12 +427,12 @@ ActiveRecord::Schema.define(version: 20171105011017) do t.string "sunniness" t.string "planted_from" t.integer "owner_id" - t.boolean "finished", default: false + t.boolean "finished", default: false t.date "finished_at" t.integer "days_before_maturity" t.integer "lifespan" t.integer "days_to_first_harvest" - t.integer "last_harvest" + t.integer "days_to_last_harvest" end add_index "plantings", ["slug"], name: "index_plantings_on_slug", unique: true, using: :btree diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 8f477d6f4..462bee3e4 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -83,9 +83,9 @@ describe Planting do context 'no data' do let(:planting) { FactoryBot.create :planting } it { expect(planting.crop.median_days_to_first_harvest).to eq(nil) } - it { expect(planting.crop.median_last_harvest).to eq(nil) } + it { expect(planting.crop.median_days_to_last_harvest).to eq(nil) } it { expect(planting.days_to_first_harvest).to eq(nil) } - it { expect(planting.last_harvest).to eq(nil) } + it { expect(planting.days_to_last_harvest).to eq(nil) } it { expect(planting.expected_lifespan).to eq(nil) } end context 'lots of data' do @@ -115,7 +115,7 @@ describe Planting do end let(:planting) { FactoryBot.create :planting } it { expect(planting.days_to_first_harvest).to eq(nil) } - it { expect(planting.last_harvest).to eq(nil) } + it { expect(planting.days_to_last_harvest).to eq(nil) } end describe 'planting has first harvest' do let(:planting) { FactoryBot.create :planting, planted_at: 100.days.ago } @@ -125,9 +125,9 @@ describe Planting do planting.crop.update_harvest_medians end it { expect(planting.days_to_first_harvest).to eq(90) } - it { expect(planting.last_harvest).to eq(nil) } + it { expect(planting.days_to_last_harvest).to eq(nil) } it { expect(planting.crop.median_days_to_first_harvest).to eq(90) } - it { expect(planting.crop.median_last_harvest).to eq(nil) } + it { expect(planting.crop.median_days_to_last_harvest).to eq(nil) } end describe 'planting has last harvest' do let(:planting) { FactoryBot.create :planting, planted_at: 100.days.ago, finished_at: 1.day.ago, finished: true } @@ -138,9 +138,9 @@ describe Planting do planting.crop.update_harvest_medians end it { expect(planting.days_to_first_harvest).to eq(10) } - it { expect(planting.last_harvest).to eq(90) } + it { expect(planting.days_to_last_harvest).to eq(90) } it { expect(planting.crop.median_days_to_first_harvest).to eq(10) } - it { expect(planting.crop.median_last_harvest).to eq(90) } + it { expect(planting.crop.median_days_to_last_harvest).to eq(90) } end end