Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-09-07 08:05:01 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-09-07 08:09:46 +0300
commitf77c952ae71ec03c9691e44479f0e4a7fc5ef8e8 (patch)
tree484d1a631a52ea9fc4d8930a1fd1794d98ad2e97 /spec/models/cycle_analytics
parent98c9d1207708cd7d9fc37167e65e8a26b668aaa7 (diff)
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.
Diffstat (limited to 'spec/models/cycle_analytics')
-rw-r--r--spec/models/cycle_analytics/code_spec.rb46
-rw-r--r--spec/models/cycle_analytics/issue_spec.rb13
-rw-r--r--spec/models/cycle_analytics/plan_spec.rb12
3 files changed, 46 insertions, 25 deletions
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