summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-03 18:03:34 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-03 18:03:34 +0200
commit16e1076e6f69626e1d8bf53f52dc67baee9fb51e (patch)
tree9d70ea74d4258cd332bed8071aa3f07d82d12b06
parente33ddfebf2248fe31bb27fe1d34048df97ed61b0 (diff)
downloadgitlab-ce-16e1076e6f69626e1d8bf53f52dc67baee9fb51e.tar.gz
Update tests.
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb62
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb40
2 files changed, 54 insertions, 48 deletions
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
index c96ee78e5fd..cb7b0fbb890 100644
--- a/spec/lib/gitlab/closing_issue_extractor_spec.rb
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -5,126 +5,128 @@ describe Gitlab::ClosingIssueExtractor do
let(:issue) { create(:issue, project: project) }
let(:iid1) { issue.iid }
- describe :closed_by_message_in_project do
+ subject { described_class.new(project, project.creator) }
+
+ describe "#closed_by_message" do
context 'with a single reference' do
it do
message = "Awesome commit (Closes ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (closes ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Closed ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "closed ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Closing ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "closing ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Close ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "close ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Fixes ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (fixes ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fixed ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fixed ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fixing ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fixing ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fix ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fix ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Resolves ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (resolves ##{iid1})"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolved ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolved ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolving ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolving ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolve ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolve ##{iid1}"
- expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ expect(subject.closed_by_message(message)).to eq([issue])
end
end
@@ -137,28 +139,28 @@ describe Gitlab::ClosingIssueExtractor do
it 'fetches issues in single line message' do
message = "Closes ##{iid1} and fix ##{iid2}"
- expect(subject.closed_by_message_in_project(message, project)).
+ expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
it 'fetches comma-separated issues references in single line message' do
message = "Closes ##{iid1}, closes ##{iid2}"
- expect(subject.closed_by_message_in_project(message, project)).
+ expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
it 'fetches comma-separated issues numbers in single line message' do
message = "Closes ##{iid1}, ##{iid2} and ##{iid3}"
- expect(subject.closed_by_message_in_project(message, project)).
+ expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue])
end
it 'fetches issues in multi-line message' do
message = "Awesome commit (closes ##{iid1})\nAlso fixes ##{iid2}"
- expect(subject.closed_by_message_in_project(message, project)).
+ expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
@@ -166,7 +168,7 @@ describe Gitlab::ClosingIssueExtractor do
message = "Awesome commit (closes ##{iid1})\n"\
"Also fixing issues ##{iid2}, ##{iid3} and #4"
- expect(subject.closed_by_message_in_project(message, project)).
+ expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue])
end
end
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 8ed4d5bc68f..c9fb62b61ae 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -2,48 +2,48 @@ require 'spec_helper'
describe Gitlab::ReferenceExtractor do
let(:project) { create(:project) }
- subject { Gitlab::ReferenceExtractor.new(project) }
+ subject { Gitlab::ReferenceExtractor.new(project, project.creator) }
it 'extracts username references' do
subject.analyze('this contains a @user reference')
- expect(subject.users).to eq([{ project: project, id: 'user' }])
+ expect(subject.references[:user]).to eq([[project, 'user']])
end
it 'extracts issue references' do
subject.analyze('this one talks about issue #1234')
- expect(subject.issues).to eq([{ project: project, id: '1234' }])
+ expect(subject.references[:issue]).to eq([[project, '1234']])
end
it 'extracts JIRA issue references' do
subject.analyze('this one talks about issue JIRA-1234')
- expect(subject.issues).to eq([{ project: project, id: 'JIRA-1234' }])
+ expect(subject.references[:issue]).to eq([[project, 'JIRA-1234']])
end
it 'extracts merge request references' do
subject.analyze("and here's !43, a merge request")
- expect(subject.merge_requests).to eq([{ project: project, id: '43' }])
+ expect(subject.references[:merge_request]).to eq([[project, '43']])
end
it 'extracts snippet ids' do
subject.analyze('snippets like $12 get extracted as well')
- expect(subject.snippets).to eq([{ project: project, id: '12' }])
+ expect(subject.references[:snippet]).to eq([[project, '12']])
end
it 'extracts commit shas' do
subject.analyze('commit shas 98cf0ae3 are pulled out as Strings')
- expect(subject.commits).to eq([{ project: project, id: '98cf0ae3' }])
+ expect(subject.references[:commit]).to eq([[project, '98cf0ae3']])
end
it 'extracts commit ranges' do
subject.analyze('here you go, a commit range: 98cf0ae3...98cf0ae4')
- expect(subject.commit_ranges).to eq([{ project: project, id: '98cf0ae3...98cf0ae4' }])
+ expect(subject.references[:commit_range]).to eq([[project, '98cf0ae3...98cf0ae4']])
end
it 'extracts multiple references and preserves their order' do
subject.analyze('@me and @you both care about this')
- expect(subject.users).to eq([
- { project: project, id: 'me' },
- { project: project, id: 'you' }
+ expect(subject.references[:user]).to eq([
+ [project, 'me'],
+ [project, 'you']
])
end
@@ -70,7 +70,7 @@ describe Gitlab::ReferenceExtractor do
it 'extracts issue references for invalid code blocks' do
subject.analyze('test: ```this one talks about issue #1234```')
- expect(subject.issues).to eq([{ project: project, id: '1234' }])
+ expect(subject.references[:issue]).to eq([[project, '1234']])
end
it 'handles all possible kinds of references' do
@@ -78,16 +78,16 @@ describe Gitlab::ReferenceExtractor do
expect(subject).to respond_to(*accessors)
end
- it 'accesses valid user objects on the project team' do
+ it 'accesses valid user objects' do
@u_foo = create(:user, username: 'foo')
@u_bar = create(:user, username: 'bar')
- create(:user, username: 'offteam')
+ @u_offteam = create(:user, username: 'offteam')
project.team << [@u_foo, :reporter]
project.team << [@u_bar, :guest]
subject.analyze('@foo, @baduser, @bar, and @offteam')
- expect(subject.users).to eq([@u_foo, @u_bar])
+ expect(subject.users).to eq([@u_foo, @u_bar, @u_offteam])
end
it 'accesses valid issue objects' do
@@ -139,11 +139,15 @@ describe Gitlab::ReferenceExtractor do
end
context 'with a project with an underscore' do
- let(:project) { create(:project, path: 'test_project') }
- let(:issue) { create(:issue, project: project) }
+ let(:other_project) { create(:project, path: 'test_project') }
+ let(:issue) { create(:issue, project: other_project) }
+
+ before do
+ other_project.team << [project.creator, :developer]
+ end
it 'handles project issue references' do
- subject.analyze("this refers issue #{project.path_with_namespace}##{issue.iid}")
+ subject.analyze("this refers issue #{other_project.path_with_namespace}##{issue.iid}")
extracted = subject.issues
expect(extracted.size).to eq(1)
expect(extracted).to eq([issue])