From b3fd8e32d047aba1aec1f3c03320ca07506c3b8b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 5 Nov 2017 17:42:59 +1300 Subject: [PATCH] Fixed ordering of Harvests - don't order in scope. --- app/controllers/harvests_controller.rb | 5 +++-- spec/controllers/harvests_controller_spec.rb | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) 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