Commit 463c5a9bb2e0c54b5781de4d97105cfc84a4334e
1 parent
ae91fcb5
Exists in
master
support #371 close issue
Showing
7 changed files
with
70 additions
and
0 deletions
Show diff stats
app/controllers/problems_controller.rb
... | ... | @@ -54,6 +54,13 @@ class ProblemsController < ApplicationController |
54 | 54 | @comment = Comment.new |
55 | 55 | end |
56 | 56 | |
57 | + def close_issue | |
58 | + issue = Issue.new(problem: problem, user: current_user) | |
59 | + flash[:error] = issue.errors.full_messages.join(', ') unless issue.close | |
60 | + | |
61 | + redirect_to app_problem_path(app, problem) | |
62 | + end | |
63 | + | |
57 | 64 | def create_issue |
58 | 65 | issue = Issue.new(problem: problem, user: current_user) |
59 | 66 | issue.body = render_to_string(*issue.render_body_args) | ... | ... |
app/models/issue.rb
... | ... | @@ -26,6 +26,23 @@ class Issue |
26 | 26 | end |
27 | 27 | end |
28 | 28 | |
29 | + def close | |
30 | + errors.add :base, "This app has no issue tracker" unless issue_tracker | |
31 | + return false if errors.present? | |
32 | + | |
33 | + tracker.errors.each { |k, err| errors.add k, err } | |
34 | + return false if errors.present? | |
35 | + | |
36 | + if issue_tracker.respond_to? :close_issue | |
37 | + url = issue_tracker.close_issue(problem.issue_link, user: user.as_document) | |
38 | + end | |
39 | + | |
40 | + errors.empty? | |
41 | + rescue => ex | |
42 | + errors.add :base, "There was an error during issue closing: #{ex.message}" | |
43 | + false | |
44 | + end | |
45 | + | |
29 | 46 | def save |
30 | 47 | errors.add :base, "The issue has no body" unless body |
31 | 48 | errors.add :base, "This app has no issue tracker" unless issue_tracker | ... | ... |
app/models/issue_tracker.rb
app/views/problems/_issue_tracker_links.html.haml
... | ... | @@ -6,6 +6,11 @@ |
6 | 6 | %img.button-icon{"src" => tracker_type.icons[:create]} |
7 | 7 | = link_to 'go to issue', problem.issue_link, :class => "goto-issue" |
8 | 8 | = link_to 'unlink issue', unlink_issue_app_problem_path(app, problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue" |
9 | + - if tracker.tracker.respond_to? :close_issue | |
10 | + %span | |
11 | + = link_to close_issue_app_problem_path(app, problem), method: :post, :class => "close-issue" do | |
12 | + %img.button-icon{"src" => tracker_type.icons[:create]} | |
13 | + close issue | |
9 | 14 | - elsif problem.issue_link == "pending" |
10 | 15 | %span.disabled |
11 | 16 | %img.button-icon{"src" => tracker_type.icons[:inactive]} | ... | ... |
config/routes.rb
spec/controllers/problems_controller_spec.rb
... | ... | @@ -262,6 +262,40 @@ describe ProblemsController, type: 'controller' do |
262 | 262 | end |
263 | 263 | end |
264 | 264 | |
265 | + describe "POST /apps/:app_id/problems/:id/close_issue" do | |
266 | + before { sign_in user } | |
267 | + | |
268 | + context "when app has a issue tracker" do | |
269 | + let(:notice) { NoticeDecorator.new(Fabricate :notice) } | |
270 | + let(:problem) { ProblemDecorator.new(notice.problem) } | |
271 | + let(:issue_tracker) do | |
272 | + Fabricate(:issue_tracker).tap do |t| | |
273 | + t.instance_variable_set(:@tracker, ErrbitPlugin::MockIssueTracker.new(t.options)) | |
274 | + end | |
275 | + end | |
276 | + | |
277 | + before do | |
278 | + problem.app.issue_tracker = issue_tracker | |
279 | + allow(controller).to receive(:problem).and_return(problem) | |
280 | + allow(controller).to receive(:current_user).and_return(user) | |
281 | + end | |
282 | + | |
283 | + it "should redirect to problem page" do | |
284 | + post :close_issue, app_id: problem.app.id, id: problem.id | |
285 | + expect(response).to redirect_to(app_problem_path(problem.app, problem)) | |
286 | + expect(flash[:error]).to be_blank | |
287 | + end | |
288 | + end | |
289 | + | |
290 | + context "when app has no issue tracker" do | |
291 | + it "should redirect to problem page" do | |
292 | + post :close_issue, app_id: problem.app.id, id: problem.id | |
293 | + expect(response).to redirect_to(app_problem_path(problem.app, problem)) | |
294 | + expect(flash[:error]).to eql "This app has no issue tracker" | |
295 | + end | |
296 | + end | |
297 | + end | |
298 | + | |
265 | 299 | describe "DELETE /apps/:app_id/problems/:id/unlink_issue" do |
266 | 300 | before(:each) do |
267 | 301 | sign_in user | ... | ... |
spec/errbit_plugin/mock_issue_tracker.rb