Commit 6e7978db authored by Igor Drozdov's avatar Igor Drozdov

Fix Ruby 2.7 deprecation warnings for Members::DestroyService

In Ruby 3.0, positional arguments and keyword arguments will be
separated. Ruby 2.7 will warn for behaviors that will change in Ruby
3.0. In most cases, you can avoid the incompatibility by adding the
double splat operator. It explicitly specifies passing keyword arguments
instead of a Hash object.
parent b928a9bd
......@@ -5,7 +5,7 @@ class NotificationRecipient
attr_reader :user, :type, :reason
def initialize(user, type, **opts)
def initialize(user, type, opts = {})
unless NotificationSetting.levels.key?(type) || type == :subscription
raise ArgumentError, "invalid type: #{type.inspect}"
end
......
......@@ -21,7 +21,7 @@ class UserInteractedProject < ApplicationRecord
user_id: event.author_id
}
cached_exists?(attributes) do
cached_exists?(**attributes) do
transaction(requires_new: true) do
where(attributes).select(1).first || create!(attributes)
true # not caching the whole record here for now
......
......@@ -31,7 +31,7 @@ RSpec.describe Members::DestroyService do
end
it 'cleans up linked SAML identity' do
expect { subject.execute(member, {}) }.to change { member_user.reload.identities.count }.by(-1)
expect { subject.execute(member) }.to change { member_user.reload.identities.count }.by(-1)
end
end
......@@ -39,14 +39,14 @@ RSpec.describe Members::DestroyService do
it 'does not attempt to destroy unrelated identities' do
create(:identity, user: member_user)
expect { subject.execute(member, {}) }.not_to change(Identity, :count)
expect { subject.execute(member) }.not_to change(Identity, :count)
end
end
end
context 'audit events' do
it_behaves_like 'logs an audit event' do
let(:event) { subject.execute(member, {}) }
let(:event) { subject.execute(member) }
end
it 'does not log the audit event as a system event' do
......
......@@ -29,15 +29,15 @@ RSpec.describe Members::DestroyService do
end
it 'destroys the member' do
expect { described_class.new(current_user).execute(member, opts) }.to change { member.source.members_and_requesters.count }.by(-1)
expect { described_class.new(current_user).execute(member, **opts) }.to change { member.source.members_and_requesters.count }.by(-1)
end
it 'destroys member notification_settings' do
if member_user.notification_settings.any?
expect { described_class.new(current_user).execute(member, opts) }
expect { described_class.new(current_user).execute(member, **opts) }
.to change { member_user.notification_settings.count }.by(-1)
else
expect { described_class.new(current_user).execute(member, opts) }
expect { described_class.new(current_user).execute(member, **opts) }
.not_to change { member_user.notification_settings.count }
end
end
......@@ -63,7 +63,7 @@ RSpec.describe Members::DestroyService do
expect(service).to receive(:enqueue_unassign_issuables).with(member)
end
service.execute(member, opts)
service.execute(member, **opts)
expect(member_user.assigned_open_merge_requests_count).to be(0)
expect(member_user.assigned_open_issues_count).to be(0)
......@@ -83,14 +83,14 @@ RSpec.describe Members::DestroyService do
it 'calls Member#after_decline_request' do
expect_any_instance_of(NotificationService).to receive(:decline_access_request).with(member)
described_class.new(current_user).execute(member, opts)
described_class.new(current_user).execute(member, **opts)
end
context 'when current user is the member' do
it 'does not call Member#after_decline_request' do
expect_any_instance_of(NotificationService).not_to receive(:decline_access_request).with(member)
described_class.new(member_user).execute(member, opts)
described_class.new(member_user).execute(member, **opts)
end
end
end
......@@ -280,7 +280,6 @@ RSpec.describe Members::DestroyService do
context 'subresources' do
let(:user) { create(:user) }
let(:member_user) { create(:user) }
let(:opts) { {} }
let(:group) { create(:group, :public) }
let(:subgroup) { create(:group, parent: group) }
......@@ -303,7 +302,7 @@ RSpec.describe Members::DestroyService do
group_member = create(:group_member, :developer, group: group, user: member_user)
described_class.new(user).execute(group_member, opts)
described_class.new(user).execute(group_member)
end
it 'removes the project membership' do
......@@ -350,7 +349,6 @@ RSpec.describe Members::DestroyService do
context 'deletion of invitations created by deleted project member' do
let(:user) { project.owner }
let(:member_user) { create(:user) }
let(:opts) { {} }
let(:project) { create(:project) }
......@@ -359,7 +357,7 @@ RSpec.describe Members::DestroyService do
project_member = create(:project_member, :maintainer, user: member_user, project: project)
described_class.new(user).execute(project_member, opts)
described_class.new(user).execute(project_member)
end
it 'removes project members invited by deleted user' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment