Commit ccc5e166 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'reduce-queries-service-spec' into 'master'

Reduce queries in service spec

See merge request gitlab-org/gitlab!41303
parents 6092b9b6 8ca14f0e
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Service do RSpec.describe Service do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to :project } it { is_expected.to belong_to :project }
...@@ -15,8 +16,6 @@ RSpec.describe Service do ...@@ -15,8 +16,6 @@ RSpec.describe Service do
describe 'validations' do describe 'validations' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:project) { create(:project) }
it { is_expected.to validate_presence_of(:type) } it { is_expected.to validate_presence_of(:type) }
where(:project_id, :group_id, :template, :instance, :valid) do where(:project_id, :group_id, :template, :instance, :valid) do
...@@ -145,11 +144,11 @@ RSpec.describe Service do ...@@ -145,11 +144,11 @@ RSpec.describe Service do
end end
describe "Test Button" do describe "Test Button" do
let(:service) { build(:service, project: project) }
describe '#can_test?' do describe '#can_test?' do
subject { service.can_test? } subject { service.can_test? }
let(:service) { build(:service, project: project) }
context 'when repository is not empty' do context 'when repository is not empty' do
let(:project) { build(:project, :repository) } let(:project) { build(:project, :repository) }
...@@ -185,7 +184,6 @@ RSpec.describe Service do ...@@ -185,7 +184,6 @@ RSpec.describe Service do
describe '#test' do describe '#test' do
let(:data) { 'test' } let(:data) { 'test' }
let(:service) { build(:service, project: project) }
context 'when repository is not empty' do context 'when repository is not empty' do
let(:project) { build(:project, :repository) } let(:project) { build(:project, :repository) }
...@@ -264,8 +262,6 @@ RSpec.describe Service do ...@@ -264,8 +262,6 @@ RSpec.describe Service do
end end
describe 'template' do describe 'template' do
let(:project) { create(:project) }
shared_examples 'retrieves service templates' do shared_examples 'retrieves service templates' do
it 'returns the available service templates' do it 'returns the available service templates' do
expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types) expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types)
...@@ -453,7 +449,7 @@ RSpec.describe Service do ...@@ -453,7 +449,7 @@ RSpec.describe Service do
describe "{property}_changed?" do describe "{property}_changed?" do
let(:service) do let(:service) do
BambooService.create( BambooService.create(
project: create(:project), project: project,
properties: { properties: {
bamboo_url: 'http://gitlab.com', bamboo_url: 'http://gitlab.com',
username: 'mic', username: 'mic',
...@@ -493,7 +489,7 @@ RSpec.describe Service do ...@@ -493,7 +489,7 @@ RSpec.describe Service do
describe "{property}_touched?" do describe "{property}_touched?" do
let(:service) do let(:service) do
BambooService.create( BambooService.create(
project: create(:project), project: project,
properties: { properties: {
bamboo_url: 'http://gitlab.com', bamboo_url: 'http://gitlab.com',
username: 'mic', username: 'mic',
...@@ -533,7 +529,7 @@ RSpec.describe Service do ...@@ -533,7 +529,7 @@ RSpec.describe Service do
describe "{property}_was" do describe "{property}_was" do
let(:service) do let(:service) do
BambooService.create( BambooService.create(
project: create(:project), project: project,
properties: { properties: {
bamboo_url: 'http://gitlab.com', bamboo_url: 'http://gitlab.com',
username: 'mic', username: 'mic',
...@@ -573,7 +569,7 @@ RSpec.describe Service do ...@@ -573,7 +569,7 @@ RSpec.describe Service do
describe 'initialize service with no properties' do describe 'initialize service with no properties' do
let(:service) do let(:service) do
BugzillaService.create( BugzillaService.create(
project: create(:project), project: project,
project_url: 'http://gitlab.example.com' project_url: 'http://gitlab.example.com'
) )
end end
...@@ -588,7 +584,6 @@ RSpec.describe Service do ...@@ -588,7 +584,6 @@ RSpec.describe Service do
end end
describe "callbacks" do describe "callbacks" do
let(:project) { create(:project) }
let!(:service) do let!(:service) do
RedmineService.new( RedmineService.new(
project: project, project: project,
...@@ -655,7 +650,6 @@ RSpec.describe Service do ...@@ -655,7 +650,6 @@ RSpec.describe Service do
end end
context 'logging' do context 'logging' do
let(:project) { build(:project) }
let(:service) { build(:service, project: project) } let(:service) { build(:service, project: project) }
let(:test_message) { "test message" } let(:test_message) { "test message" }
let(:arguments) do let(:arguments) 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