diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 08:47:36 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 10:53:14 +0300 |
commit | d0e101e997347b0b52d4ef3a945a0f26571546a2 (patch) | |
tree | 684b05bbd6f507e7cb90d8fec98a49b56975ed35 /spec/models | |
parent | cebfe053a85c8e376b35101686ba05225c6f4e65 (diff) |
Fix all cycle analytics specs.
A number of failures were introduced due to performance
improvements (like pre-calculating metrics).
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/cycle_analytics/code_spec.rb | 9 | ||||
-rw-r--r-- | spec/models/cycle_analytics/issue_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/cycle_analytics/plan_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/cycle_analytics/review_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/cycle_analytics/test_spec.rb | 25 |
5 files changed, 61 insertions, 9 deletions
diff --git a/spec/models/cycle_analytics/code_spec.rb b/spec/models/cycle_analytics/code_spec.rb index 18dd4d0f1ab..e81c78df8f0 100644 --- a/spec/models/cycle_analytics/code_spec.rb +++ b/spec/models/cycle_analytics/code_spec.rb @@ -9,7 +9,11 @@ describe 'CycleAnalytics#code', feature: true do generate_cycle_analytics_spec(phase: :code, data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } }, start_time_conditions: [["issue mentioned in a commit", -> (context, data) { context.create_commit_referencing_issue(data[:issue]) }]], - end_time_conditions: [["merge request that closes issue is created", -> (context, data) { context.create_merge_request_closing_issue(data[:issue]) }]]) + end_time_conditions: [["merge request that closes issue is created", -> (context, data) { context.create_merge_request_closing_issue(data[:issue]) }]], + post_fn: -> (context, data) do + context.merge_merge_requests_closing_issue(data[:issue]) + context.deploy_master + end) context "when a regular merge request (that doesn't close the issue) is created" do it "returns nil" do @@ -18,6 +22,9 @@ describe 'CycleAnalytics#code', feature: true do create_commit_referencing_issue(issue) create_merge_request_closing_issue(issue, message: "Closes nothing") + + merge_merge_requests_closing_issue(issue) + deploy_master end expect(subject.code).to be_nil diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb index 06715498d26..8d7d03193f0 100644 --- a/spec/models/cycle_analytics/issue_spec.rb +++ b/spec/models/cycle_analytics/issue_spec.rb @@ -3,13 +3,21 @@ require 'spec_helper' describe 'CycleAnalytics#issue', models: true do let(:project) { create(:project) } let(:from_date) { 10.days.ago } + let(:user) { create(:user, :admin) } subject { CycleAnalytics.new(project, from: from_date) } generate_cycle_analytics_spec(phase: :issue, data_fn: -> (context) { { issue: context.build(:issue, project: context.project) } }, start_time_conditions: [["issue created", -> (context, data) { data[:issue].save }]], end_time_conditions: [["issue associated with a milestone", -> (context, data) { data[:issue].update(milestone: context.create(:milestone, project: context.project)) if data[:issue].persisted? }], - ["list label added to issue", -> (context, data) { data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id]) if data[:issue].persisted? }]]) + ["list label added to issue", -> (context, data) { data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id]) if data[:issue].persisted? }]], + post_fn: -> (context, data) do + if data[:issue].persisted? + context.create_merge_request_closing_issue(data[:issue].reload) + context.merge_merge_requests_closing_issue(data[:issue]) + context.deploy_master + end + end) context "when a regular label (instead of a list label) is added to the issue" do it "returns nil" do @@ -17,6 +25,10 @@ describe 'CycleAnalytics#issue', models: true do regular_label = create(:label) issue = create(:issue, project: project) issue.update(label_ids: [regular_label.id]) + + create_merge_request_closing_issue(issue) + merge_merge_requests_closing_issue(issue) + deploy_master end expect(subject.issue).to be_nil diff --git a/spec/models/cycle_analytics/plan_spec.rb b/spec/models/cycle_analytics/plan_spec.rb index fa092bf6825..aa779e5050f 100644 --- a/spec/models/cycle_analytics/plan_spec.rb +++ b/spec/models/cycle_analytics/plan_spec.rb @@ -7,17 +7,28 @@ describe 'CycleAnalytics#plan', feature: true do subject { CycleAnalytics.new(project, from: from_date) } generate_cycle_analytics_spec(phase: :plan, - data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } }, + data_fn: -> (context) { { issue: context.create(:issue, project: context.project), + branch_name: context.random_git_name } }, start_time_conditions: [["issue associated with a milestone", -> (context, data) { data[:issue].update(milestone: context.create(:milestone, project: context.project)) }], ["list label added to issue", -> (context, data) { data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id]) }]], - end_time_conditions: [["issue mentioned in a commit", -> (context, data) { context.create_commit_referencing_issue(data[:issue]) }]]) + end_time_conditions: [["issue mentioned in a commit", -> (context, data) { context.create_commit_referencing_issue(data[:issue], branch_name: data[:branch_name]) }]], + post_fn: -> (context, data) do + context.create_merge_request_closing_issue(data[:issue], source_branch: data[:branch_name]) + context.merge_merge_requests_closing_issue(data[:issue]) + context.deploy_master + end) context "when a regular label (instead of a list label) is added to the issue" do it "returns nil" do + branch_name = random_git_name label = create(:label) issue = create(:issue, project: project) issue.update(label_ids: [label.id]) - create_commit_referencing_issue(issue) + create_commit_referencing_issue(issue, branch_name: branch_name) + + create_merge_request_closing_issue(issue, source_branch: branch_name) + merge_merge_requests_closing_issue(issue) + deploy_master expect(subject.issue).to be_nil end diff --git a/spec/models/cycle_analytics/review_spec.rb b/spec/models/cycle_analytics/review_spec.rb index 867a90d6258..100ce11299a 100644 --- a/spec/models/cycle_analytics/review_spec.rb +++ b/spec/models/cycle_analytics/review_spec.rb @@ -9,12 +9,15 @@ describe 'CycleAnalytics#review', feature: true do generate_cycle_analytics_spec(phase: :review, data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } }, start_time_conditions: [["merge request that closes issue is created", -> (context, data) { context.create_merge_request_closing_issue(data[:issue]) }]], - end_time_conditions: [["merge request that closes issue is merged", -> (context, data) { context.merge_merge_requests_closing_issue(data[:issue]) }]]) + end_time_conditions: [["merge request that closes issue is merged", -> (context, data) { context.merge_merge_requests_closing_issue(data[:issue]) }]], + post_fn: -> (context, data) { context.deploy_master }) context "when a regular merge request (that doesn't close the issue) is created and merged" do it "returns nil" do 5.times do MergeRequests::MergeService.new(project, user).execute(create(:merge_request)) + + deploy_master end expect(subject.review).to be_nil diff --git a/spec/models/cycle_analytics/test_spec.rb b/spec/models/cycle_analytics/test_spec.rb index aa7faa74d38..79edc29c173 100644 --- a/spec/models/cycle_analytics/test_spec.rb +++ b/spec/models/cycle_analytics/test_spec.rb @@ -10,19 +10,30 @@ describe 'CycleAnalytics#test', feature: true do data_fn: lambda do |context| issue = context.create(:issue, project: context.project) merge_request = context.create_merge_request_closing_issue(issue) - { pipeline: context.create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha) } + { + pipeline: context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project), + issue: issue + } end, start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]], - end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]]) + end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]], + post_fn: -> (context, data) do + context.merge_merge_requests_closing_issue(data[:issue]) + context.deploy_master + end) context "when the pipeline is for a regular merge request (that doesn't close an issue)" do it "returns nil" do 5.times do - merge_request = create(:merge_request) + issue = create(:issue, project: project) + merge_request = create_merge_request_closing_issue(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(issue) + deploy_master end expect(subject.test).to be_nil @@ -36,6 +47,8 @@ describe 'CycleAnalytics#test', feature: true do pipeline.run! pipeline.succeed! + + deploy_master end expect(subject.test).to be_nil @@ -51,6 +64,9 @@ describe 'CycleAnalytics#test', feature: true do pipeline.run! pipeline.drop! + + merge_merge_requests_closing_issue(issue) + deploy_master end expect(subject.test).to be_nil @@ -66,6 +82,9 @@ describe 'CycleAnalytics#test', feature: true do pipeline.run! pipeline.cancel! + + merge_merge_requests_closing_issue(issue) + deploy_master end expect(subject.test).to be_nil |