Commit acab00fe authored by Alex Kalderimis's avatar Alex Kalderimis

Rename teamcity service to integration

Rename teamcity project association from teamcity_service to
teamcity_integration.
parent b3507289
...@@ -53,6 +53,7 @@ class Integration < ApplicationRecord ...@@ -53,6 +53,7 @@ class Integration < ApplicationRecord
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
redmine redmine
slack slack_slash_commands slack slack_slash_commands
teamcity
].to_set.freeze ].to_set.freeze
def self.renamed?(name) def self.renamed?(name)
......
...@@ -187,7 +187,7 @@ class Project < ApplicationRecord ...@@ -187,7 +187,7 @@ class Project < ApplicationRecord
has_one :redmine_integration, class_name: 'Integrations::Redmine' has_one :redmine_integration, class_name: 'Integrations::Redmine'
has_one :slack_integration, class_name: 'Integrations::Slack' has_one :slack_integration, class_name: 'Integrations::Slack'
has_one :slack_slash_commands_integration, class_name: 'Integrations::SlackSlashCommands' has_one :slack_slash_commands_integration, class_name: 'Integrations::SlackSlashCommands'
has_one :teamcity_service, class_name: 'Integrations::Teamcity' has_one :teamcity_integration, class_name: 'Integrations::Teamcity'
has_one :unify_circuit_service, class_name: 'Integrations::UnifyCircuit' has_one :unify_circuit_service, class_name: 'Integrations::UnifyCircuit'
has_one :webex_teams_service, class_name: 'Integrations::WebexTeams' has_one :webex_teams_service, class_name: 'Integrations::WebexTeams'
has_one :youtrack_service, class_name: 'Integrations::Youtrack' has_one :youtrack_service, class_name: 'Integrations::Youtrack'
......
...@@ -384,7 +384,7 @@ project: ...@@ -384,7 +384,7 @@ project:
- unify_circuit_service - unify_circuit_service
- buildkite_integration - buildkite_integration
- bamboo_integration - bamboo_integration
- teamcity_service - teamcity_integration
- pushover_integration - pushover_integration
- jira_integration - jira_integration
- redmine_integration - redmine_integration
......
...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -10,7 +10,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
let(:teamcity_full_url) { 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123' } let(:teamcity_full_url) { 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123' }
let(:project) { create(:project) } let(:project) { create(:project) }
subject(:service) do subject(:integration) do
described_class.create!( described_class.create!(
project: project, project: project,
properties: { properties: {
...@@ -28,14 +28,14 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -28,14 +28,14 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
describe 'Validations' do describe 'Validations' do
context 'when service is active' do context 'when integration is active' do
before do before do
subject.active = true subject.active = true
end end
it { is_expected.to validate_presence_of(:build_type) } it { is_expected.to validate_presence_of(:build_type) }
it { is_expected.to validate_presence_of(:teamcity_url) } it { is_expected.to validate_presence_of(:teamcity_url) }
it_behaves_like 'issue tracker service URL attribute', :teamcity_url it_behaves_like 'issue tracker integration URL attribute', :teamcity_url
describe '#username' do describe '#username' do
it 'does not validate the presence of username if password is nil' do it 'does not validate the presence of username if password is nil' do
...@@ -66,7 +66,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -66,7 +66,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
end end
context 'when service is inactive' do context 'when integration is inactive' do
before do before do
subject.active = false subject.active = false
end end
...@@ -79,71 +79,66 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -79,71 +79,66 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
describe 'Callbacks' do describe 'Callbacks' do
let(:teamcity_integration) { integration }
describe 'before_update :reset_password' do describe 'before_update :reset_password' do
context 'when a password was previously set' do context 'when a password was previously set' do
it 'resets password if url changed' do it 'resets password if url changed' do
teamcity_service = service teamcity_integration.teamcity_url = 'http://gitlab1.com'
teamcity_integration.save!
teamcity_service.teamcity_url = 'http://gitlab1.com'
teamcity_service.save!
expect(teamcity_service.password).to be_nil expect(teamcity_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
teamcity_service = service teamcity_integration.username = 'some_name'
teamcity_integration.save!
teamcity_service.username = 'some_name' expect(teamcity_integration.password).to eq('password')
teamcity_service.save!
expect(teamcity_service.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
teamcity_service = service teamcity_integration.teamcity_url = 'http://gitlab_edited.com'
teamcity_integration.password = 'password'
teamcity_service.teamcity_url = 'http://gitlab_edited.com' teamcity_integration.save!
teamcity_service.password = 'password'
teamcity_service.save!
expect(teamcity_service.password).to eq('password') expect(teamcity_integration.password).to eq('password')
expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com') expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com')
end end
end end
it 'saves password if new url is set together with password when no password was previously set' do it 'saves password if new url is set together with password when no password was previously set' do
teamcity_service = service teamcity_integration.password = nil
teamcity_service.password = nil
teamcity_service.teamcity_url = 'http://gitlab_edited.com' teamcity_integration.teamcity_url = 'http://gitlab_edited.com'
teamcity_service.password = 'password' teamcity_integration.password = 'password'
teamcity_service.save! teamcity_integration.save!
expect(teamcity_service.password).to eq('password') expect(teamcity_integration.password).to eq('password')
expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com') expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com')
end end
end end
end end
describe '#build_page' do describe '#build_page' do
it 'returns the contents of the reactive cache' do it 'returns the contents of the reactive cache' do
stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref') stub_reactive_cache(integration, { build_page: 'foo' }, 'sha', 'ref')
expect(service.build_page('sha', 'ref')).to eq('foo') expect(integration.build_page('sha', 'ref')).to eq('foo')
end end
end end
describe '#commit_status' do describe '#commit_status' do
it 'returns the contents of the reactive cache' do it 'returns the contents of the reactive cache' do
stub_reactive_cache(service, { commit_status: 'foo' }, 'sha', 'ref') stub_reactive_cache(integration, { commit_status: 'foo' }, 'sha', 'ref')
expect(service.commit_status('sha', 'ref')).to eq('foo') expect(integration.commit_status('sha', 'ref')).to eq('foo')
end end
end end
describe '#calculate_reactive_cache' do describe '#calculate_reactive_cache' do
context 'build_page' do context 'build_page' do
subject { service.calculate_reactive_cache('123', 'unused')[:build_page] } subject { integration.calculate_reactive_cache('123', 'unused')[:build_page] }
it 'returns a specific URL when status is 500' do it 'returns a specific URL when status is 500' do
stub_request(status: 500) stub_request(status: 500)
...@@ -179,7 +174,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -179,7 +174,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
end end
context 'commit_status' do context 'commit_status' do
subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } subject { integration.calculate_reactive_cache('123', 'unused')[:commit_status] }
it 'sets commit status to :error when status is 500' do it 'sets commit status to :error when status is 500' do
stub_request(status: 500) stub_request(status: 500)
...@@ -243,25 +238,25 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -243,25 +238,25 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
it 'handles push request correctly' do it 'handles push request correctly' do
stub_post_to_build_queue(branch: 'dev-123_branch') stub_post_to_build_queue(branch: 'dev-123_branch')
expect(service.execute(data)).to include('Ok') expect(integration.execute(data)).to include('Ok')
end end
it 'returns nil when ref is blank' do it 'returns nil when ref is blank' do
data[:after] = Gitlab::Git::BLANK_SHA data[:after] = Gitlab::Git::BLANK_SHA
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil when there is no content' do it 'returns nil when there is no content' do
data[:total_commits_count] = 0 data[:total_commits_count] = 0
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil when a merge request is opened for the same ref' do it 'returns nil when a merge request is opened for the same ref' do
create(:merge_request, source_project: project, source_branch: 'dev-123_branch') create(:merge_request, source_project: project, source_branch: 'dev-123_branch')
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
...@@ -283,26 +278,26 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do ...@@ -283,26 +278,26 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do
it 'handles merge request correctly' do it 'handles merge request correctly' do
stub_post_to_build_queue(branch: 'dev-123_branch') stub_post_to_build_queue(branch: 'dev-123_branch')
expect(service.execute(data)).to include('Ok') expect(integration.execute(data)).to include('Ok')
end end
it 'returns nil when merge request is not opened' do it 'returns nil when merge request is not opened' do
data[:object_attributes][:state] = 'closed' data[:object_attributes][:state] = 'closed'
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
it 'returns nil unless merge request is marked as unchecked' do it 'returns nil unless merge request is marked as unchecked' do
data[:object_attributes][:merge_status] = 'can_be_merged' data[:object_attributes][:merge_status] = 'can_be_merged'
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
it 'returns nil when event is not supported' do it 'returns nil when event is not supported' do
data = { object_kind: 'foo' } data = { object_kind: 'foo' }
expect(service.execute(data)).to be_nil expect(integration.execute(data)).to be_nil
end end
end end
......
...@@ -59,7 +59,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -59,7 +59,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:mattermost_slash_commands_integration) } it { is_expected.to have_one(:mattermost_slash_commands_integration) }
it { is_expected.to have_one(:buildkite_integration) } it { is_expected.to have_one(:buildkite_integration) }
it { is_expected.to have_one(:bamboo_integration) } it { is_expected.to have_one(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) } it { is_expected.to have_one(:teamcity_integration) }
it { is_expected.to have_one(:jira_integration) } it { is_expected.to have_one(:jira_integration) }
it { is_expected.to have_one(:redmine_integration) } it { is_expected.to have_one(:redmine_integration) }
it { is_expected.to have_one(:youtrack_service) } it { is_expected.to have_one(:youtrack_service) }
......
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