diff --git a/spec/helpers/bulkrax/exporters_helper_spec.rb b/spec/helpers/bulkrax/exporters_helper_spec.rb deleted file mode 100644 index 53180a18d..000000000 --- a/spec/helpers/bulkrax/exporters_helper_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the ExportersHelper. For example: -# -# describe ExportersHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -module Bulkrax - RSpec.describe ExportersHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" - end -end diff --git a/spec/helpers/bulkrax/importers_helper_spec.rb b/spec/helpers/bulkrax/importers_helper_spec.rb index 61b504eb5..7d444573e 100644 --- a/spec/helpers/bulkrax/importers_helper_spec.rb +++ b/spec/helpers/bulkrax/importers_helper_spec.rb @@ -14,6 +14,35 @@ # end module Bulkrax RSpec.describe ImportersHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" + describe '#available_admin_sets' do + let(:admin_set_id) { 'admin_set_1' } + let(:admin_set) { instance_double('AdminSet', title: ['My Admin Set']) } + + before do + allow(helper).to receive(:current_ability).and_return(instance_double('Ability')) + allow(Hyrax::Collections::PermissionsService).to receive(:source_ids_for_deposit) + .with(ability: helper.current_ability, source_type: 'admin_set') + .and_return([admin_set_id]) + allow(Bulkrax.object_factory).to receive(:find_or_nil).with(admin_set_id).and_return(admin_set) + end + + it 'returns an array of [title, id] pairs for admin sets the user can deposit to' do + expect(helper.available_admin_sets).to eq([['My Admin Set', admin_set_id]]) + end + + it 'memoizes the result' do + helper.available_admin_sets + helper.available_admin_sets + expect(Hyrax::Collections::PermissionsService).to have_received(:source_ids_for_deposit).once + end + + context 'when admin set has no title' do + let(:admin_set) { nil } + + it 'falls back to the id' do + expect(helper.available_admin_sets).to eq([[admin_set_id, admin_set_id]]) + end + end + end end end diff --git a/spec/jobs/bulkrax/import_collection_job_spec.rb b/spec/jobs/bulkrax/import_collection_job_spec.rb index a37f45519..53b3e0ef0 100644 --- a/spec/jobs/bulkrax/import_collection_job_spec.rb +++ b/spec/jobs/bulkrax/import_collection_job_spec.rb @@ -34,7 +34,10 @@ module Bulkrax expect { perform }.not_to change { entry.importerexporter.current_run.reload.enqueued_records } end - it 'decrements the number of enqueued records' + it 'decrements the number of enqueued records' do + entry.importerexporter.current_run.update!(enqueued_records: 1) + expect { perform }.to change { entry.importerexporter.current_run.reload.enqueued_records }.by(-1) + end end context 'a run with an error' do before do @@ -58,7 +61,11 @@ module Bulkrax expect { perform }.to raise_error(StandardError) expect(ImporterRun).not_to have_received(:decrement_counter).with(:enqueued_records, current_run_id) end - it 'decrements the number of enqueued records' + it 'decrements the number of enqueued records' do + entry.importerexporter.current_run.update!(enqueued_records: 1) + expect { perform }.to raise_error(StandardError) + expect(entry.importerexporter.current_run.reload.enqueued_records).to eq(0) + end end end end diff --git a/spec/models/bulkrax/pending_relationship_spec.rb b/spec/models/bulkrax/pending_relationship_spec.rb index 70d1a4ce2..f8e78f24f 100644 --- a/spec/models/bulkrax/pending_relationship_spec.rb +++ b/spec/models/bulkrax/pending_relationship_spec.rb @@ -4,6 +4,23 @@ module Bulkrax RSpec.describe PendingRelationship, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + subject(:pending_relationship) { FactoryBot.create(:pending_relationship) } + + it 'is valid with valid attributes' do + expect(pending_relationship).to be_valid + end + + it 'belongs to an importer run' do + expect(pending_relationship.importer_run).to be_a(Bulkrax::ImporterRun) + end + + describe '.ordered' do + it 'returns records ordered by the order column' do + run = FactoryBot.create(:bulkrax_importer_run) + r2 = FactoryBot.create(:pending_relationship, importer_run: run, order: 2) + r1 = FactoryBot.create(:pending_relationship, importer_run: run, order: 1) + expect(described_class.where(importer_run: run).ordered).to eq([r1, r2]) + end + end end end diff --git a/spec/models/bulkrax/status_spec.rb b/spec/models/bulkrax/status_spec.rb index f4dff9655..91087d3dd 100644 --- a/spec/models/bulkrax/status_spec.rb +++ b/spec/models/bulkrax/status_spec.rb @@ -4,6 +4,40 @@ module Bulkrax RSpec.describe Status, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + subject(:status) { FactoryBot.create(:bulkrax_status) } + + it 'is valid with valid attributes' do + expect(status).to be_valid + end + + describe '#latest?' do + it 'returns true for the most recent status for its statusable' do + expect(status.latest?).to be true + end + + it 'returns false for an earlier status' do + earlier = FactoryBot.create(:bulkrax_status, statusable: status.statusable, runnable: status.runnable) + expect(status.reload.latest?).to be false + expect(earlier.latest?).to be true + end + end + + describe '.for_importers' do + it 'returns statuses whose statusable_type is Bulkrax::Importer' do + importer = FactoryBot.create(:bulkrax_importer) + importer_status = FactoryBot.create(:bulkrax_status, statusable: importer) + expect(described_class.for_importers).to include(importer_status) + expect(described_class.for_importers).not_to include(status) + end + end + + describe '.for_exporters' do + it 'returns statuses whose statusable_type is Bulkrax::Exporter' do + exporter = FactoryBot.create(:bulkrax_exporter) + exporter_status = FactoryBot.create(:bulkrax_status, statusable: exporter) + expect(described_class.for_exporters).to include(exporter_status) + expect(described_class.for_exporters).not_to include(status) + end + end end end