diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index a5054c4..855e5eb 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -64,9 +64,9 @@ class ProblemsController < ApplicationController def create_issue body = "" # TODO render_issue_body title = "" # TODO generate_title - issue = Issue.new(problem: problem, user: current_user, title: title, body: body) + issue = Issue.new(issue_tracker: problem.app.issue_tracker, user: current_user, title: title, body: body) unless issue.save - flash[:error] = issue_creation.errors.full_messages.join(', ') + flash[:error] = issue.errors.full_messages.join(', ') end redirect_to app_problem_path(app, problem) diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index 11e4128..968ebe2 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -263,39 +263,33 @@ describe ProblemsController do end context "successful issue creation" do - context "lighthouseapp tracker" do - let(:notice) { Fabricate :notice } - let(:problem) { notice.problem } + let(:notice) { Fabricate :notice } + let(:problem) { notice.problem } + let(:issue_tracker) { Fabricate(:issue_tracker) } - before(:each) do - controller.stub(:problem).and_return(problem) - controller.stub(:current_user).and_return(admin) - IssueCreation.should_receive(:new).with(problem, admin, nil, request).and_return(double(:execute => true)) - post :create_issue, :app_id => problem.app.id, :id => problem.id - end + before do + problem.app.issue_tracker = issue_tracker + problem.app.save! + controller.stub(:current_user).and_return(admin) + post :create_issue, app_id: problem.app.id, id: problem.id + end - it "should redirect to problem page" do - expect(response).to redirect_to( app_problem_path(problem.app, problem) ) - expect(flash[:error]).to be_blank - end + it "should redirect to problem page" do + expect(response).to redirect_to( app_problem_path(problem.app, problem) ) + expect(flash[:error]).to be_blank end end context "error during request to a tracker" do - before(:each) do - IssueCreation.should_receive(:new).with(problem, admin, nil, request).and_return( - double(:execute => false, :errors => double(:full_messages => ['not create'])) - ) - controller.stub(:problem).and_return(problem) - post :create_issue, :app_id => problem.app.id, :id => problem.id + before do + post :create_issue, app_id: problem.app.id, id: problem.id end it "should redirect to problem page" do expect(response).to redirect_to( app_problem_path(problem.app, problem) ) - expect(flash[:error]).to eql 'not create' + expect(flash[:error]).to eql "This app has no issue tracker setup." end end - end describe "DELETE /apps/:app_id/problems/:id/unlink_issue" do -- libgit2 0.21.2