From efe14d43cbff1e619a3dce6a96dcd0d30fe63b50 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 12 Jul 2019 16:36:54 +1200 Subject: [PATCH] read photo from a harvest's planting --- app/models/harvest.rb | 4 ++++ spec/models/harvest_spec.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 2b24e2fa7..6dffbca6a 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -74,6 +74,10 @@ class Harvest < ApplicationRecord harvested_at - planting.planted_at end + def default_photo + most_liked_photo || planting&.default_photo + end + # we're storing the harvest weight in kilograms in the db too # to make data manipulation easier def set_si_weight diff --git a/spec/models/harvest_spec.rb b/spec/models/harvest_spec.rb index 35cb9ba5f..168b2bcdc 100644 --- a/spec/models/harvest_spec.rb +++ b/spec/models/harvest_spec.rb @@ -237,6 +237,7 @@ describe Harvest do @planting = FactoryBot.create(:planting, crop: @harvest.crop) @photo = FactoryBot.create(:photo, owner: @planting.owner) @planting.photos << @photo + @harvest.update(planting: @planting) end it 'has a default photo' do