Commit 0630b159 authored by Siddharth Asthana's avatar Siddharth Asthana

Fix Rails/SaveBang offenses

Changelog: other
EE: true
parent 7976ea9c
......@@ -2,15 +2,6 @@
Rails/SaveBang:
Exclude:
- ee/spec/lib/analytics/merge_request_metrics_calculator_spec.rb
- ee/spec/models/protected_environment_spec.rb
- ee/spec/models/repository_spec.rb
- ee/spec/models/scim_identity_spec.rb
- ee/spec/models/scim_oauth_access_token_spec.rb
- ee/spec/models/upload_spec.rb
- ee/spec/models/user_preference_spec.rb
- ee/spec/models/visible_approvable_spec.rb
- ee/spec/models/vulnerabilities/feedback_spec.rb
- ee/spec/models/vulnerabilities/issue_link_spec.rb
- spec/lib/backup/manager_spec.rb
- spec/lib/gitlab/alerting/alert_spec.rb
- spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb
......
......@@ -332,6 +332,6 @@ RSpec.describe ProtectedEnvironment do
end
def create_deploy_access_level(protected_environment, **opts)
protected_environment.deploy_access_levels.create(**opts)
protected_environment.deploy_access_levels.create!(**opts)
end
end
......@@ -49,7 +49,7 @@ RSpec.describe ScimIdentity do
user = create(:user)
group = create(:group)
identity = user.scim_identities.create(group: group, extern_uid: user.email)
identity = user.scim_identities.create!(group: group, extern_uid: user.email)
expect(group.scim_identities.with_extern_uid(user.email.upcase).first).to eq identity
end
......
......@@ -25,7 +25,7 @@ RSpec.describe ScimOauthAccessToken do
describe '#token' do
it 'generates a token on creation' do
scim_token = described_class.create(group: create(:group))
scim_token = described_class.create!(group: create(:group))
expect(scim_token.token).to be_a(String)
end
......
......@@ -46,7 +46,7 @@ RSpec.describe Upload do
with_them do
subject(:upload_included) { described_class.replicables_for_current_secondary(upload).exists? }
let(:model) { create(*model_factory) }
let(:model) { create(*model_factory) } # rubocop:disable Rails/SaveBang
let(:node) do
create(:geo_node_with_selective_sync_for,
model: model,
......@@ -103,7 +103,7 @@ RSpec.describe Upload do
it 'logs an event to the Geo event log when bulk removal is used', :sidekiq_inline do
stub_current_geo_node(primary)
expect { subject.model.destroy }.to change(Geo::Event.where(replicable_name: :upload, event_name: :deleted), :count).by(1)
expect { subject.model.destroy! }.to change(Geo::Event.where(replicable_name: :upload, event_name: :deleted), :count).by(1)
payload = Geo::Event.where(replicable_name: :upload, event_name: :deleted).last.payload
......
......@@ -7,7 +7,7 @@ RSpec.describe UserPreference do
shared_examples 'updates roadmap_epics_state' do |state|
it 'saves roadmap_epics_state in user_preference' do
user_preference.update(roadmap_epics_state: state)
user_preference.update!(roadmap_epics_state: state)
expect(user_preference.reload.roadmap_epics_state).to eq(state)
end
......
......@@ -45,13 +45,13 @@ RSpec.describe VisibleApprovable do
let!(:approver) { resource.author }
it 'excludes author if author cannot approve' do
project.update(merge_requests_author_approval: false)
project.update!(merge_requests_author_approval: false)
is_expected.not_to include(approver)
end
it 'includes author if author is able to approve' do
project.update(merge_requests_author_approval: true)
project.update!(merge_requests_author_approval: true)
is_expected.to include(approver)
end
......@@ -61,13 +61,13 @@ RSpec.describe VisibleApprovable do
let!(:approver) { create(:user, email: resource.commits.without_merge_commits.first.committer_email) }
it 'excludes the committer if committers cannot approve' do
project.update(merge_requests_disable_committers_approval: true)
project.update!(merge_requests_disable_committers_approval: true)
is_expected.not_to include(approver)
end
it 'includes the committer if committers are able to approve' do
project.update(merge_requests_disable_committers_approval: false)
project.update!(merge_requests_disable_committers_approval: false)
is_expected.to include(approver)
end
......@@ -82,7 +82,7 @@ RSpec.describe VisibleApprovable do
end
it 'returns true when merge_requests_author_approval flag is turned on' do
project.update(merge_requests_author_approval: true)
project.update!(merge_requests_author_approval: true)
is_expected.to be_truthy
end
......
......@@ -97,7 +97,7 @@ RSpec.describe Vulnerabilities::Feedback do
context 'when pipeline is assigned to feedback' do
before do
feedback.update(pipeline: pipeline)
feedback.update!(pipeline: pipeline)
end
context 'when pipeline was updated less than 5 minutes ago' do
......
......@@ -55,7 +55,7 @@ RSpec.describe Vulnerabilities::IssueLink do
:vulnerabilities_issue_link,
issue_id: existing_link.issue_id,
vulnerability_id: existing_link.vulnerability_id)
issue_link.save(validate: false)
issue_link.save!(validate: false)
end.to raise_error(ActiveRecord::RecordNotUnique)
end
end
......@@ -66,14 +66,14 @@ RSpec.describe Vulnerabilities::IssueLink do
it 'prevents the creation of a new "created" issue link' do
expect do
issue_link = build(:vulnerabilities_issue_link, :created, vulnerability: existing_link.vulnerability)
issue_link.save(validate: false)
issue_link.save!(validate: false)
end.to raise_error(ActiveRecord::RecordNotUnique)
end
it 'allows the creation of a new "related" issue link' do
expect do
issue_link = build(:vulnerabilities_issue_link, :related, vulnerability: existing_link.vulnerability)
issue_link.save(validate: false)
issue_link.save!(validate: false)
end.not_to raise_error
end
end
......
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