From f77c952ae71ec03c9691e44479f0e4a7fc5ef8e8 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Wed, 7 Sep 2016 10:35:01 +0530 Subject: Test the `code` cycle analytics phase. - Move the "data belongs to other project" test case into the generated tests, and remove the explicit tests from the `code` and `plan` phases. --- spec/models/cycle_analytics/code_spec.rb | 46 +++++++++++++++++++++++++++++++ spec/models/cycle_analytics/issue_spec.rb | 13 --------- spec/models/cycle_analytics/plan_spec.rb | 12 -------- 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 spec/models/cycle_analytics/code_spec.rb (limited to 'spec/models/cycle_analytics') diff --git a/spec/models/cycle_analytics/code_spec.rb b/spec/models/cycle_analytics/code_spec.rb new file mode 100644 index 00000000000..1eaccb5e937 --- /dev/null +++ b/spec/models/cycle_analytics/code_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'CycleAnalytics#code', feature: true do + let(:project) { create(:project) } + let(:from_date) { 10.days.ago } + let(:user) { create(:user, :admin) } + subject { CycleAnalytics.new(project, from: from_date) } + + def create_commit_referencing_issue(issue) + sha = project.repository.commit_file(user, FFaker::Product.brand, "content", "Commit for ##{issue.iid}", "master", false) + commit = project.repository.commit(sha) + commit.create_cross_references!(user) + end + + def create_merge_request_closing_issue(issue, message: nil) + source_branch = FFaker::Product.brand + project.repository.add_branch(user, source_branch, 'master') + + opts = { + title: 'Awesome merge_request', + description: message || "Fixes #{issue.to_reference}", + source_branch: source_branch, + target_branch: 'master' + } + + MergeRequests::CreateService.new(project, user, opts).execute + end + + 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]) }]]) + + context "when a regular merge request (that doesn't close the issue) is created" do + it "returns nil" do + 5.times do + issue = create(:issue, project: project) + + create_commit_referencing_issue(issue) + create_merge_request_closing_issue(issue, message: "Closes nothing") + end + + expect(subject.code).to be_nil + end + end +end diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb index ef4de184d64..06715498d26 100644 --- a/spec/models/cycle_analytics/issue_spec.rb +++ b/spec/models/cycle_analytics/issue_spec.rb @@ -22,17 +22,4 @@ describe 'CycleAnalytics#issue', models: true do expect(subject.issue).to be_nil end end - - context "when the issue belongs to a different project" do - it 'returns nil' do - other_project = create(:project) - - 5.times do - issue = create(:issue, project: other_project) - issue.update(milestone: create(:milestone, project: other_project)) - end - - expect(subject.issue).to be_nil - end - end end diff --git a/spec/models/cycle_analytics/plan_spec.rb b/spec/models/cycle_analytics/plan_spec.rb index a5d4128d938..4cae87e9d89 100644 --- a/spec/models/cycle_analytics/plan_spec.rb +++ b/spec/models/cycle_analytics/plan_spec.rb @@ -28,16 +28,4 @@ describe 'CycleAnalytics#plan', feature: true do expect(subject.issue).to be_nil end end - - it "does not include issues from other projects" do - other_project = create(:project) - - list_label = create(:label, lists: [create(:list)]) - issue = create(:issue, project: other_project) - issue.update(milestone: create(:milestone)) - issue.update(label_ids: [list_label.id]) - create_commit_referencing_issue(issue) - - expect(subject.issue).to be_nil - end end -- cgit v1.2.3