mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-05 23:21:07 -05:00
Tests for crop.photos
This commit is contained in:
@@ -139,57 +139,61 @@ describe Crop do
|
||||
end
|
||||
|
||||
context 'photos' do
|
||||
before :each do
|
||||
@crop = FactoryBot.create(:tomato)
|
||||
shared_examples 'has default photo' do
|
||||
it { expect(Crop.has_photos).to include(crop) }
|
||||
end
|
||||
let!(:crop) { FactoryBot.create :tomato }
|
||||
let(:member) { FactoryBot.create :member }
|
||||
|
||||
context 'with a planting photo' do
|
||||
before :each do
|
||||
@planting = FactoryBot.create(:planting, crop: @crop)
|
||||
@photo = FactoryBot.create(:photo, owner: @planting.owner)
|
||||
@planting.photos << @photo
|
||||
end
|
||||
let!(:photo) { FactoryBot.create(:photo, owner: planting.owner) }
|
||||
let!(:planting) { FactoryBot.create(:planting, crop: crop) }
|
||||
|
||||
it 'has a default photo' do
|
||||
@crop.default_photo.should be_an_instance_of Photo
|
||||
expect(@crop.default_photo.id).to eq @photo.id
|
||||
end
|
||||
|
||||
it 'is found in has_photos scope' do
|
||||
Crop.has_photos.should include(@crop)
|
||||
end
|
||||
before { planting.photos << photo }
|
||||
it { expect(crop.default_photo).to eq photo }
|
||||
include_examples 'has default photo'
|
||||
end
|
||||
|
||||
context 'with a harvest photo' do
|
||||
before :each do
|
||||
@harvest = FactoryBot.create(:harvest, crop: @crop)
|
||||
@photo = FactoryBot.create(:photo, owner: @harvest.owner)
|
||||
@harvest.photos << @photo
|
||||
end
|
||||
|
||||
it 'has a default photo' do
|
||||
@crop.default_photo.should be_an_instance_of Photo
|
||||
expect(@crop.default_photo.id).to eq @photo.id
|
||||
end
|
||||
let!(:harvest) { FactoryBot.create(:harvest, crop: crop) }
|
||||
let!(:photo) { FactoryBot.create(:photo, owner: harvest.owner) }
|
||||
before { harvest.photos << photo }
|
||||
it { expect(crop.default_photo).to eq photo }
|
||||
include_examples 'has default photo'
|
||||
|
||||
context 'and planting photo' do
|
||||
before :each do
|
||||
@planting = FactoryBot.create(:planting, crop: @crop)
|
||||
@planting_photo = FactoryBot.create(:photo, owner: @planting.owner)
|
||||
@planting.photos << @planting_photo
|
||||
end
|
||||
let(:planting) { FactoryBot.create(:planting, crop: crop) }
|
||||
let!(:planting_photo) { FactoryBot.create(:photo, owner: planting.owner) }
|
||||
before { planting.photos << planting_photo }
|
||||
|
||||
it 'should prefer the planting photo' do
|
||||
expect(@crop.default_photo.id).to eq @planting_photo.id
|
||||
expect(crop.default_photo.id).to eq planting_photo.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with no plantings or harvests' do
|
||||
it 'has no default photo' do
|
||||
expect(@crop.default_photo).to eq nil
|
||||
expect(crop.default_photo).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'finding all photos' do
|
||||
let(:planting) { FactoryBot.create :planting, crop: crop }
|
||||
let(:harvest) { FactoryBot.create :harvest, crop: crop }
|
||||
let(:seed) { FactoryBot.create :seed, crop: crop }
|
||||
before do
|
||||
# Add photos to all
|
||||
planting.photos << FactoryBot.create(:photo, owner: planting.owner)
|
||||
harvest.photos << FactoryBot.create(:photo, owner: harvest.owner)
|
||||
seed.photos << FactoryBot.create(:photo, owner: seed.owner)
|
||||
end
|
||||
|
||||
it { expect(crop.photos.size).to eq 3 }
|
||||
it { expect(crop.planting_photos.size).to eq 1 }
|
||||
it { expect(crop.harvest_photos.size).to eq 1 }
|
||||
it { expect(crop.seed_photos.size).to eq 1 }
|
||||
end
|
||||
end
|
||||
|
||||
context 'sunniness' do
|
||||
|
||||
Reference in New Issue
Block a user