Commit 45e0e68f authored by Alex Kalderimis's avatar Alex Kalderimis

Rename jenkins service to jenkins integration

Renames project association to jenkins association name.
parent 3f8193f8
...@@ -48,6 +48,7 @@ class Integration < ApplicationRecord ...@@ -48,6 +48,7 @@ class Integration < ApplicationRecord
flowdock flowdock
hangouts_chat hangouts_chat
irker irker
jenkins
packagist pipelines_email pivotaltracker pushover packagist pipelines_email pivotaltracker pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
].to_set.freeze ].to_set.freeze
......
...@@ -172,7 +172,7 @@ class Project < ApplicationRecord ...@@ -172,7 +172,7 @@ class Project < ApplicationRecord
has_one :flowdock_integration, class_name: 'Integrations::Flowdock' has_one :flowdock_integration, class_name: 'Integrations::Flowdock'
has_one :hangouts_chat_integration, class_name: 'Integrations::HangoutsChat' has_one :hangouts_chat_integration, class_name: 'Integrations::HangoutsChat'
has_one :irker_integration, class_name: 'Integrations::Irker' has_one :irker_integration, class_name: 'Integrations::Irker'
has_one :jenkins_service, class_name: 'Integrations::Jenkins' has_one :jenkins_integration, class_name: 'Integrations::Jenkins'
has_one :jira_service, class_name: 'Integrations::Jira' has_one :jira_service, class_name: 'Integrations::Jira'
has_one :mattermost_integration, class_name: 'Integrations::Mattermost' has_one :mattermost_integration, class_name: 'Integrations::Mattermost'
has_one :mattermost_slash_commands_integration, class_name: 'Integrations::MattermostSlashCommands' has_one :mattermost_slash_commands_integration, class_name: 'Integrations::MattermostSlashCommands'
......
...@@ -485,7 +485,7 @@ project: ...@@ -485,7 +485,7 @@ project:
- protected_environments - protected_environments
- mirror_user - mirror_user
- push_rule - push_rule
- jenkins_service - jenkins_integration
- index_status - index_status
- feature_usage - feature_usage
- approval_rules - approval_rules
......
...@@ -30,8 +30,8 @@ RSpec.describe Integrations::Jenkins do ...@@ -30,8 +30,8 @@ RSpec.describe Integrations::Jenkins do
end end
describe 'username validation' do describe 'username validation' do
before do let(:jenkins_integration) do
@jenkins_service = described_class.create!( described_class.create!(
active: active, active: active,
project: project, project: project,
properties: { properties: {
...@@ -43,7 +43,7 @@ RSpec.describe Integrations::Jenkins do ...@@ -43,7 +43,7 @@ RSpec.describe Integrations::Jenkins do
) )
end end
subject { @jenkins_service } subject { jenkins_integration }
context 'when the service is active' do context 'when the service is active' do
let(:active) { true } let(:active) { true }
...@@ -84,7 +84,7 @@ RSpec.describe Integrations::Jenkins do ...@@ -84,7 +84,7 @@ RSpec.describe Integrations::Jenkins do
describe '#hook_url' do describe '#hook_url' do
let(:username) { nil } let(:username) { nil }
let(:password) { nil } let(:password) { nil }
let(:jenkins_service) do let(:jenkins_integration) do
described_class.new( described_class.new(
project: project, project: project,
properties: { properties: {
...@@ -96,7 +96,7 @@ RSpec.describe Integrations::Jenkins do ...@@ -96,7 +96,7 @@ RSpec.describe Integrations::Jenkins do
) )
end end
subject { jenkins_service.hook_url } subject { jenkins_integration.hook_url }
context 'when the jenkins_url has no relative path' do context 'when the jenkins_url has no relative path' do
let(:jenkins_url) { 'http://jenkins.example.com/' } let(:jenkins_url) { 'http://jenkins.example.com/' }
...@@ -138,10 +138,10 @@ RSpec.describe Integrations::Jenkins do ...@@ -138,10 +138,10 @@ RSpec.describe Integrations::Jenkins do
user = create(:user, username: 'username') user = create(:user, username: 'username')
project = create(:project, name: 'project') project = create(:project, name: 'project')
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
jenkins_service = described_class.create!(jenkins_params) jenkins_integration = described_class.create!(jenkins_params)
stub_request(:post, jenkins_hook_url).with(headers: { 'Authorization' => jenkins_authorization }) stub_request(:post, jenkins_hook_url).with(headers: { 'Authorization' => jenkins_authorization })
result = jenkins_service.test(push_sample_data) result = jenkins_integration.test(push_sample_data)
expect(result).to eq({ success: true, result: '' }) expect(result).to eq({ success: true, result: '' })
end end
...@@ -152,20 +152,20 @@ RSpec.describe Integrations::Jenkins do ...@@ -152,20 +152,20 @@ RSpec.describe Integrations::Jenkins do
let(:namespace) { create(:group, :private) } let(:namespace) { create(:group, :private) }
let(:project) { create(:project, :private, name: 'project', namespace: namespace) } let(:project) { create(:project, :private, name: 'project', namespace: namespace) }
let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) } let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
let(:jenkins_service) { described_class.create!(jenkins_params) } let(:jenkins_integration) { described_class.create!(jenkins_params) }
before do before do
stub_request(:post, jenkins_hook_url) stub_request(:post, jenkins_hook_url)
end end
it 'invokes the Jenkins API' do it 'invokes the Jenkins API' do
jenkins_service.execute(push_sample_data) jenkins_integration.execute(push_sample_data)
expect(a_request(:post, jenkins_hook_url)).to have_been_made.once expect(a_request(:post, jenkins_hook_url)).to have_been_made.once
end end
it 'adds default web hook headers to the request' do it 'adds default web hook headers to the request' do
jenkins_service.execute(push_sample_data) jenkins_integration.execute(push_sample_data)
expect( expect(
a_request(:post, jenkins_hook_url) a_request(:post, jenkins_hook_url)
...@@ -174,7 +174,7 @@ RSpec.describe Integrations::Jenkins do ...@@ -174,7 +174,7 @@ RSpec.describe Integrations::Jenkins do
end end
it 'request url contains properly serialized username and password' do it 'request url contains properly serialized username and password' do
jenkins_service.execute(push_sample_data) jenkins_integration.execute(push_sample_data)
expect( expect(
a_request(:post, 'http://jenkins.example.com/project/my_project') a_request(:post, 'http://jenkins.example.com/project/my_project')
...@@ -187,8 +187,8 @@ RSpec.describe Integrations::Jenkins do ...@@ -187,8 +187,8 @@ RSpec.describe Integrations::Jenkins do
let(:project) { create(:project) } let(:project) { create(:project) }
context 'when a password was previously set' do context 'when a password was previously set' do
before do let(:jenkins_integration) do
@jenkins_service = described_class.create!( described_class.create!(
project: project, project: project,
properties: { properties: {
jenkins_url: 'http://jenkins.example.com/', jenkins_url: 'http://jenkins.example.com/',
...@@ -199,42 +199,47 @@ RSpec.describe Integrations::Jenkins do ...@@ -199,42 +199,47 @@ RSpec.describe Integrations::Jenkins do
end end
it 'resets password if url changed' do it 'resets password if url changed' do
@jenkins_service.jenkins_url = 'http://jenkins-edited.example.com/' jenkins_integration.jenkins_url = 'http://jenkins-edited.example.com/'
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to be_nil
expect(jenkins_integration.password).to be_nil
end end
it 'resets password if username is blank' do it 'resets password if username is blank' do
@jenkins_service.username = '' jenkins_integration.username = ''
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to be_nil
expect(jenkins_integration.password).to be_nil
end end
it 'does not reset password if username changed' do it 'does not reset password if username changed' do
@jenkins_service.username = 'some_name' jenkins_integration.username = 'some_name'
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to eq('password')
expect(jenkins_integration.password).to eq('password')
end end
it 'does not reset password if new url is set together with password, even if it\'s the same password' do it 'does not reset password if new url is set together with password, even if it\'s the same password' do
@jenkins_service.jenkins_url = 'http://jenkins_edited.example.com/' jenkins_integration.jenkins_url = 'http://jenkins_edited.example.com/'
@jenkins_service.password = 'password' jenkins_integration.password = 'password'
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to eq('password')
expect(@jenkins_service.jenkins_url).to eq('http://jenkins_edited.example.com/') expect(jenkins_integration.password).to eq('password')
expect(jenkins_integration.jenkins_url).to eq('http://jenkins_edited.example.com/')
end end
it 'resets password if url changed, even if setter called multiple times' do it 'resets password if url changed, even if setter called multiple times' do
@jenkins_service.jenkins_url = 'http://jenkins1.example.com/' jenkins_integration.jenkins_url = 'http://jenkins1.example.com/'
@jenkins_service.jenkins_url = 'http://jenkins1.example.com/' jenkins_integration.jenkins_url = 'http://jenkins1.example.com/'
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to be_nil
expect(jenkins_integration.password).to be_nil
end end
end end
context 'when no password was previously set' do context 'when no password was previously set' do
before do let(:jenkins_integration) do
@jenkins_service = described_class.create!( described_class.create!(
project: create(:project), project: create(:project),
properties: { properties: {
jenkins_url: 'http://jenkins.example.com/', jenkins_url: 'http://jenkins.example.com/',
...@@ -244,11 +249,12 @@ RSpec.describe Integrations::Jenkins do ...@@ -244,11 +249,12 @@ RSpec.describe Integrations::Jenkins do
end end
it 'saves password if new url is set together with password' do it 'saves password if new url is set together with password' do
@jenkins_service.jenkins_url = 'http://jenkins_edited.example.com/' jenkins_integration.jenkins_url = 'http://jenkins_edited.example.com/'
@jenkins_service.password = 'password' jenkins_integration.password = 'password'
@jenkins_service.save! jenkins_integration.save!
expect(@jenkins_service.password).to eq('password')
expect(@jenkins_service.jenkins_url).to eq('http://jenkins_edited.example.com/') expect(jenkins_integration.password).to eq('password')
expect(jenkins_integration.jenkins_url).to eq('http://jenkins_edited.example.com/')
end end
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