Commit 0c0f7b3d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'remove-unnecessary-cleanup-after-spec-context' into 'master'

Remove DB cleanup in after(:context)

See merge request gitlab-org/gitlab!28305
parents e4c54a0b 41088d00
...@@ -248,7 +248,11 @@ so we need to set some guidelines for their use going forward: ...@@ -248,7 +248,11 @@ so we need to set some guidelines for their use going forward:
In some cases, there is no need to recreate the same object for tests In some cases, there is no need to recreate the same object for tests
again for each example. For example, a project and a guest of that project again for each example. For example, a project and a guest of that project
is needed to test issues on the same project, one project and user will do for the entire file. is needed to test issues on the same project, one project and user will do for the entire file.
This can be achieved by using
As much as possible, do not implement this using `before(:all)` or `before(:context)`. If you do,
you would need to manually clean up the data as those hooks run outside a database transaction.
Instead, this can be achieved by using
[`let_it_be`](https://test-prof.evilmartians.io/#/let_it_be) variables and the [`let_it_be`](https://test-prof.evilmartians.io/#/let_it_be) variables and the
[`before_all`](https://test-prof.evilmartians.io/#/before_all) hook [`before_all`](https://test-prof.evilmartians.io/#/before_all) hook
from the [`test-prof` gem](https://rubygems.org/gems/test-prof). from the [`test-prof` gem](https://rubygems.org/gems/test-prof).
......
...@@ -16,7 +16,7 @@ describe 'Merge requests > User merges immediately', :js do ...@@ -16,7 +16,7 @@ describe 'Merge requests > User merges immediately', :js do
{ test: { stage: 'test', script: 'echo', only: ['merge_requests'] } } { test: { stage: 'test', script: 'echo', only: ['merge_requests'] } }
end end
before(:all) do before_all do
project.add_maintainer(user) project.add_maintainer(user)
project.update!(merge_pipelines_enabled: true) project.update!(merge_pipelines_enabled: true)
merge_request.all_pipelines.first.succeed! merge_request.all_pipelines.first.succeed!
......
...@@ -19,7 +19,7 @@ describe 'Projects > Activity > User sees design comment', :js do ...@@ -19,7 +19,7 @@ describe 'Projects > Activity > User sees design comment', :js do
"#{user.name} #{user.to_reference} closed issue #{issue.to_reference}" "#{user.name} #{user.to_reference} closed issue #{issue.to_reference}"
end end
before(:all) do before_all do
project.add_developer(commenter) project.add_developer(commenter)
create(:event, :for_design, project: project, author: commenter, design: design) create(:event, :for_design, project: project, author: commenter, design: design)
create(:closed_issue_event, project: project, author: user, target: issue) create(:closed_issue_event, project: project, author: user, target: issue)
......
...@@ -15,7 +15,7 @@ describe DesignManagement::Action do ...@@ -15,7 +15,7 @@ describe DesignManagement::Action do
let(:designs) { [design_a, design_b, design_c] } let(:designs) { [design_a, design_b, design_c] }
before(:all) do before_all do
create(:design_version, designs: [design_a, design_b, design_c]) create(:design_version, designs: [design_a, design_b, design_c])
create(:design_version, designs: [design_a, design_b]) create(:design_version, designs: [design_a, design_b])
create(:design_version, designs: [design_a]) create(:design_version, designs: [design_a])
......
...@@ -30,7 +30,7 @@ describe API::Issues, :mailer do ...@@ -30,7 +30,7 @@ describe API::Issues, :mailer do
let_it_be(:milestone) { create(:milestone, title: '1.0.0', project: project) } let_it_be(:milestone) { create(:milestone, title: '1.0.0', project: project) }
before(:all) do before_all do
project.add_reporter(user) project.add_reporter(user)
end end
......
...@@ -4,7 +4,7 @@ RSpec.shared_examples 'Insights page' do ...@@ -4,7 +4,7 @@ RSpec.shared_examples 'Insights page' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe 'as a permitted user' do describe 'as a permitted user' do
before(:context) do before_all do
entity.add_maintainer(user) entity.add_maintainer(user)
end end
......
...@@ -774,14 +774,16 @@ describe IssuesFinder do ...@@ -774,14 +774,16 @@ describe IssuesFinder do
end end
describe '#row_count', :request_store do describe '#row_count', :request_store do
let_it_be(:admin) { create(:admin) }
it 'returns the number of rows for the default state' do it 'returns the number of rows for the default state' do
finder = described_class.new(user) finder = described_class.new(admin)
expect(finder.row_count).to eq(4) expect(finder.row_count).to eq(4)
end end
it 'returns the number of rows for a given state' do it 'returns the number of rows for a given state' do
finder = described_class.new(user, state: 'closed') finder = described_class.new(admin, state: 'closed')
expect(finder.row_count).to be_zero expect(finder.row_count).to be_zero
end end
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Composite do describe Gitlab::Ci::Status::Composite do
let_it_be(:pipeline) { create(:ci_pipeline) } let_it_be(:pipeline) { create(:ci_pipeline) }
before(:all) do before_all do
@statuses = HasStatus::STATUSES_ENUM.map do |status, idx| @statuses = HasStatus::STATUSES_ENUM.map do |status, idx|
[status, create(:ci_build, pipeline: pipeline, status: status, importing: true)] [status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
end.to_h end.to_h
......
...@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Group::TreeRestorer do ...@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Group::TreeRestorer do
let(:shared) { Gitlab::ImportExport::Shared.new(group) } let(:shared) { Gitlab::ImportExport::Shared.new(group) }
describe 'restore group tree' do describe 'restore group tree' do
before(:context) do before_all do
# Using an admin for import, so we can check assignment of existing members # Using an admin for import, so we can check assignment of existing members
user = create(:admin, email: 'root@gitlabexample.com') user = create(:admin, email: 'root@gitlabexample.com')
create(:user, email: 'adriene.mcclure@gitlabexample.com') create(:user, email: 'adriene.mcclure@gitlabexample.com')
......
...@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Project::TreeRestorer do ...@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
let(:shared) { project.import_export_shared } let(:shared) { project.import_export_shared }
describe 'restore project tree' do describe 'restore project tree' do
before(:context) do before_all do
# Using an admin for import, so we can check assignment of existing members # Using an admin for import, so we can check assignment of existing members
@user = create(:admin) @user = create(:admin)
@existing_members = [ @existing_members = [
......
...@@ -17,5 +17,7 @@ RSpec.configure do |config| ...@@ -17,5 +17,7 @@ RSpec.configure do |config|
# Reset stdout # Reset stdout
config.after(:all) do config.after(:all) do
$stdout = STDOUT $stdout = STDOUT
delete_from_all_tables!
end end
end end
...@@ -78,7 +78,7 @@ describe API::Issues do ...@@ -78,7 +78,7 @@ describe API::Issues do
description: "closes #{issue.to_reference(private_mrs_project)}") description: "closes #{issue.to_reference(private_mrs_project)}")
end end
before(:all) do before_all do
project.add_reporter(user) project.add_reporter(user)
project.add_guest(guest) project.add_guest(guest)
private_mrs_project.add_reporter(user) private_mrs_project.add_reporter(user)
......
...@@ -61,7 +61,7 @@ describe API::Issues do ...@@ -61,7 +61,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' } let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' } let(:any_milestone_title) { 'Any' }
before(:all) do before_all do
project.add_reporter(user) project.add_reporter(user)
project.add_guest(guest) project.add_guest(guest)
private_mrs_project.add_reporter(user) private_mrs_project.add_reporter(user)
......
...@@ -60,7 +60,7 @@ describe API::Issues do ...@@ -60,7 +60,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' } let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' } let(:any_milestone_title) { 'Any' }
before(:all) do before_all do
project.add_reporter(user) project.add_reporter(user)
project.add_guest(guest) project.add_guest(guest)
end end
......
...@@ -61,7 +61,7 @@ describe API::Issues do ...@@ -61,7 +61,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' } let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' } let(:any_milestone_title) { 'Any' }
before(:all) do before_all do
project.add_reporter(user) project.add_reporter(user)
project.add_guest(guest) project.add_guest(guest)
end end
......
...@@ -92,7 +92,7 @@ describe Projects::ParticipantsService do ...@@ -92,7 +92,7 @@ describe Projects::ParticipantsService do
let_it_be(:group_ancestor_owner) { create(:user) } let_it_be(:group_ancestor_owner) { create(:user) }
before(:context) do before_all do
public_group.add_owner public_group_owner public_group.add_owner public_group_owner
private_group.add_developer private_group_member private_group.add_developer private_group_member
public_project.add_maintainer public_project_maintainer public_project.add_maintainer public_project_maintainer
...@@ -102,7 +102,7 @@ describe Projects::ParticipantsService do ...@@ -102,7 +102,7 @@ describe Projects::ParticipantsService do
end end
context 'when the private group is invited to the public project' do context 'when the private group is invited to the public project' do
before(:context) do before_all do
create(:project_group_link, group: private_group, project: public_project) create(:project_group_link, group: private_group, project: public_project)
end end
......
...@@ -11,10 +11,6 @@ RSpec.configure do |config| ...@@ -11,10 +11,6 @@ RSpec.configure do |config|
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
end end
config.append_after(:context) do
delete_from_all_tables!
end
config.append_after(:context, :migration) do config.append_after(:context, :migration) do
delete_from_all_tables! delete_from_all_tables!
......
...@@ -28,19 +28,10 @@ RSpec.shared_context 'IssuesFinder#execute context' do ...@@ -28,19 +28,10 @@ RSpec.shared_context 'IssuesFinder#execute context' do
let(:params) { {} } let(:params) { {} }
let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute }
before(:context) do before_all do
project1.add_maintainer(user) project1.add_maintainer(user)
project2.add_developer(user) project2.add_developer(user)
project2.add_developer(user2) project2.add_developer(user2)
project3.add_developer(user) project3.add_developer(user)
issue1
issue2
issue3
issue4
award_emoji1
award_emoji2
award_emoji3
end end
end end
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
RSpec.shared_examples 'snippet visibility' do RSpec.shared_examples 'snippet visibility' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
# Make sure no snippets exist prior to running the test matrix
before(:context) do
DatabaseCleaner.clean_with(:truncation)
end
let_it_be(:author) { create(:user) } let_it_be(:author) { create(:user) }
let_it_be(:member) { create(:user) } let_it_be(:member) { create(:user) }
let_it_be(:external) { create(:user, :external) } let_it_be(:external) { create(:user, :external) }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
require 'rake' require 'rake'
describe 'gitlab:app namespace rake task' do describe 'gitlab:app namespace rake task', :delete do
let(:enable_registry) { true } let(:enable_registry) { true }
def tars_glob def tars_glob
......
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