Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions spec/helpers/bulkrax/exporters_helper_spec.rb

This file was deleted.

31 changes: 30 additions & 1 deletion spec/helpers/bulkrax/importers_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions spec/jobs/bulkrax/import_collection_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/models/bulkrax/pending_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 35 additions & 1 deletion spec/models/bulkrax/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading