diff --git a/app/controllers/harvests_controller.rb b/app/controllers/harvests_controller.rb index 4b7695854..9b148c3f5 100644 --- a/app/controllers/harvests_controller.rb +++ b/app/controllers/harvests_controller.rb @@ -34,6 +34,7 @@ class HarvestsController < ApplicationController def create @harvest.crop_id = @harvest.planting.crop_id if @harvest.planting_id + @harvest.harvested_at = Time.zone.now if @harvest.harvested_at.blank? @harvest.save respond_with(@harvest) end @@ -72,8 +73,8 @@ class HarvestsController < ApplicationController elsif @planting @planting.harvests else - Harvest - end.joins(:owner, :crop).paginate(page: params[:page]) + Harvest.all + end.order(harvested_at: :desc).joins(:owner, :crop).paginate(page: params[:page]) end def csv_filename diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index a42d11f69..ff4972a7a 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -19,7 +19,8 @@ describe HarvestsController do { owner_id: subject.current_member.id, crop_id: FactoryBot.create(:crop).id, - plant_part_id: FactoryBot.create(:plant_part).id + plant_part_id: FactoryBot.create(:plant_part).id, + harvested_at: '2017-01-01' } end