Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/models/concerns/photo_capable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ def default_photo
def thumbnail_url
df = default_photo

return unless df

df.source == 'flickr' ? df.fullsize_url : df.thumbnail_url
if df
df.source == 'flickr' ? df.fullsize_url : df.thumbnail_url
elsif respond_to?(:crop) && crop.present?
crop.thumbnail_url
end
end

def most_liked_photo
Expand Down
1 change: 1 addition & 0 deletions app/models/photo_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def set_crop

def photo_and_item_have_same_owner
return if photographable_type == 'Crop'
return if photographable.blank?

errors.add(:photo, :photo_owner_mismatch) unless photographable.owner_id == photo.owner_id
end
Expand Down
19 changes: 19 additions & 0 deletions spec/models/planting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,25 @@ def one_hundred_day_old_planting
planting.photos << @photo2
expect(planting.default_photo).to eq @photo2
end

describe '#thumbnail_url' do
let(:crop_photo) { create(:photo) }

it 'returns its own default photo if present' do
expect(planting.thumbnail_url).to eq photo.fullsize_url
end

it 'falls back to crop default photo if no planting photo is present' do
planting_without_photo = create(:planting, crop:)
PhotoAssociation.create!(photo: crop_photo, photographable: crop)
expect(planting_without_photo.thumbnail_url).to eq crop_photo.fullsize_url
end

it 'returns nil if neither planting nor crop has a photo' do
planting_without_photo = create(:planting, crop:)
expect(planting_without_photo.thumbnail_url).to be_nil
end
end
end

context 'interesting plantings' do
Expand Down
Loading