Skip to content

Commit

Permalink
Fix test broken by rubocop --autocorrect in 8fa8584
Browse files Browse the repository at this point in the history
  • Loading branch information
cbliard committed Jan 5, 2024
1 parent 8fa8584 commit 5055854
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def process(_hook, request, params, user)
'github_event' => event_type,
'github_delivery' => event_delivery)

OpenProject::Notifications.send(:"github.#{event_type}", payload)
event_name = "github.#{event_type}"
OpenProject::Notifications.send(event_name, payload)

200
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
factory :storage_file_info, class: '::Storages::StorageFileInfo' do
status { "OK" }
status_code { 200 }
sequence(:id) { |n| "20000#{n}" } # rubocop:disable FactoryBot/IdSequence
sequence(:name) { |n| "file_name_#{n}.txt" }
last_modified_at { Time.zone.now }
created_at { Time.zone.now }
Expand Down
2 changes: 1 addition & 1 deletion spec/features/projects/work_package_type_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

require 'spec_helper'

RSpec.describe 'Projects', :js, :with_cuprite, 'work package type mgmt' do
RSpec.describe 'Projects', 'work package type mgmt', :js, :with_cuprite do # rubocop:disable RSpec/SortMetadata
current_user { create(:user, member_with_permissions: { project => %i[edit_project manage_types] }) }

let(:phase_type) { create(:type, name: 'Phase', is_default: true) }
Expand Down
44 changes: 24 additions & 20 deletions spec/lib/open_project/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,34 @@
require 'spec_helper'

RSpec.describe OpenProject::Notifications do
let(:probe) { lambda { |*_args| } }
let(:payload) { { 'test' => 'payload' } }

describe '.send' do
let(:probe) { lambda { |*_args| } }
let(:payload) { { 'test' => 'payload' } }

before do
# We can't clean this up, so we need to use a unique name
OpenProject::Notifications.subscribe('notifications_spec_send', &probe)

expect(probe).to receive(:call) do |payload|
# Don't check for object identity for the payload as it might be
# marshalled and unmarshalled before being delivered in the future.
expect(payload).to eql(payload)
described_class.subscribe('notifications_spec_send') do |*args, **kwargs|
probe.call(*args, **kwargs)
end

allow(probe).to receive(:call)
end

it 'delivers a notification' do
OpenProject::Notifications.send(:notifications_spec_send, payload)
described_class.send(:notifications_spec_send, payload)

expect(probe).to have_received(:call) do |call_payload|
# Don't check for object identity for the payload as it might be
# marshalled and unmarshalled before being delivered in the future.
expect(call_payload).to eql(payload)
end
end
end

describe '.subscribe' do
it 'throws an error when no callback is given' do
expect do
OpenProject::Notifications.subscribe('notifications_spec_send')
described_class.subscribe('notifications_spec_send')
end.to raise_error ArgumentError, /provide a block as a callback/
end

Expand All @@ -61,21 +65,21 @@
let(:as) { [] }
let(:bs) { [] }

def example_with(clear:)
OpenProject::Notifications.subscribe(key) do |out|
def example_with(clear_subscriptions:)
described_class.subscribe(key) do |out|
as << out
end
OpenProject::Notifications.send(key, 1)
described_class.send(key, 1)

OpenProject::Notifications.subscribe(key, clear_subscriptions: clear) do |out|
described_class.subscribe(key, clear_subscriptions:) do |out|
bs << out
end
OpenProject::Notifications.send(key, 2)
described_class.send(key, 2)
end

context 'true' do
context 'when true' do
before do
example_with clear: true
example_with clear_subscriptions: true
end

it 'clears previous subscriptions' do
Expand All @@ -84,9 +88,9 @@ def example_with(clear:)
end
end

context 'false' do
context 'when false' do
before do
example_with clear: false
example_with clear_subscriptions: false
end

it 'notifies both subscriptions' do
Expand Down

0 comments on commit 5055854

Please sign in to comment.