fixes to crop photos

This commit is contained in:
Brenda Wallace
2020-01-05 16:57:14 +13:00
parent ebb8460e44
commit b7e53daeba
3 changed files with 15 additions and 5 deletions

View File

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

View File

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

View File

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