Fixed ordering of Harvests - don't order in scope.

This commit is contained in:
Brenda Wallace
2017-11-05 17:42:59 +13:00
parent 9b1b22afa8
commit b3fd8e32d0
2 changed files with 5 additions and 3 deletions

View File

@@ -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

View File

@@ -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