diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 09:09:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 09:09:25 +0000 |
commit | 6f7881ee9dcec34141a8f34fc814b56b366d2b48 (patch) | |
tree | 25f72a06874b32b1049b79a9d7f4f1b7bca43b9b /spec/models | |
parent | 8c8bf44fa64f98114f7439f751c92d59a44b3218 (diff) | |
download | gitlab-ce-6f7881ee9dcec34141a8f34fc814b56b366d2b48.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/clusters/applications/ingress_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 45 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/user_canonical_email_spec.rb | 20 |
4 files changed, 129 insertions, 12 deletions
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb index ba5f48ce6b3..64d667f40f6 100644 --- a/spec/models/clusters/applications/ingress_spec.rb +++ b/spec/models/clusters/applications/ingress_spec.rb @@ -21,26 +21,60 @@ describe Clusters::Applications::Ingress do describe '#can_uninstall?' do subject { ingress.can_uninstall? } - it 'returns true if external ip is set and no application exists' do - ingress.external_ip = 'IP' + context 'with jupyter installed' do + before do + create(:clusters_applications_jupyter, :installed, cluster: ingress.cluster) + end - is_expected.to be_truthy - end + it 'returns false if external_ip_or_hostname? is true' do + ingress.external_ip = 'IP' - it 'returns false if application_jupyter_nil_or_installable? is false' do - create(:clusters_applications_jupyter, :installed, cluster: ingress.cluster) + is_expected.to be_falsey + end - is_expected.to be_falsey + it 'returns false if external_ip_or_hostname? is false' do + is_expected.to be_falsey + end end - it 'returns false if application_elastic_stack_nil_or_installable? is false' do - create(:clusters_applications_elastic_stack, :installed, cluster: ingress.cluster) + context 'with jupyter installable' do + before do + create(:clusters_applications_jupyter, :installable, cluster: ingress.cluster) + end + + it 'returns true if external_ip_or_hostname? is true' do + ingress.external_ip = 'IP' + + is_expected.to be_truthy + end - is_expected.to be_falsey + it 'returns false if external_ip_or_hostname? is false' do + is_expected.to be_falsey + end end - it 'returns false if external_ip_or_hostname? is false' do - is_expected.to be_falsey + context 'with jupyter nil' do + it 'returns false if external_ip_or_hostname? is false' do + is_expected.to be_falsey + end + + context 'if external_ip_or_hostname? is true' do + context 'with IP' do + before do + ingress.external_ip = 'IP' + end + + it { is_expected.to be_truthy } + end + + context 'with hostname' do + before do + ingress.external_hostname = 'example.com' + end + + it { is_expected.to be_truthy } + end + end end end diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index ecb87910d2d..ce341e67c14 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -39,6 +39,19 @@ describe Clusters::Applications::Prometheus do end end + describe 'transition to updating' do + let(:project) { create(:project) } + let(:cluster) { create(:cluster, projects: [project]) } + + subject { create(:clusters_applications_prometheus, :installed, cluster: cluster) } + + it 'sets last_update_started_at to now' do + Timecop.freeze do + expect { subject.make_updating }.to change { subject.reload.last_update_started_at }.to be_within(1.second).of(Time.now) + end + end + end + describe '#can_uninstall?' do let(:prometheus) { create(:clusters_applications_prometheus) } @@ -331,6 +344,38 @@ describe Clusters::Applications::Prometheus do end end + describe '#updated_since?' do + let(:cluster) { create(:cluster) } + let(:prometheus_app) { build(:clusters_applications_prometheus, cluster: cluster) } + let(:timestamp) { Time.now - 5.minutes } + + around do |example| + Timecop.freeze { example.run } + end + + before do + prometheus_app.last_update_started_at = Time.now + end + + context 'when app does not have status failed' do + it 'returns true when last update started after the timestamp' do + expect(prometheus_app.updated_since?(timestamp)).to be true + end + + it 'returns false when last update started before the timestamp' do + expect(prometheus_app.updated_since?(Time.now + 5.minutes)).to be false + end + end + + context 'when app has status failed' do + it 'returns false when last update started after the timestamp' do + prometheus_app.status = 6 + + expect(prometheus_app.updated_since?(timestamp)).to be false + end + end + end + describe 'alert manager token' do subject { create(:clusters_applications_prometheus) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ceb6382eb6c..f0423937710 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -5938,6 +5938,24 @@ describe Project do end end + describe '#environments_for_scope' do + let_it_be(:project, reload: true) { create(:project) } + + before do + create_list(:environment, 2, project: project) + end + + it 'retrieves all project environments when using the * wildcard' do + expect(project.environments_for_scope("*")).to eq(project.environments) + end + + it 'retrieves a specific project environment when using the name of that environment' do + environment = project.environments.first + + expect(project.environments_for_scope(environment.name)).to eq([environment]) + end + end + def finish_job(export_job) export_job.start export_job.finish diff --git a/spec/models/user_canonical_email_spec.rb b/spec/models/user_canonical_email_spec.rb new file mode 100644 index 00000000000..54a4e968033 --- /dev/null +++ b/spec/models/user_canonical_email_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe UserCanonicalEmail do + it { is_expected.to belong_to(:user) } + + describe 'validations' do + describe 'canonical_email' do + it { is_expected.to validate_presence_of(:canonical_email) } + + it 'validates email address', :aggregate_failures do + expect(build(:user_canonical_email, canonical_email: 'nonsense')).not_to be_valid + expect(build(:user_canonical_email, canonical_email: '@nonsense')).not_to be_valid + expect(build(:user_canonical_email, canonical_email: '@nonsense@')).not_to be_valid + expect(build(:user_canonical_email, canonical_email: 'nonsense@')).not_to be_valid + end + end + end +end |