From b7e53daebaf7a936b8aaa9ea6c394298afa486ec Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 5 Jan 2020 16:57:14 +1300 Subject: [PATCH] fixes to crop photos --- app/models/concerns/photo_capable.rb | 6 +++++- app/views/crops/_photos.html.haml | 2 +- spec/features/crops/crop_photos_spec.rb | 12 +++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/photo_capable.rb b/app/models/concerns/photo_capable.rb index 3144ec283..c1433a7fc 100644 --- a/app/models/concerns/photo_capable.rb +++ b/app/models/concerns/photo_capable.rb @@ -16,7 +16,11 @@ module PhotoCapable end def thumbnail_url - default_photo ? default_photo.thumbnail_url : nil + df = default_photo + + return unless df + + df.source == 'flickr' ? df.fullsize_url : df.thumbnail_url end def most_liked_photo diff --git a/app/views/crops/_photos.html.haml b/app/views/crops/_photos.html.haml index 207974b0a..42ee6eef7 100644 --- a/app/views/crops/_photos.html.haml +++ b/app/views/crops/_photos.html.haml @@ -1,4 +1,4 @@ -- if crop.photo_associations_count.positive? +- if crop.photos.count.positive? %h2 #{photo_icon} Photos - [Crop, Planting, Harvest, Seed].each do |model_name| - if crop.photos.by_model(model_name).size.positive? diff --git a/spec/features/crops/crop_photos_spec.rb b/spec/features/crops/crop_photos_spec.rb index 1fc44772a..edeac6fcd 100644 --- a/spec/features/crops/crop_photos_spec.rb +++ b/spec/features/crops/crop_photos_spec.rb @@ -2,15 +2,17 @@ require 'rails_helper' -describe "crop detail page", js: true do +describe "crop detail page", :js, :search do subject { page } let!(:owner_member) { FactoryBot.create :member } - let!(:crop) { FactoryBot.create :crop } + let!(:crop) { FactoryBot.create :crop, :reindex } + let(:plant_part) { FactoryBot.create :plant_part, name: 'fruit' } + + let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: owner_member, plant_part: plant_part } let!(:planting) { FactoryBot.create :planting, crop: crop, owner: owner_member } - let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: owner_member } let!(:seed) { FactoryBot.create :seed, crop: crop, owner: owner_member } let!(:photo1) { FactoryBot.create(:photo, owner: owner_member) } @@ -27,7 +29,11 @@ describe "crop detail page", js: true do harvest.photos << photo4 seed.photos << photo5 seed.photos << photo6 + Crop.reindex visit crop_path(crop) + expect(crop.photos.count).to eq 6 + expect(crop.photos.by_model(Planting).count).to eq 2 + expect(page).to have_content 'Photos' end shared_examples "shows photos" do