diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 03:09:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 03:09:07 +0300 |
commit | e144369009f3404072f7e0f969f7cded93195a01 (patch) | |
tree | d7a354e2c3c69a7ad65dc81aba8fe2ba59b0a26f /spec/models | |
parent | d466ee5042520ad078fe050cb078d81dc2ebe196 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/mentionable_spec.rb | 36 | ||||
-rw-r--r-- | spec/models/cycle_analytics/group_level_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/deployment_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 69 | ||||
-rw-r--r-- | spec/models/event_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/trending_project_spec.rb | 10 |
8 files changed, 169 insertions, 13 deletions
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index 883f678b8f5..13a3d1cdd82 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -26,6 +26,42 @@ describe Mentionable do expect(mentionable.referenced_mentionables).to be_empty end end + + describe '#any_mentionable_attributes_changed?' do + Message = Struct.new(:text) + + let(:mentionable) { Example.new } + let(:changes) do + msg = Message.new('test') + + changes = {} + changes[msg] = ['', 'some message'] + changes[:random_sym_key] = ['', 'some message'] + changes["random_string_key"] = ['', 'some message'] + changes + end + + it 'returns true with key string' do + changes["message"] = ['', 'some message'] + + allow(mentionable).to receive(:saved_changes).and_return(changes) + + expect(mentionable.send(:any_mentionable_attributes_changed?)).to be true + end + + it 'returns false with key symbol' do + changes[:message] = ['', 'some message'] + allow(mentionable).to receive(:saved_changes).and_return(changes) + + expect(mentionable.send(:any_mentionable_attributes_changed?)).to be false + end + + it 'returns false when no attr_mentionable keys' do + allow(mentionable).to receive(:saved_changes).and_return(changes) + + expect(mentionable.send(:any_mentionable_attributes_changed?)).to be false + end + end end describe Issue, "Mentionable" do diff --git a/spec/models/cycle_analytics/group_level_spec.rb b/spec/models/cycle_analytics/group_level_spec.rb index 03fe8c3b50b..1f410a7c539 100644 --- a/spec/models/cycle_analytics/group_level_spec.rb +++ b/spec/models/cycle_analytics/group_level_spec.rb @@ -22,10 +22,6 @@ describe CycleAnalytics::GroupLevel do describe '#stats' do before do - allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance| - allow(instance).to receive(:issues).and_return([issue]) - end - create_cycle(user, project, issue, mr, milestone, pipeline) deploy_master(user, project) end diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index bdbe38afc56..89fb4eb3ff2 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -51,6 +51,22 @@ describe Deployment do end end + describe '.stoppable' do + subject { described_class.stoppable } + + context 'when deployment is stoppable' do + let!(:deployment) { create(:deployment, :success, on_stop: 'stop-review') } + + it { is_expected.to eq([deployment]) } + end + + context 'when deployment is not stoppable' do + let!(:deployment) { create(:deployment, :failed) } + + it { is_expected.to be_empty } + end + end + describe '.success' do subject { described_class.success } diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index af7ab24d7d6..72143d69fc8 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -7,6 +7,7 @@ describe Environment, :use_clean_rails_memory_store_caching do using RSpec::Parameterized::TableSyntax include RepoHelpers include StubENV + include CreateEnvironmentsHelpers let(:project) { create(:project, :repository) } @@ -114,6 +115,72 @@ describe Environment, :use_clean_rails_memory_store_caching do end end + describe '.auto_stoppable' do + subject { described_class.auto_stoppable(limit) } + + let(:limit) { 100 } + + context 'when environment is auto-stoppable' do + let!(:environment) { create(:environment, :auto_stoppable) } + + it { is_expected.to eq([environment]) } + end + + context 'when environment is not auto-stoppable' do + let!(:environment) { create(:environment) } + + it { is_expected.to be_empty } + end + end + + describe '.stop_actions' do + subject { environments.stop_actions } + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let(:environments) { Environment.all } + + before_all do + project.add_developer(user) + project.repository.add_branch(user, 'review/feature-1', 'master') + project.repository.add_branch(user, 'review/feature-2', 'master') + end + + shared_examples_for 'correct filtering' do + it 'returns stop actions for available environments only' do + expect(subject.count).to eq(1) + expect(subject.first.name).to eq('stop_review_app') + expect(subject.first.ref).to eq('review/feature-1') + end + end + + before do + create_review_app(user, project, 'review/feature-1') + create_review_app(user, project, 'review/feature-2') + end + + it 'returns stop actions for environments' do + expect(subject.count).to eq(2) + expect(subject).to match_array(Ci::Build.where(name: 'stop_review_app')) + end + + context 'when one of the stop actions has already been executed' do + before do + Ci::Build.where(ref: 'review/feature-2').find_by_name('stop_review_app').enqueue! + end + + it_behaves_like 'correct filtering' + end + + context 'when one of the deployments does not have stop action' do + before do + Deployment.where(ref: 'review/feature-2').update_all(on_stop: nil) + end + + it_behaves_like 'correct filtering' + end + end + describe '.pluck_names' do subject { described_class.pluck_names } @@ -449,7 +516,7 @@ describe Environment, :use_clean_rails_memory_store_caching do describe '#reset_auto_stop' do subject { environment.reset_auto_stop } - let(:environment) { create(:environment, :auto_stopped) } + let(:environment) { create(:environment, :auto_stoppable) } it 'nullifies the auto_stop_at' do expect { subject }.to change(environment, :auto_stop_at).from(Time).to(nil) diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 990141cf511..97ea32a120d 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -173,6 +173,7 @@ describe Event do end context 'commit note event' do + let(:project) { create(:project, :public, :repository) } let(:target) { note_on_commit } it do @@ -185,7 +186,7 @@ describe Event do end context 'private project' do - let(:project) { create(:project, :private) } + let(:project) { create(:project, :private, :repository) } it do aggregate_failures do diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 08348e3767a..36fd5d21e73 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -3576,4 +3576,44 @@ describe MergeRequest do expect(merge_request.recent_visible_deployments.count).to eq(10) end end + + describe '#diffable_merge_ref?' do + context 'diff_compare_with_head enabled' do + context 'merge request can be merged' do + context 'merge_to_ref is not calculated' do + it 'returns true' do + expect(subject.diffable_merge_ref?).to eq(false) + end + end + + context 'merge_to_ref is calculated' do + before do + MergeRequests::MergeToRefService.new(subject.project, subject.author).execute(subject) + end + + it 'returns true' do + expect(subject.diffable_merge_ref?).to eq(true) + end + end + end + + context 'merge request cannot be merged' do + it 'returns false' do + subject.mark_as_unchecked! + + expect(subject.diffable_merge_ref?).to eq(false) + end + end + end + + context 'diff_compare_with_head disabled' do + before do + stub_feature_flags(diff_compare_with_head: { enabled: false, thing: subject.target_project }) + end + + it 'returns false' do + expect(subject.diffable_merge_ref?).to eq(false) + end + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 79d9e42666c..b3d8ac83075 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1299,8 +1299,8 @@ describe Project do describe '.trending' do let(:group) { create(:group, :public) } - let(:project1) { create(:project, :public, group: group) } - let(:project2) { create(:project, :public, group: group) } + let(:project1) { create(:project, :public, :repository, group: group) } + let(:project2) { create(:project, :public, :repository, group: group) } before do create_list(:note_on_commit, 2, project: project1) diff --git a/spec/models/trending_project_spec.rb b/spec/models/trending_project_spec.rb index 4a248b71574..39f5d686eb4 100644 --- a/spec/models/trending_project_spec.rb +++ b/spec/models/trending_project_spec.rb @@ -4,11 +4,11 @@ require 'spec_helper' describe TrendingProject do let(:user) { create(:user) } - let(:public_project1) { create(:project, :public) } - let(:public_project2) { create(:project, :public) } - let(:public_project3) { create(:project, :public) } - let(:private_project) { create(:project, :private) } - let(:internal_project) { create(:project, :internal) } + let(:public_project1) { create(:project, :public, :repository) } + let(:public_project2) { create(:project, :public, :repository) } + let(:public_project3) { create(:project, :public, :repository) } + let(:private_project) { create(:project, :private, :repository) } + let(:internal_project) { create(:project, :internal, :repository) } before do create_list(:note_on_commit, 3, project: public_project1) |