Commit 38283b4e authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 2fda8151 bcf8d48e
......@@ -144,7 +144,6 @@ module EE
scope :for_plan_name, -> (name) { joins(namespace: { gitlab_subscription: :hosted_plan }).where(plans: { name: name }) }
scope :requiring_code_owner_approval,
-> { joins(:protected_branches).where(protected_branches: { code_owner_approval_required: true }) }
scope :with_active_integrations, -> { joins(:integrations).merge(::Integration.active) }
scope :github_imported, -> { where(import_type: 'github') }
scope :with_protected_branches, -> { joins(:protected_branches) }
scope :with_repositories_enabled, -> { joins(:project_feature).where(project_features: { repository_access_level: ::ProjectFeature::ENABLED }) }
......
......@@ -11,7 +11,7 @@ RSpec.describe Analytics::DevopsAdoption::Snapshot, type: :model do
describe '.latest_for_namespace_ids' do
it 'returns for previous month finalized snapshot for the given namespace ids based on snapshot end_time' do
freeze_time do
travel_to(Date.new(2021, 07, 15)) do
group1 = create(:group)
group1_latest_snapshot = create(:devops_adoption_snapshot, namespace: group1, end_time: 1.month.ago.end_of_month, recorded_at: 1.day.ago)
create(:devops_adoption_snapshot, namespace: group1, end_time: 2.months.ago.end_of_month, recorded_at: 1.day.ago)
......
......@@ -281,16 +281,6 @@ RSpec.describe Project do
end
end
describe '.with_active_integrations' do
it 'returns the correct project' do
active = create(:service, active: true)
inactive = create(:service, active: false)
expect(described_class.with_active_integrations).to include(active.project)
expect(described_class.with_active_integrations).not_to include(inactive.project)
end
end
describe '.github_imported' do
it 'returns the correct project' do
project_imported_from_github = create(:project, :github_imported)
......
......@@ -18,7 +18,7 @@
# batch_count(::Clusters::Cluster.aws_installed.enabled, :cluster_id)
# batch_count(Namespace.group(:type))
# batch_distinct_count(::Project, :creator_id)
# batch_distinct_count(::Project.with_active_integrations.service_desk_enabled.where(time_period), start: ::User.minimum(:id), finish: ::User.maximum(:id))
# batch_distinct_count(::Project.aimed_for_deletion.service_desk_enabled.where(time_period), start: ::User.minimum(:id), finish: ::User.maximum(:id))
# batch_distinct_count(Project.group(:visibility_level), :creator_id)
# batch_sum(User, :sign_in_count)
# batch_sum(Issue.group(:state_id), :weight))
......
......@@ -11,17 +11,17 @@ module Gitlab
# In order to not use a possible complex time consuming query when calculating min and max values,
# the start and finish can be sent specifically, start and finish should contain max and min values for PRIMARY KEY of
# relation (most cases `id` column) rather than counted attribute eg:
# estimate_distinct_count(start: ::Project.with_active_integrations.minimum(:id), finish: ::Project.with_active_integrations.maximum(:id))
# estimate_distinct_count(start: ::Project.aimed_for_deletion.minimum(:id), finish: ::Project.aimed_for_deletion.maximum(:id))
#
# Grouped relations are NOT supported yet.
#
# @example Usage
# ::Gitlab::Database::PostgresHllBatchDistinctCount.new(::Project, :creator_id).execute
# ::Gitlab::Database::PostgresHllBatchDistinctCount.new(::Project.with_active_integrations.service_desk_enabled.where(time_period))
# ::Gitlab::Database::PostgresHllBatchDistinctCount.new(::Project.aimed_for_deletion.service_desk_enabled.where(time_period))
# .execute(
# batch_size: 1_000,
# start: ::Project.with_active_integrations.service_desk_enabled.where(time_period).minimum(:id),
# finish: ::Project.with_active_integrations.service_desk_enabled.where(time_period).maximum(:id)
# start: ::Project.aimed_for_deletion.service_desk_enabled.where(time_period).minimum(:id),
# finish: ::Project.aimed_for_deletion.service_desk_enabled.where(time_period).maximum(:id)
# )
#
# @note HyperLogLog is an PROBABILISTIC algorithm that ESTIMATES distinct count of given attribute value for supplied relation
......
......@@ -10,7 +10,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
let_it_be(:project) { create(:project) }
subject(:service) do
subject(:integration) do
described_class.create!(
project: project,
properties: {
......@@ -28,47 +28,47 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
end
describe 'Validations' do
context 'when service is active' do
context 'when active' do
before do
subject.active = true
integration.active = true
end
it { is_expected.to validate_presence_of(:build_key) }
it { is_expected.to validate_presence_of(:bamboo_url) }
it_behaves_like 'issue tracker service URL attribute', :bamboo_url
it_behaves_like 'issue tracker integration URL attribute', :bamboo_url
describe '#username' do
it 'does not validate the presence of username if password is nil' do
subject.password = nil
integration.password = nil
expect(subject).not_to validate_presence_of(:username)
expect(integration).not_to validate_presence_of(:username)
end
it 'validates the presence of username if password is present' do
subject.password = 'secret'
integration.password = 'secret'
expect(subject).to validate_presence_of(:username)
expect(integration).to validate_presence_of(:username)
end
end
describe '#password' do
it 'does not validate the presence of password if username is nil' do
subject.username = nil
integration.username = nil
expect(subject).not_to validate_presence_of(:password)
expect(integration).not_to validate_presence_of(:password)
end
it 'validates the presence of password if username is present' do
subject.username = 'john'
integration.username = 'john'
expect(subject).to validate_presence_of(:password)
expect(integration).to validate_presence_of(:password)
end
end
end
context 'when service is inactive' do
context 'when inactive' do
before do
subject.active = false
integration.active = false
end
it { is_expected.not_to validate_presence_of(:build_key) }
......@@ -82,45 +82,38 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
describe 'before_update :reset_password' do
context 'when a password was previously set' do
it 'resets password if url changed' do
bamboo_integration = service
integration.bamboo_url = 'http://gitlab1.com'
integration.save!
bamboo_integration.bamboo_url = 'http://gitlab1.com'
bamboo_integration.save!
expect(bamboo_integration.password).to be_nil
expect(integration.password).to be_nil
end
it 'does not reset password if username changed' do
bamboo_integration = service
bamboo_integration.username = 'some_name'
bamboo_integration.save!
integration.username = 'some_name'
integration.save!
expect(bamboo_integration.password).to eq('password')
expect(integration.password).to eq('password')
end
it "does not reset password if new url is set together with password, even if it's the same password" do
bamboo_integration = service
bamboo_integration.bamboo_url = 'http://gitlab_edited.com'
bamboo_integration.password = 'password'
bamboo_integration.save!
integration.bamboo_url = 'http://gitlab_edited.com'
integration.password = 'password'
integration.save!
expect(bamboo_integration.password).to eq('password')
expect(bamboo_integration.bamboo_url).to eq('http://gitlab_edited.com')
expect(integration.password).to eq('password')
expect(integration.bamboo_url).to eq('http://gitlab_edited.com')
end
end
it 'saves password if new url is set together with password when no password was previously set' do
bamboo_integration = service
bamboo_integration.password = nil
integration.password = nil
bamboo_integration.bamboo_url = 'http://gitlab_edited.com'
bamboo_integration.password = 'password'
bamboo_integration.save!
integration.bamboo_url = 'http://gitlab_edited.com'
integration.password = 'password'
integration.save!
expect(bamboo_integration.password).to eq('password')
expect(bamboo_integration.bamboo_url).to eq('http://gitlab_edited.com')
expect(integration.password).to eq('password')
expect(integration.bamboo_url).to eq('http://gitlab_edited.com')
end
end
end
......@@ -129,29 +122,29 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
it 'runs update and build action' do
stub_update_and_build_request
subject.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
integration.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
end
end
describe '#build_page' 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
describe '#commit_status' 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
shared_examples 'reactive cache calculation' do
describe '#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
stub_request(status: 500)
......@@ -183,7 +176,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
end
describe '#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
stub_request(status: 500)
......
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