Commit 0cc9982a authored by Eugenia Grieff's avatar Eugenia Grieff

Reduce no of queries in epic_issues service specs

- Replace the use of modifier let with let_it_be
parent 39b7836b
......@@ -4,14 +4,14 @@ require 'spec_helper'
RSpec.describe EpicIssues::CreateService do
describe '#execute' do
let(:group) { create(:group) }
let(:epic) { create(:epic, group: group) }
let(:project) { create(:project, group: group) }
let(:issue) { create(:issue, project: project) }
let(:issue2) { create(:issue, project: project) }
let(:issue3) { create(:issue, project: project) }
let(:user) { create(:user) }
let(:valid_reference) { issue.to_reference(full: true) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:issue2) { create(:issue, project: project) }
let_it_be(:issue3) { create(:issue, project: project) }
let_it_be(:valid_reference) { issue.to_reference(full: true) }
let_it_be(:epic, reload: true) { create(:epic, group: group) }
def assign_issue(references)
params = { issuable_references: references }
......@@ -159,9 +159,9 @@ RSpec.describe EpicIssues::CreateService do
end
context 'when a link of an issue in a subgroup is given' do
let(:subgroup) { create(:group, parent: group) }
let(:project2) { create(:project, group: subgroup) }
let(:issue) { create(:issue, project: project2) }
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:project2) { create(:project, group: subgroup) }
let_it_be(:issue) { create(:issue, project: project2) }
subject { assign_issue([Gitlab::Routing.url_helpers.namespace_project_issue_url(namespace_id: issue.project.namespace, project_id: issue.project, id: issue.iid)])}
......@@ -201,10 +201,10 @@ RSpec.describe EpicIssues::CreateService do
end
context 'when there are invalid references' do
let(:epic) { create(:epic, confidential: true, group: group) }
let(:valid_issue) { create(:issue, :confidential, project: project) }
let(:invalid_issue1) { create(:issue, project: project) }
let(:invalid_issue2) { create(:issue, project: project) }
let_it_be(:epic) { create(:epic, confidential: true, group: group) }
let_it_be(:valid_issue) { create(:issue, :confidential, project: project) }
let_it_be(:invalid_issue1) { create(:issue, project: project) }
let_it_be(:invalid_issue2) { create(:issue, project: project) }
subject do
assign_issue([invalid_issue1.to_reference(full: true),
......@@ -255,7 +255,7 @@ RSpec.describe EpicIssues::CreateService do
end
context 'when at least one of the issues is still not assigned to the epic' do
let(:valid_reference) { issue2.to_reference(full: true) }
let_it_be(:valid_reference) { issue2.to_reference(full: true) }
subject { assign_issue([valid_reference, issue.to_reference(full: true)]) }
......@@ -270,7 +270,7 @@ RSpec.describe EpicIssues::CreateService do
issue.reload
end
let(:another_epic) { create(:epic, group: group) }
let_it_be(:another_epic) { create(:epic, group: group) }
subject do
params = { issuable_references: [valid_reference] }
......@@ -335,7 +335,7 @@ RSpec.describe EpicIssues::CreateService do
context 'when issue from non group project is given' do
subject { assign_issue([another_issue.to_reference(full: true)]) }
let(:another_issue) { create :issue }
let_it_be(:another_issue) { create :issue }
before do
group.add_developer(user)
......
......@@ -4,12 +4,12 @@ require 'spec_helper'
RSpec.describe EpicIssues::DestroyService do
describe '#execute' do
let(:user) { create(:user) }
let(:group) { create(:group, :public) }
let(:project) { create(:project, group: group) }
let(:epic) { create(:epic, group: group) }
let(:issue) { create(:issue, project: project) }
let!(:epic_issue) { create(:epic_issue, epic: epic, issue: issue) }
let_it_be(:user) { create(:user) }
let_it_be(:group, refind: true) { create(:group, :public) }
let_it_be(:project, refind: true) { create(:project, group: group) }
let_it_be(:epic, reload: true) { create(:epic, group: group) }
let_it_be(:issue, reload: true) { create(:issue, project: project) }
let_it_be(:epic_issue, reload: true) { create(:epic_issue, epic: epic, issue: issue) }
subject { described_class.new(epic_issue, user).execute }
......
......@@ -3,22 +3,22 @@
require 'spec_helper'
RSpec.describe EpicIssues::ListService do
let(:user) { create :user }
let(:group) { create(:group, :private) }
let(:project) { create(:project_empty_repo, group: group) }
let(:other_project) { create(:project_empty_repo, group: group) }
let(:epic) { create(:epic, group: group) }
let_it_be(:user) { create :user }
let_it_be(:group, refind: true) { create(:group, :private) }
let_it_be(:project, refind: true) { create(:project_empty_repo, group: group) }
let_it_be(:other_project) { create(:project_empty_repo, group: group) }
let_it_be(:epic, refind: true) { create(:epic, group: group) }
# Reloading issues here is needed because when storing datetime on postgres
# nanoseconds precision is ignored when fetching records but not when inserting,
# which makes the expectations fails for created_at field.
let!(:issue1) { create(:issue, project: project, weight: 1).reload }
let!(:issue2) { create(:issue, project: project).reload }
let!(:issue3) { create(:issue, project: other_project).reload }
let_it_be(:issue1) { create(:issue, project: project, weight: 1).reload }
let_it_be(:issue2) { create(:issue, project: project).reload }
let_it_be(:issue3) { create(:issue, project: other_project).reload }
let!(:epic_issue1) { create(:epic_issue, issue: issue1, epic: epic, relative_position: 2) }
let!(:epic_issue2) { create(:epic_issue, issue: issue2, epic: epic, relative_position: 1) }
let!(:epic_issue3) { create(:epic_issue, issue: issue3, epic: epic, relative_position: 3) }
let_it_be(:epic_issue1) { create(:epic_issue, issue: issue1, epic: epic, relative_position: 2) }
let_it_be(:epic_issue2) { create(:epic_issue, issue: issue2, epic: epic, relative_position: 1) }
let_it_be(:epic_issue3) { create(:epic_issue, issue: issue3, epic: epic, relative_position: 3) }
describe '#execute' do
subject { described_class.new(epic, user).execute }
......
......@@ -4,15 +4,15 @@ require 'spec_helper'
RSpec.describe EpicIssues::UpdateService do
describe '#execute' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:epic) { create(:epic, group: group) }
let(:issues) { create_list(:issue, 4) }
let!(:epic_issue1) { create(:epic_issue, epic: epic, issue: issues[0], relative_position: 3) }
let!(:epic_issue2) { create(:epic_issue, epic: epic, issue: issues[1], relative_position: 600) }
let!(:epic_issue3) { create(:epic_issue, epic: epic, issue: issues[2], relative_position: 1200) }
let!(:epic_issue4) { create(:epic_issue, epic: epic, issue: issues[3], relative_position: 2000) }
let(:default_position_value) { Gitlab::Database::MAX_INT_VALUE / 2 }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:epic) { create(:epic, group: group) }
let_it_be(:issues) { create_list(:issue, 4) }
let_it_be(:epic_issue1, reload: true) { create(:epic_issue, epic: epic, issue: issues[0], relative_position: 3) }
let_it_be(:epic_issue2, reload: true) { create(:epic_issue, epic: epic, issue: issues[1], relative_position: 600) }
let_it_be(:epic_issue3, reload: true) { create(:epic_issue, epic: epic, issue: issues[2], relative_position: 1200) }
let_it_be(:epic_issue4, reload: true) { create(:epic_issue, epic: epic, issue: issues[3], relative_position: 2000) }
let_it_be(:default_position_value) { Gitlab::Database::MAX_INT_VALUE / 2 }
before do
group.add_developer(user)
......@@ -28,10 +28,10 @@ RSpec.describe EpicIssues::UpdateService do
context 'when moving issues between different epics' do
before do
epic_issue3.update_attribute(:epic, create(:epic, group: group))
epic_issue3.update_attribute(:epic, build(:epic, group: group))
end
let(:params) { { move_before_id: epic_issue3.id, move_after_id: epic_issue4.id } }
let_it_be(:params) { { move_before_id: epic_issue3.id, move_after_id: epic_issue4.id } }
subject { order_issue(epic_issue1, params) }
......@@ -50,7 +50,7 @@ RSpec.describe EpicIssues::UpdateService do
end
context 'moving issue to the first position' do
let(:params) { { move_after_id: epic_issue1.id } }
let_it_be(:params) { { move_after_id: epic_issue1.id } }
context 'when some positions are close to each other' do
before do
......@@ -76,7 +76,7 @@ RSpec.describe EpicIssues::UpdateService do
end
context 'moving issue to the third position' do
let(:params) { { move_before_id: epic_issue3.id, move_after_id: epic_issue4.id } }
let_it_be(:params) { { move_before_id: epic_issue3.id, move_after_id: epic_issue4.id } }
context 'when some positions are close to each other' do
before 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