Commit 3484c2429e2cf32fb9193fb3051a0e76905f49c9

Authored by Nick Recobra
1 parent d55b0776
Exists in master and in 1 other branch production

Using /issues.xml for Redmine issue creation. Overriding RedmineClient::Base.site on every request.

app/controllers/errs_controller.rb
... ... @@ -36,7 +36,8 @@ class ErrsController < ApplicationController
36 36 flash[:error] = "This up has no issue tracker setup."
37 37 end
38 38 redirect_to app_err_path(@app, @err)
39   - rescue ActiveResource::ConnectionError
  39 + rescue ActiveResource::ConnectionError => e
  40 + Rails.logger.error e.to_s
40 41 flash[:error] = "There was an error during issue creation. Check your tracker settings or try again later."
41 42 redirect_to app_err_path(@app, @err)
42 43 end
... ...
app/models/issue_tracker.rb
... ... @@ -22,15 +22,16 @@ class IssueTracker
22 22 protected
23 23 def create_redmine_issue err
24 24 token = api_token
  25 + acc = account
25 26 RedmineClient::Base.configure do
26 27 self.token = token
  28 + self.site = acc
27 29 end
28   - RedmineClient::Issue.site = account + "/projects/:project_id"
29 30 issue = RedmineClient::Issue.new(:project_id => project_id)
30 31 issue.subject = issue_title err
31 32 issue.description = self.class.redmine_body_template.result(binding)
32 33 issue.save!
33   - err.update_attribute :issue_link, "#{RedmineClient::Issue.site.to_s.sub(/#{RedmineClient::Issue.site.path}$/, '')}#{RedmineClient::Issue.element_path(issue.id, :project_id => project_id)}".sub(/\.xml$/, '')
  34 + err.update_attribute :issue_link, "#{RedmineClient::Issue.site.to_s.sub(/#{RedmineClient::Issue.site.path}$/, '')}#{RedmineClient::Issue.element_path(issue.id, :project_id => project_id)}".sub(/\.xml\?project_id=#{project_id}$/, "\?project_id=#{project_id}")
34 35 end
35 36  
36 37 def create_lighthouseapp_issue err
... ...
spec/controllers/errs_controller_spec.rb
... ... @@ -261,17 +261,18 @@ describe ErrsController do
261 261  
262 262 before(:each) do
263 263 number = 5
264   - @issue_link = "#{tracker.account}/projects/#{tracker.project_id}/issues/#{number}.xml"
265   - body = "<issue><id type=\"integer\">#{number}</id></issue>"
266   - stub_request(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body )
  264 + @issue_link = "#{tracker.account}/issues/#{number}.xml?project_id=#{tracker.project_id}"
  265 + body = "<issue><subject>my subject</subject><id>#{number}</id></issue>"
  266 + stub_request(:post, "#{tracker.account}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body )
267 267  
268 268 post :create_issue, :app_id => err.app.id, :id => err.id
269 269 err.reload
270 270 end
271 271  
272 272 it "should make request to Redmine with err params" do
273   - requested = have_requested(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml")
  273 + requested = have_requested(:post, "#{tracker.account}/issues.xml")
274 274 WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token})
  275 + WebMock.should requested.with(:body => /<project-id>#{tracker.project_id}<\/project-id>/)
275 276 WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/)
276 277 WebMock.should requested.with(:body => /<description>.+<\/description>/m)
277 278 end
... ... @@ -281,7 +282,7 @@ describe ErrsController do
281 282 end
282 283  
283 284 it "should create issue link for err" do
284   - err.issue_link.should == @issue_link.sub(/\.xml$/, '')
  285 + err.issue_link.should == @issue_link.sub(/\.xml/, '')
285 286 end
286 287 end
287 288 end
... ...