Skip to content

Commit

Permalink
Merge pull request #6552 from samvera/valkyrizes_statistics_file_sets…
Browse files Browse the repository at this point in the history
…_by_format_spec

Valkyrizes `spec/services/hyrax/statistics/file_sets/by_format_spec.rb`.
  • Loading branch information
dlpierce authored Jan 2, 2024
2 parents b9d4069 + c269208 commit f36c682
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions spec/services/hyrax/statistics/file_sets/by_format_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
# frozen_string_literal: true
RSpec.describe Hyrax::Statistics::FileSets::ByFormat, :clean_repo do
RSpec.describe Hyrax::Statistics::FileSets::ByFormat, :clean_repo, valkyrie_adapter: :test_adapter, index_adapter: :solr_index do
describe ".query" do
let(:fs1) { build(:file_set, id: '1234567') }
let(:fs2) { build(:file_set, id: '2345678') }
let(:fs3) { build(:file_set, id: '3456789') }
let(:fs4) { build(:file_set, id: '4567890') }

before do
allow(fs1).to receive_messages(mime_type: 'text/plain', format_label: ["plain text"])
fs1.update_index
allow(fs2).to receive_messages(mime_type: 'image/jpg', format_label: ["JPEG image"])
fs2.update_index
allow(fs3).to receive_messages(mime_type: 'image/tiff', format_label: ["TIFF image"])
fs3.update_index
allow(fs4).to receive_messages(mime_type: 'image/jpg', format_label: ["JPEG image"])
fs4.update_index
let(:file1) { Rack::Test::UploadedFile.new('spec/fixtures/small_file.txt', 'text/plain') }
let(:file2) { Rack::Test::UploadedFile.new('spec/fixtures/1.5mb-avatar.jpg', 'image/jpg') }
let(:file3) { Rack::Test::UploadedFile.new('spec/fixtures/world.png', 'image/png') }
let(:file4) { Rack::Test::UploadedFile.new('spec/fixtures/image.jpg', 'image/jpg') }
let(:orig_file1) do
Hyrax.persister.save(resource: Hyrax::FileMetadata.new(label: file1.original_filename,
original_filename: file1.original_filename,
mime_type: file1.content_type,
format_label: 'plain text'))
end
let(:orig_file2) do
Hyrax.persister.save(resource: Hyrax::FileMetadata.new(label: file2.original_filename,
original_filename: file2.original_filename,
mime_type: file2.content_type,
format_label: 'JPEG image'))
end
let(:orig_file3) do
Hyrax.persister.save(resource: Hyrax::FileMetadata.new(label: file3.original_filename,
original_filename: file3.original_filename,
mime_type: file3.content_type,
format_label: 'PNG image'))
end
let(:orig_file4) do
Hyrax.persister.save(resource: Hyrax::FileMetadata.new(label: file4.original_filename,
original_filename: file4.original_filename,
mime_type: file4.content_type,
format_label: 'JPEG image'))
end
let(:fs1) { valkyrie_create(:hyrax_file_set, file_ids: [orig_file1.id]) }
let(:fs2) { valkyrie_create(:hyrax_file_set, file_ids: [orig_file2.id]) }
let(:fs3) { valkyrie_create(:hyrax_file_set, file_ids: [orig_file3.id]) }
let(:fs4) { valkyrie_create(:hyrax_file_set, file_ids: [orig_file4.id]) }

before { [fs1, fs2, fs3, fs4] }
subject { described_class.query }

it "is a list of categories" do
expect(subject).to eq [{ label: 'jpg (JPEG image)', data: 2 },
{ label: 'plain (plain text)', data: 1 },
{ label: 'tiff (TIFF image)', data: 1 }]
{ label: 'png (PNG image)', data: 1 }]
expect(subject.first.label).to eq 'jpg (JPEG image)'
expect(subject.first.value).to eq 2
end
Expand Down

0 comments on commit f36c682

Please sign in to comment.