Commit 39b3998d authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Fix Rails/SaveBang RuboCop offenses for all factories

parent 2bbc4d78
...@@ -855,10 +855,6 @@ Rails/SaveBang: ...@@ -855,10 +855,6 @@ Rails/SaveBang:
Exclude: Exclude:
- 'ee/spec/controllers/projects/merge_requests_controller_spec.rb' - 'ee/spec/controllers/projects/merge_requests_controller_spec.rb'
- 'ee/spec/controllers/subscriptions_controller_spec.rb' - 'ee/spec/controllers/subscriptions_controller_spec.rb'
- 'ee/spec/factories/ci/job_artifacts.rb'
- 'ee/spec/factories/epics.rb'
- 'ee/spec/factories/licenses.rb'
- 'ee/spec/factories/merge_requests.rb'
- 'ee/spec/features/admin/admin_users_spec.rb' - 'ee/spec/features/admin/admin_users_spec.rb'
- 'ee/spec/features/admin/geo/admin_geo_nodes_spec.rb' - 'ee/spec/features/admin/geo/admin_geo_nodes_spec.rb'
- 'ee/spec/features/admin/licenses/admin_views_license_spec.rb' - 'ee/spec/features/admin/licenses/admin_views_license_spec.rb'
...@@ -1100,19 +1096,6 @@ Rails/SaveBang: ...@@ -1100,19 +1096,6 @@ Rails/SaveBang:
- 'spec/controllers/sent_notifications_controller_spec.rb' - 'spec/controllers/sent_notifications_controller_spec.rb'
- 'spec/controllers/sessions_controller_spec.rb' - 'spec/controllers/sessions_controller_spec.rb'
- 'spec/controllers/users_controller_spec.rb' - 'spec/controllers/users_controller_spec.rb'
- 'spec/factories/alert_management/alerts.rb'
- 'spec/factories/boards.rb'
- 'spec/factories/ci/pipelines.rb'
- 'spec/factories/design_management/designs.rb'
- 'spec/factories/design_management/versions.rb'
- 'spec/factories/emails.rb'
- 'spec/factories/issues.rb'
- 'spec/factories/labels.rb'
- 'spec/factories/merge_requests.rb'
- 'spec/factories/plans.rb'
- 'spec/factories/projects.rb'
- 'spec/factories/services.rb'
- 'spec/factories/wiki_pages.rb'
- 'spec/factories_spec.rb' - 'spec/factories_spec.rb'
- 'spec/features/admin/admin_appearance_spec.rb' - 'spec/features/admin/admin_appearance_spec.rb'
- 'spec/features/admin/admin_labels_spec.rb' - 'spec/features/admin/admin_labels_spec.rb'
......
---
title: Refactor all factories to fix SaveBang Cop
merge_request: 37268
author: Rajendra Kadam
type: fixed
...@@ -180,7 +180,7 @@ FactoryBot.define do ...@@ -180,7 +180,7 @@ FactoryBot.define do
end end
trait :license_management do trait :license_management do
to_create { |instance| instance.save(validate: false) } to_create { |instance| instance.save!(validate: false) }
file_type { :license_management } file_type { :license_management }
file_format { :raw } file_format { :raw }
......
...@@ -34,7 +34,7 @@ FactoryBot.define do ...@@ -34,7 +34,7 @@ FactoryBot.define do
end end
after(:create) do |epic, evaluator| after(:create) do |epic, evaluator|
epic.update(labels: evaluator.labels) epic.update!(labels: evaluator.labels)
end end
end end
end end
......
...@@ -57,6 +57,6 @@ FactoryBot.define do ...@@ -57,6 +57,6 @@ FactoryBot.define do
end end
# Disable validations when creating an expired license key # Disable validations when creating an expired license key
to_create {|instance| instance.save(validate: !expired) } to_create {|instance| instance.save!(validate: !expired) }
end end
end end
...@@ -31,7 +31,7 @@ FactoryBot.modify do ...@@ -31,7 +31,7 @@ FactoryBot.modify do
after(:create) do |merge_request, evaluator| after(:create) do |merge_request, evaluator|
merge_request.pipelines_for_merge_request.last merge_request.pipelines_for_merge_request.last
.update(ref: merge_request.train_ref_path) .update!(ref: merge_request.train_ref_path)
end end
end end
...@@ -62,7 +62,7 @@ FactoryBot.modify do ...@@ -62,7 +62,7 @@ FactoryBot.modify do
after :create do |merge_request, evaluator| after :create do |merge_request, evaluator|
next if evaluator.approval_users.blank? && evaluator.approval_groups.blank? next if evaluator.approval_users.blank? && evaluator.approval_groups.blank?
rule = merge_request.approval_rules.first_or_create(attributes_for(:approval_merge_request_rule)) rule = merge_request.approval_rules.first_or_create!(attributes_for(:approval_merge_request_rule))
rule.users = evaluator.approval_users if evaluator.approval_users.present? rule.users = evaluator.approval_users if evaluator.approval_users.present?
rule.groups = evaluator.approval_groups if evaluator.approval_groups.present? rule.groups = evaluator.approval_groups if evaluator.approval_groups.present?
end end
......
...@@ -23,7 +23,7 @@ FactoryBot.define do ...@@ -23,7 +23,7 @@ FactoryBot.define do
trait :with_assignee do |alert| trait :with_assignee do |alert|
after(:create) do |alert| after(:create) do |alert|
alert.alert_assignees.create(assignee: create(:user)) alert.alert_assignees.create!(assignee: create(:user))
end end
end end
......
...@@ -28,7 +28,7 @@ FactoryBot.define do ...@@ -28,7 +28,7 @@ FactoryBot.define do
end end
after(:create) do |board| after(:create) do |board|
board.lists.create(list_type: :closed) board.lists.create!(list_type: :closed)
end end
end end
end end
...@@ -17,7 +17,7 @@ FactoryBot.define do ...@@ -17,7 +17,7 @@ FactoryBot.define do
after(:create) do |pipeline, evaluator| after(:create) do |pipeline, evaluator|
merge_request = evaluator.head_pipeline_of merge_request = evaluator.head_pipeline_of
merge_request&.update(head_pipeline: pipeline) merge_request&.update!(head_pipeline: pipeline)
end end
factory :ci_pipeline do factory :ci_pipeline do
......
...@@ -34,7 +34,7 @@ FactoryBot.define do ...@@ -34,7 +34,7 @@ FactoryBot.define do
run_action = ->(action) do run_action = ->(action) do
sha = commit_version[action] sha = commit_version[action]
version = DesignManagement::Version.new(sha: sha, issue: issue, author: evaluator.author) version = DesignManagement::Version.new(sha: sha, issue: issue, author: evaluator.author)
version.save(validate: false) # We need it to have an ID, validate later version.save!(validate: false) # We need it to have an ID, validate later
Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert
end end
......
...@@ -135,7 +135,7 @@ FactoryBot.define do ...@@ -135,7 +135,7 @@ FactoryBot.define do
actions: version_actions actions: version_actions
) )
version.update(sha: sha) version.update!(sha: sha)
end end
end end
end end
......
...@@ -6,6 +6,6 @@ FactoryBot.define do ...@@ -6,6 +6,6 @@ FactoryBot.define do
email { generate(:email_alias) } email { generate(:email_alias) }
trait(:confirmed) { confirmed_at { Time.now } } trait(:confirmed) { confirmed_at { Time.now } }
trait(:skip_validate) { to_create {|instance| instance.save(validate: false) } } trait(:skip_validate) { to_create {|instance| instance.save!(validate: false) } }
end end
end end
...@@ -38,7 +38,7 @@ FactoryBot.define do ...@@ -38,7 +38,7 @@ FactoryBot.define do
end end
after(:create) do |issue, evaluator| after(:create) do |issue, evaluator|
issue.update(labels: evaluator.labels) issue.update!(labels: evaluator.labels)
end end
end end
end end
......
...@@ -27,7 +27,7 @@ FactoryBot.define do ...@@ -27,7 +27,7 @@ FactoryBot.define do
after(:create) do |label, evaluator| after(:create) do |label, evaluator|
if evaluator.priority if evaluator.priority
label.priorities.create(project: label.project, priority: evaluator.priority) label.priorities.create!(project: label.project, priority: evaluator.priority)
end end
end end
end end
......
...@@ -268,7 +268,7 @@ FactoryBot.define do ...@@ -268,7 +268,7 @@ FactoryBot.define do
end end
after(:create) do |merge_request, evaluator| after(:create) do |merge_request, evaluator|
merge_request.update(labels: evaluator.labels) merge_request.update!(labels: evaluator.labels)
end end
end end
end end
......
...@@ -6,7 +6,7 @@ FactoryBot.define do ...@@ -6,7 +6,7 @@ FactoryBot.define do
factory :"#{plan}_plan" do factory :"#{plan}_plan" do
name { plan } name { plan }
title { name.titleize } title { name.titleize }
initialize_with { Plan.find_or_create_by(name: plan) } initialize_with { Plan.find_or_create_by!(name: plan) }
end end
end end
end end
......
...@@ -61,7 +61,7 @@ FactoryBot.define do ...@@ -61,7 +61,7 @@ FactoryBot.define do
hash.store("pages_access_level", evaluator.pages_access_level) hash.store("pages_access_level", evaluator.pages_access_level)
end end
project.project_feature.update(hash) project.project_feature.update!(hash)
# Normally the class Projects::CreateService is used for creating # Normally the class Projects::CreateService is used for creating
# projects, and this class takes care of making sure the owner and current # projects, and this class takes care of making sure the owner and current
...@@ -82,7 +82,7 @@ FactoryBot.define do ...@@ -82,7 +82,7 @@ FactoryBot.define do
import_state.jid = evaluator.import_jid import_state.jid = evaluator.import_jid
import_state.correlation_id_value = evaluator.import_correlation_id import_state.correlation_id_value = evaluator.import_correlation_id
import_state.last_error = evaluator.import_last_error import_state.last_error = evaluator.import_last_error
import_state.save import_state.save!
end end
end end
......
...@@ -196,7 +196,7 @@ FactoryBot.define do ...@@ -196,7 +196,7 @@ FactoryBot.define do
IssueTrackerService.skip_callback(:validation, :before, :handle_properties) IssueTrackerService.skip_callback(:validation, :before, :handle_properties)
end end
to_create { |instance| instance.save(validate: false) } to_create { |instance| instance.save!(validate: false) }
after(:create) do after(:create) do
IssueTrackerService.set_callback(:validation, :before, :handle_properties) IssueTrackerService.set_callback(:validation, :before, :handle_properties)
......
...@@ -31,7 +31,8 @@ FactoryBot.define do ...@@ -31,7 +31,8 @@ FactoryBot.define do
end end
to_create do |page, evaluator| to_create do |page, evaluator|
page.create(message: evaluator.message) # WikiPages is ActiveModel which doesn't support `create!`.
page.create(message: evaluator.message) # rubocop:disable Rails/SaveBang
end end
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