diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-18 21:08:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-18 21:08:04 +0300 |
commit | bbe243060399191abcba33c7ebd611f6ec34c6cd (patch) | |
tree | 769ba47355cb903bc9139232d75710232ccb545a /spec/finders | |
parent | ccf37fd3eca15cd5f55c1eba3b28d2798808d357 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/environments_finder_spec.rb | 28 | ||||
-rw-r--r-- | spec/finders/events_finder_spec.rb | 26 |
2 files changed, 50 insertions, 4 deletions
diff --git a/spec/finders/environments_finder_spec.rb b/spec/finders/environments_finder_spec.rb index 69687eaa99f..7100376478a 100644 --- a/spec/finders/environments_finder_spec.rb +++ b/spec/finders/environments_finder_spec.rb @@ -13,17 +13,22 @@ describe EnvironmentsFinder do end context 'tagged deployment' do + let(:environment_two) { create(:environment, project: project) } + # Environments need to include commits, so rewind two commits to fit + let(:commit) { project.commit('HEAD~2') } + before do - create(:deployment, :success, environment: environment, ref: 'v1.1.0', tag: true, sha: project.commit.id) + create(:deployment, :success, environment: environment, ref: 'v1.0.0', tag: true, sha: project.commit.id) + create(:deployment, :success, environment: environment_two, ref: 'v1.1.0', tag: true, sha: project.commit('HEAD~1').id) end it 'returns environment when with_tags is set' do - expect(described_class.new(project, user, ref: 'master', commit: project.commit, with_tags: true).execute) - .to contain_exactly(environment) + expect(described_class.new(project, user, ref: 'master', commit: commit, with_tags: true).execute) + .to contain_exactly(environment, environment_two) end it 'does not return environment when no with_tags is set' do - expect(described_class.new(project, user, ref: 'master', commit: project.commit).execute) + expect(described_class.new(project, user, ref: 'master', commit: commit).execute) .to be_empty end @@ -31,6 +36,21 @@ describe EnvironmentsFinder do expect(described_class.new(project, user, ref: 'master', commit: project.commit('feature')).execute) .to be_empty end + + it 'returns environment when with_tags is set' do + expect(described_class.new(project, user, ref: 'master', commit: commit, with_tags: true).execute) + .to contain_exactly(environment, environment_two) + end + + # We expect two Gitaly calls: FindCommit, CommitIsAncestor + # This tests to ensure we don't call one CommitIsAncestor per environment + it 'only calls Gitaly twice when multiple environments are present', :request_store do + expect do + result = described_class.new(project, user, ref: 'master', commit: commit, with_tags: true, find_latest: true).execute + + expect(result).to contain_exactly(environment_two) + end.to change { Gitlab::GitalyClient.get_request_count }.by(2) + end end context 'branch deployment' do diff --git a/spec/finders/events_finder_spec.rb b/spec/finders/events_finder_spec.rb index 848030262cd..5c28b31e8c8 100644 --- a/spec/finders/events_finder_spec.rb +++ b/spec/finders/events_finder_spec.rb @@ -5,8 +5,10 @@ require 'spec_helper' describe EventsFinder do let(:user) { create(:user) } let(:other_user) { create(:user) } + let(:project1) { create(:project, :private, creator_id: user.id, namespace: user.namespace) } let(:project2) { create(:project, :private, creator_id: user.id, namespace: user.namespace) } + let(:closed_issue) { create(:closed_issue, project: project1, author: user) } let(:opened_merge_request) { create(:merge_request, source_project: project2, author: user) } let!(:closed_issue_event) { create(:event, project: project1, author: user, target: closed_issue, action: Event::CLOSED, created_at: Date.new(2016, 12, 30)) } @@ -15,6 +17,8 @@ describe EventsFinder do let(:opened_merge_request2) { create(:merge_request, source_project: project2, author: user) } let!(:closed_issue_event2) { create(:event, project: project1, author: user, target: closed_issue, action: Event::CLOSED, created_at: Date.new(2016, 2, 2)) } let!(:opened_merge_request_event2) { create(:event, project: project2, author: user, target: opened_merge_request, action: Event::CREATED, created_at: Date.new(2017, 2, 2)) } + let(:opened_merge_request3) { create(:merge_request, source_project: project1, author: other_user) } + let!(:other_developer_event) { create(:event, project: project1, author: other_user, target: opened_merge_request3, action: Event::CREATED) } let(:public_project) { create(:project, :public, creator_id: user.id, namespace: user.namespace) } let(:confidential_issue) { create(:closed_issue, confidential: true, project: public_project, author: user) } @@ -55,6 +59,28 @@ describe EventsFinder do end end + context 'dashboard events' do + before do + project1.add_developer(other_user) + end + + context 'scope is `all`' do + it 'includes activity of other users' do + events = described_class.new(source: user, current_user: user, scope: 'all').execute + + expect(events).to include(other_developer_event) + end + end + + context 'scope is not `all`' do + it 'does not include activity of other users' do + events = described_class.new(source: user, current_user: user, scope: '').execute + + expect(events).not_to include(other_developer_event) + end + end + end + context 'when targeting a project' do it 'returns project events between specified dates filtered on action and type' do events = described_class.new(source: project1, current_user: user, action: 'closed', target_type: 'issue', after: Date.new(2016, 12, 1), before: Date.new(2017, 1, 1)).execute |