Commit b973fc4a authored by Marin Jankovski's avatar Marin Jankovski

Add note cross reference specs, remove repetition.

parent a7ae2679
......@@ -57,7 +57,7 @@ class JiraService < IssueTrackerService
def create_cross_reference_note(mentioned, noteable, author)
issue_name = mentioned.id
project = self.project
noteable_name = noteable.class.name.downcase.to_sym
noteable_name = noteable.class.name.underscore.downcase.to_sym
noteable_id = if noteable.is_a?(Commit)
noteable.id
else
......@@ -161,7 +161,7 @@ class JiraService < IssueTrackerService
"#{self.class.name} ERROR: #{result}. Hostname: #{url}."
else
case result.code
when 201
when 201, 200
"#{self.class.name} SUCCESS 201: Sucessfully posted to #{url}."
when 401
"#{self.class.name} ERROR 401: Unauthorized. Check the #{self.username} credentials and JIRA access permissions and try again."
......@@ -170,8 +170,8 @@ class JiraService < IssueTrackerService
end
end
Rails.logger.info(message)
message
Rails.logger.info(message)
message
end
def server_url
......
......@@ -209,26 +209,80 @@ describe Note do
let(:issue) { create(:issue, project: project) }
let(:mergereq) { create(:merge_request, :simple, target_project: project, source_project: project) }
let(:commit) { project.repository.commit }
let(:jira_issue) { JiraIssue.new("JIRA-1", project)}
let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? }
let(:api_mention_url) { 'http://jira.example/rest/api/2/issue/JIRA-1/comment' }
# Test all of {issue, merge request, commit} in both the referenced and referencing
# roles, to ensure that the correct information can be inferred from any argument.
context 'issue from a merge request' do
subject { Note.create_cross_reference_note(issue, mergereq, author, project) }
context 'in default issue tracker' do
subject { Note.create_cross_reference_note(issue, mergereq, author, project) }
it { should be_valid }
its(:noteable) { should == issue }
its(:project) { should == issue.project }
its(:author) { should == author }
its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
end
it { should be_valid }
its(:noteable) { should == issue }
its(:project) { should == issue.project }
its(:author) { should == author }
its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
context 'in JIRA issue tracker' do
before do
jira_service_settings
WebMock.stub_request(:post, api_mention_url)
end
after do
jira_tracker.destroy!
end
subject { Note.create_cross_reference_note(jira_issue, mergereq, author, project) }
it { should == jira_status_message }
end
end
context 'issue from a commit' do
subject { Note.create_cross_reference_note(issue, commit, author, project) }
context 'in default issue tracker' do
subject { Note.create_cross_reference_note(issue, commit, author, project) }
it { should be_valid }
its(:noteable) { should == issue }
its(:note) { should == "_mentioned in commit #{commit.sha}_" }
it { should be_valid }
its(:noteable) { should == issue }
its(:note) { should == "_mentioned in commit #{commit.sha}_" }
end
context 'in JIRA issue tracker' do
before do
jira_service_settings
WebMock.stub_request(:post, api_mention_url)
end
after do
jira_tracker.destroy!
end
subject { Note.create_cross_reference_note(jira_issue, commit, author, project) }
it { should == jira_status_message }
end
end
context 'issue from an isue' do
context 'in JIRA issue tracker' do
before do
jira_service_settings
WebMock.stub_request(:post, api_mention_url)
end
after do
jira_tracker.destroy!
end
subject { Note.create_cross_reference_note(jira_issue, issue, author, project) }
it { should == jira_status_message }
end
end
context 'merge request from an issue' do
......@@ -386,4 +440,19 @@ describe Note do
let(:backref_text) { issue.gfm_reference }
let(:set_mentionable_text) { ->(txt) { subject.note = txt } }
end
def jira_service_settings
properties = {
"title"=>"JIRA tracker",
"project_url"=>"http://jira.example/issues/?jql=project=A",
"issues_url"=>"http://jira.example/browse/JIRA-1",
"new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa"
}
jira_tracker.update_attributes(properties: properties, active: true)
end
def jira_status_message
"JiraService SUCCESS 201: Sucessfully posted to #{api_mention_url}."
end
end
......@@ -270,15 +270,15 @@ describe GitPushService do
it "should initiate one api call to jira server to close the issue" do
message = {
'update' => {
'comment' => [{
'add' => {
'body' => "Issue solved with http://localhost/#{project.path_with_namespace}/commit/#{closing_commit.id}"
update: {
comment: [{
add: {
body: "Issue solved with http://localhost/#{project.path_with_namespace}/commit/#{closing_commit.id}"
}
}]
},
'transition' => {
'id' => '2'
transition: {
id: '2'
}
}.to_json
......
......@@ -96,4 +96,13 @@ eos
commits: commits
)
end
def jira_properties
{
"title"=>"JIRA tracker",
"project_url"=>"http://jira.example/issues/?jql=project=A",
"issues_url"=>"http://jira.example/browse/JIRA-1",
"new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa"
}
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment