diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 00:08:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 00:08:08 +0300 |
commit | e0b84f4ba4b44c8ecf00be97843c40df2550b74c (patch) | |
tree | 7cecae4276358dd46d7fa15f84068f7b4c626089 /spec/models/cycle_analytics | |
parent | 73391dcc368ef846c2960c1d0ef5e64ca78e1bee (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/cycle_analytics')
-rw-r--r-- | spec/models/cycle_analytics/code_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/cycle_analytics/group_level_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/cycle_analytics/issue_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/cycle_analytics/plan_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/cycle_analytics/production_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/cycle_analytics/project_level_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/cycle_analytics/review_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/cycle_analytics/staging_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/cycle_analytics/test_spec.rb | 26 |
9 files changed, 50 insertions, 77 deletions
diff --git a/spec/models/cycle_analytics/code_spec.rb b/spec/models/cycle_analytics/code_spec.rb index 808659552ff..441f8265629 100644 --- a/spec/models/cycle_analytics/code_spec.rb +++ b/spec/models/cycle_analytics/code_spec.rb @@ -5,11 +5,12 @@ require 'spec_helper' describe 'CycleAnalytics#code' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } context 'with deployment' do generate_cycle_analytics_spec( @@ -24,8 +25,6 @@ describe 'CycleAnalytics#code' do context.create_merge_request_closing_issue(context.user, context.project, data[:issue]) end]], post_fn: -> (context, data) do - context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue]) - context.deploy_master(context.user, context.project) end) context "when a regular merge request (that doesn't close the issue) is created" do @@ -56,7 +55,6 @@ describe 'CycleAnalytics#code' do context.create_merge_request_closing_issue(context.user, context.project, data[:issue]) end]], post_fn: -> (context, data) do - context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue]) end) context "when a regular merge request (that doesn't close the issue) is created" do diff --git a/spec/models/cycle_analytics/group_level_spec.rb b/spec/models/cycle_analytics/group_level_spec.rb index 0d2c14c29dd..03fe8c3b50b 100644 --- a/spec/models/cycle_analytics/group_level_spec.rb +++ b/spec/models/cycle_analytics/group_level_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' describe CycleAnalytics::GroupLevel do - let(:group) { create(:group)} - let(:project) { create(:project, :repository, namespace: group) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:group) { create(:group)} + let_it_be(:project) { create(:project, :repository, namespace: group) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } let(:issue) { create(:issue, project: project, created_at: 2.days.ago) } - let(:milestone) { create(:milestone, project: project) } + let_it_be(:milestone) { create(:milestone, project: project) } let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") } let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) } diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb index 8cdf83b1292..726f2f8b018 100644 --- a/spec/models/cycle_analytics/issue_spec.rb +++ b/spec/models/cycle_analytics/issue_spec.rb @@ -5,11 +5,12 @@ require 'spec_helper' describe 'CycleAnalytics#issue' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } generate_cycle_analytics_spec( phase: :issue, @@ -28,10 +29,6 @@ describe 'CycleAnalytics#issue' do end end]], post_fn: -> (context, data) do - if data[:issue].persisted? - context.create_merge_request_closing_issue(context.user, context.project, data[:issue].reload) - context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue]) - end end) context "when a regular label (instead of a list label) is added to the issue" do diff --git a/spec/models/cycle_analytics/plan_spec.rb b/spec/models/cycle_analytics/plan_spec.rb index 28ad9bd194d..3bd9f317ca7 100644 --- a/spec/models/cycle_analytics/plan_spec.rb +++ b/spec/models/cycle_analytics/plan_spec.rb @@ -5,17 +5,18 @@ require 'spec_helper' describe 'CycleAnalytics#plan' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } generate_cycle_analytics_spec( phase: :plan, data_fn: -> (context) do { - issue: context.create(:issue, project: context.project), + issue: context.build(:issue, project: context.project), branch_name: context.generate(:branch) } end, @@ -32,8 +33,6 @@ describe 'CycleAnalytics#plan' do context.create_commit_referencing_issue(data[:issue], branch_name: data[:branch_name]) end]], post_fn: -> (context, data) do - context.create_merge_request_closing_issue(context.user, context.project, data[:issue], source_branch: data[:branch_name]) - context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue]) end) context "when a regular label (instead of a list label) is added to the issue" do diff --git a/spec/models/cycle_analytics/production_spec.rb b/spec/models/cycle_analytics/production_spec.rb index 613c1786540..01d88bbeec9 100644 --- a/spec/models/cycle_analytics/production_spec.rb +++ b/spec/models/cycle_analytics/production_spec.rb @@ -5,11 +5,12 @@ require 'spec_helper' describe 'CycleAnalytics#production' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } generate_cycle_analytics_spec( phase: :production, @@ -24,13 +25,7 @@ describe 'CycleAnalytics#production' do ["production deploy happens after merge request is merged (along with other changes)", lambda do |context, data| # Make other changes on master - sha = context.project.repository.create_file( - context.user, - context.generate(:branch), - 'content', - message: 'commit message', - branch_name: 'master') - context.project.repository.commit(sha) + context.project.repository.commit("sha_that_does_not_matter") context.deploy_master(context.user, context.project) end]]) @@ -47,7 +42,7 @@ describe 'CycleAnalytics#production' do context "when the deployment happens to a non-production environment" do it "returns nil" do - issue = create(:issue, project: project) + issue = build(:issue, project: project) merge_request = create_merge_request_closing_issue(user, project, issue) MergeRequests::MergeService.new(project, user).execute(merge_request) deploy_master(user, project, environment: 'staging') diff --git a/spec/models/cycle_analytics/project_level_spec.rb b/spec/models/cycle_analytics/project_level_spec.rb index 351eb139416..2fc81777746 100644 --- a/spec/models/cycle_analytics/project_level_spec.rb +++ b/spec/models/cycle_analytics/project_level_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe CycleAnalytics::ProjectLevel do - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } - let(:issue) { create(:issue, project: project, created_at: 2.days.ago) } - let(:milestone) { create(:milestone, project: project) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:issue) { create(:issue, project: project, created_at: 2.days.ago) } + let_it_be(:milestone) { create(:milestone, project: project) } let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") } let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) } diff --git a/spec/models/cycle_analytics/review_spec.rb b/spec/models/cycle_analytics/review_spec.rb index ef88fd86340..50670188e85 100644 --- a/spec/models/cycle_analytics/review_spec.rb +++ b/spec/models/cycle_analytics/review_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe 'CycleAnalytics#review' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } diff --git a/spec/models/cycle_analytics/staging_spec.rb b/spec/models/cycle_analytics/staging_spec.rb index 571792559d8..cf0695f175a 100644 --- a/spec/models/cycle_analytics/staging_spec.rb +++ b/spec/models/cycle_analytics/staging_spec.rb @@ -5,11 +5,12 @@ require 'spec_helper' describe 'CycleAnalytics#staging' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } generate_cycle_analytics_spec( phase: :staging, @@ -28,14 +29,7 @@ describe 'CycleAnalytics#staging' do ["production deploy happens after merge request is merged (along with other changes)", lambda do |context, data| # Make other changes on master - sha = context.project.repository.create_file( - context.user, - context.generate(:branch), - 'content', - message: 'commit message', - branch_name: 'master') - context.project.repository.commit(sha) - + context.project.repository.commit("this_sha_apparently_does_not_matter") context.deploy_master(context.user, context.project) end]]) diff --git a/spec/models/cycle_analytics/test_spec.rb b/spec/models/cycle_analytics/test_spec.rb index 7b3001d2bd8..24800aafca7 100644 --- a/spec/models/cycle_analytics/test_spec.rb +++ b/spec/models/cycle_analytics/test_spec.rb @@ -5,16 +5,19 @@ require 'spec_helper' describe 'CycleAnalytics#test' do extend CycleAnalyticsHelpers::TestGeneration - let(:project) { create(:project, :repository) } - let(:from_date) { 10.days.ago } - let(:user) { create(:user, :admin) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:from_date) { 10.days.ago } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + let!(:merge_request) { create_merge_request_closing_issue(user, project, issue) } - subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) } + subject { project_level } generate_cycle_analytics_spec( phase: :test, data_fn: lambda do |context| - issue = context.create(:issue, project: context.project) + issue = context.issue merge_request = context.create_merge_request_closing_issue(context.user, context.project, issue) pipeline = context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project, head_pipeline_of: merge_request) { pipeline: pipeline, issue: issue } @@ -22,20 +25,15 @@ describe 'CycleAnalytics#test' do start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]], end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]], post_fn: -> (context, data) do - context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue]) end) context "when the pipeline is for a regular merge request (that doesn't close an issue)" do it "returns nil" do - issue = create(:issue, project: project) - merge_request = create_merge_request_closing_issue(user, project, issue) pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha) pipeline.run! pipeline.succeed! - merge_merge_requests_closing_issue(user, project, issue) - expect(subject[:test].project_median).to be_nil end end @@ -53,30 +51,22 @@ describe 'CycleAnalytics#test' do context "when the pipeline is dropped (failed)" do it "returns nil" do - issue = create(:issue, project: project) - merge_request = create_merge_request_closing_issue(user, project, issue) pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha) pipeline.run! pipeline.drop! - merge_merge_requests_closing_issue(user, project, issue) - expect(subject[:test].project_median).to be_nil end end context "when the pipeline is cancelled" do it "returns nil" do - issue = create(:issue, project: project) - merge_request = create_merge_request_closing_issue(user, project, issue) pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha) pipeline.run! pipeline.cancel! - merge_merge_requests_closing_issue(user, project, issue) - expect(subject[:test].project_median).to be_nil end end |