Skip to content

Commit

Permalink
Update object_created_spec to use RepositoryObjects.
Browse files Browse the repository at this point in the history
refs #5014
  • Loading branch information
justinlittman committed May 20, 2024
1 parent 27e4d5d commit 5dd3710
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/repository_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VersionNotOpened < StandardError; end
scope :collections, -> { where(object_type: 'collection') }
scope :admin_policies, -> { where(object_type: 'admin_policy') }

delegate :to_cocina, to: :head_version
delegate :to_cocina, :to_cocina_with_metadata, to: :head_version

# NOTE: This block uses metaprogramming to create the equivalent of scopes that query the RepositoryObjectVersion table using only rows that are a `current` in the RepositoryObject table
#
Expand Down
14 changes: 9 additions & 5 deletions spec/services/notifications/object_created_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@
let(:channel) { instance_double(Notifications::RabbitChannel, topic:) }
let(:topic) { instance_double(Bunny::Exchange, publish: true) }

let(:model) do
create(:repository_object, :with_repository_object_version, object_type) do |repo_obj|
repo_obj.head_version.update(created_at:, updated_at:)
end
end

let(:object_type) { :dro }

context 'when RabbitMQ is enabled' do
before do
allow(Notifications::RabbitChannel).to receive(:instance).and_return(channel)
allow(Settings.rabbitmq).to receive(:enabled).and_return(true)
end

context 'when called with a DRO' do
let(:model) { build(:ar_dro, created_at:, updated_at:) }

before do
allow(AdministrativeTags).to receive(:project).and_return(['h2'])
end
Expand All @@ -34,7 +40,7 @@
end

context 'when called with an AdminPolicy' do
let(:model) { build(:ar_admin_policy, created_at:, updated_at:) }
let(:object_type) { :admin_policy }

it 'is successful' do
publish
Expand All @@ -49,8 +55,6 @@
end

context 'when called with a DRO' do
let(:model) { build(:ar_dro, created_at:, updated_at:) }

it 'does not receive a message' do
publish
expect(topic).not_to have_received(:publish)
Expand Down

0 comments on commit 5dd3710

Please sign in to comment.