Skip to content

Commit

Permalink
LP-1169 - Add upload image association max of 30
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrlc committed Dec 18, 2024
1 parent 3f28b5d commit b3bc7a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/prepends/prepended_models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module PrependedModels::Upload

Spotlight::Resources::Upload.accepts_nested_attributes_for :uploads

Spotlight::Resources::Upload.validates :uploads, length: { maximum: 30 }

# Overrides to_solr method to handle multiple uploads
# rubocop:disable Metrics/AbcSize
def to_solr
Expand Down
20 changes: 20 additions & 0 deletions spec/prepends/prepended_models/upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

# Tests overrides in PrependedModels::Upload
describe Spotlight::Resources::Upload, type: :model do
describe 'validations' do
let(:exhibit) { create(:exhibit) }
let(:upload_resource) { Spotlight::Resources::Upload.new(exhibit: exhibit) }
let(:file) { Rack::Test::UploadedFile.new(File.expand_path('../../fixtures/grey.png', __dir__)) }

it 'is invalid when more than 30 upload files are associated' do
uploads_attributes = Array.new(31, { image: file })
upload_resource.uploads.build(uploads_attributes)
expect(upload_resource).to be_invalid
expect(upload_resource.errors[:uploads]).to include('You are not allowed to upload more than 30 files for a single exhibit item.')
end

it 'is valid when 30 upload files are associated' do
uploads_attributes = Array.new(30, { image: file })
upload_resource.uploads.build(uploads_attributes)
expect(upload_resource).to be_valid
expect(upload_resource.errors).to be_empty
end
end

describe '#to_solr' do
let(:upload_resource) { create(:upload_with_multiple_images) }

Expand Down

0 comments on commit b3bc7a2

Please sign in to comment.