Commit 41088d00 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Remove DB cleanup in after(:context)

`set` has been removed so there shouldn't be any extra data left over
after specs are run. I also checked all `before(:all)` and
`before(:context)` calls to make sure those are cleaned up.
parent 964f191d
......@@ -244,7 +244,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
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.
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
[`before_all`](https://test-prof.evilmartians.io/#/before_all) hook
from the [`test-prof` gem](https://rubygems.org/gems/test-prof).
......
......@@ -16,7 +16,7 @@ describe 'Merge requests > User merges immediately', :js do
{ test: { stage: 'test', script: 'echo', only: ['merge_requests'] } }
end
before(:all) do
before_all do
project.add_maintainer(user)
project.update!(merge_pipelines_enabled: true)
merge_request.all_pipelines.first.succeed!
......
......@@ -19,7 +19,7 @@ describe 'Projects > Activity > User sees design comment', :js do
"#{user.name} #{user.to_reference} closed issue #{issue.to_reference}"
end
before(:all) do
before_all do
project.add_developer(commenter)
create(:event, :for_design, project: project, author: commenter, design: design)
create(:closed_issue_event, project: project, author: user, target: issue)
......
......@@ -15,7 +15,7 @@ describe DesignManagement::Action do
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])
create(:design_version, designs: [design_a])
......
......@@ -30,7 +30,7 @@ describe API::Issues, :mailer do
let_it_be(:milestone) { create(:milestone, title: '1.0.0', project: project) }
before(:all) do
before_all do
project.add_reporter(user)
end
......
......@@ -4,7 +4,7 @@ RSpec.shared_examples 'Insights page' do
let_it_be(:user) { create(:user) }
describe 'as a permitted user' do
before(:context) do
before_all do
entity.add_maintainer(user)
end
......
......@@ -774,14 +774,16 @@ describe IssuesFinder do
end
describe '#row_count', :request_store do
let_it_be(:admin) { create(:admin) }
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)
end
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
end
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Composite do
let_it_be(:pipeline) { create(:ci_pipeline) }
before(:all) do
before_all do
@statuses = HasStatus::STATUSES_ENUM.map do |status, idx|
[status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
end.to_h
......
......@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Group::TreeRestorer do
let(:shared) { Gitlab::ImportExport::Shared.new(group) }
describe 'restore group tree' do
before(:context) do
before_all do
# Using an admin for import, so we can check assignment of existing members
user = create(:admin, email: 'root@gitlabexample.com')
create(:user, email: 'adriene.mcclure@gitlabexample.com')
......
......@@ -8,7 +8,7 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
let(:shared) { project.import_export_shared }
describe 'restore project tree' do
before(:context) do
before_all do
# Using an admin for import, so we can check assignment of existing members
@user = create(:admin)
@existing_members = [
......
......@@ -17,5 +17,7 @@ RSpec.configure do |config|
# Reset stdout
config.after(:all) do
$stdout = STDOUT
delete_from_all_tables!
end
end
......@@ -78,7 +78,7 @@ describe API::Issues do
description: "closes #{issue.to_reference(private_mrs_project)}")
end
before(:all) do
before_all do
project.add_reporter(user)
project.add_guest(guest)
private_mrs_project.add_reporter(user)
......
......@@ -61,7 +61,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' }
before(:all) do
before_all do
project.add_reporter(user)
project.add_guest(guest)
private_mrs_project.add_reporter(user)
......
......@@ -60,7 +60,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' }
before(:all) do
before_all do
project.add_reporter(user)
project.add_guest(guest)
end
......
......@@ -61,7 +61,7 @@ describe API::Issues do
let(:no_milestone_title) { 'None' }
let(:any_milestone_title) { 'Any' }
before(:all) do
before_all do
project.add_reporter(user)
project.add_guest(guest)
end
......
......@@ -92,7 +92,7 @@ describe Projects::ParticipantsService do
let_it_be(:group_ancestor_owner) { create(:user) }
before(:context) do
before_all do
public_group.add_owner public_group_owner
private_group.add_developer private_group_member
public_project.add_maintainer public_project_maintainer
......@@ -102,7 +102,7 @@ describe Projects::ParticipantsService do
end
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)
end
......
......@@ -11,10 +11,6 @@ RSpec.configure do |config|
DatabaseCleaner.clean_with(:truncation)
end
config.append_after(:context) do
delete_from_all_tables!
end
config.append_after(:context, :migration) do
delete_from_all_tables!
......
......@@ -28,19 +28,10 @@ RSpec.shared_context 'IssuesFinder#execute context' do
let(:params) { {} }
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)
project2.add_developer(user)
project2.add_developer(user2)
project3.add_developer(user)
issue1
issue2
issue3
issue4
award_emoji1
award_emoji2
award_emoji3
end
end
......@@ -3,11 +3,6 @@
RSpec.shared_examples 'snippet visibility' do
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(:member) { create(:user) }
let_it_be(:external) { create(:user, :external) }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
require 'rake'
describe 'gitlab:app namespace rake task' do
describe 'gitlab:app namespace rake task', :delete do
let(:enable_registry) { true }
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