Files
growstuff/spec/models/photo_association_spec.rb
T
Brenda WallaceandClaude Sonnet 5.5 ab024ac51a Address review comments on packet photo labels
Keep every packet label when a side is photographed again, and use the newest
photo of a side. Before, giving a second photo the same label cleared the
older photo's, which let it back into the crop's photos and default picture.

Carry the label through the HTML photo picker (its search form and the links
that add a photo), so a packet photo added without JavaScript is labelled.

Have the OCR script treat any network failure on an image (DNS, timeout) as
that image failing, so the rest of the batch still runs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 21:20:27 +13:00

96 lines
2.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe PhotoAssociation do
subject(:association) { job.photo_associations.build(photo:) }
let(:job) { create(:job) }
let(:photo) { create(:photo, owner: job.owner) }
it { is_expected.to be_valid }
it 'has no label, unless it is given one' do
expect(association.label).to be_nil
end
describe 'label' do
subject(:association) { item.photo_associations.build(photo: create(:photo, owner: item.owner), label:) }
context 'with before, on a job' do
let(:item) { job }
let(:label) { 'before' }
it { is_expected.to be_valid }
end
context 'with after, on a job' do
let(:item) { job }
let(:label) { 'after' }
it { is_expected.to be_valid }
end
context 'with front, on a job' do
let(:item) { job }
let(:label) { 'front' }
it { is_expected.not_to be_valid }
end
context 'with front, on a seed' do
let(:item) { create(:seed) }
let(:label) { 'front' }
it { is_expected.to be_valid }
end
context 'with back, on a seed' do
let(:item) { create(:seed) }
let(:label) { 'back' }
it { is_expected.to be_valid }
end
context 'with before, on a seed' do
let(:item) { create(:seed) }
let(:label) { 'before' }
it { is_expected.not_to be_valid }
end
context 'with an empty string' do
let(:item) { job }
let(:label) { '' }
it('is none') { expect(association.label).to be_nil }
end
context 'with any label, on a harvest' do
let(:item) { create(:harvest) }
let(:label) { 'front' }
it { is_expected.not_to be_valid }
end
end
describe 'a seed packet label' do
let(:seed) { create(:seed) }
let!(:earlier) { seed.photo_associations.create!(photo: create(:photo, owner: seed.owner), label: 'front') }
let(:later) { seed.photo_associations.create!(photo: create(:photo, owner: seed.owner), label: 'front') }
it('is kept by the earlier photo when the side is photographed again') do
later
expect(earlier.reload.label).to eq 'front'
end
it('is on the later photo too') { expect(later.reload.label).to eq 'front' }
end
context 'when the photo is someone else\'s' do
let(:photo) { create(:photo) }
it { is_expected.not_to be_valid }
end
end