Commit 02db31b71d72b74bf5718483efcb5da5e0d1e4b3

Authored by Arthur Neves
1 parent 242fd923
Exists in master and in 1 other branch production

Fix problem_controller and spec

app/controllers/problems_controller.rb
... ... @@ -64,9 +64,9 @@ class ProblemsController < ApplicationController
64 64 def create_issue
65 65 body = "" # TODO render_issue_body
66 66 title = "" # TODO generate_title
67   - issue = Issue.new(problem: problem, user: current_user, title: title, body: body)
  67 + issue = Issue.new(issue_tracker: problem.app.issue_tracker, user: current_user, title: title, body: body)
68 68 unless issue.save
69   - flash[:error] = issue_creation.errors.full_messages.join(', ')
  69 + flash[:error] = issue.errors.full_messages.join(', ')
70 70 end
71 71  
72 72 redirect_to app_problem_path(app, problem)
... ...
spec/controllers/problems_controller_spec.rb
... ... @@ -263,39 +263,33 @@ describe ProblemsController do
263 263 end
264 264  
265 265 context "successful issue creation" do
266   - context "lighthouseapp tracker" do
267   - let(:notice) { Fabricate :notice }
268   - let(:problem) { notice.problem }
  266 + let(:notice) { Fabricate :notice }
  267 + let(:problem) { notice.problem }
  268 + let(:issue_tracker) { Fabricate(:issue_tracker) }
269 269  
270   - before(:each) do
271   - controller.stub(:problem).and_return(problem)
272   - controller.stub(:current_user).and_return(admin)
273   - IssueCreation.should_receive(:new).with(problem, admin, nil, request).and_return(double(:execute => true))
274   - post :create_issue, :app_id => problem.app.id, :id => problem.id
275   - end
  270 + before do
  271 + problem.app.issue_tracker = issue_tracker
  272 + problem.app.save!
  273 + controller.stub(:current_user).and_return(admin)
  274 + post :create_issue, app_id: problem.app.id, id: problem.id
  275 + end
276 276  
277   - it "should redirect to problem page" do
278   - expect(response).to redirect_to( app_problem_path(problem.app, problem) )
279   - expect(flash[:error]).to be_blank
280   - end
  277 + it "should redirect to problem page" do
  278 + expect(response).to redirect_to( app_problem_path(problem.app, problem) )
  279 + expect(flash[:error]).to be_blank
281 280 end
282 281 end
283 282  
284 283 context "error during request to a tracker" do
285   - before(:each) do
286   - IssueCreation.should_receive(:new).with(problem, admin, nil, request).and_return(
287   - double(:execute => false, :errors => double(:full_messages => ['not create']))
288   - )
289   - controller.stub(:problem).and_return(problem)
290   - post :create_issue, :app_id => problem.app.id, :id => problem.id
  284 + before do
  285 + post :create_issue, app_id: problem.app.id, id: problem.id
291 286 end
292 287  
293 288 it "should redirect to problem page" do
294 289 expect(response).to redirect_to( app_problem_path(problem.app, problem) )
295   - expect(flash[:error]).to eql 'not create'
  290 + expect(flash[:error]).to eql "This app has no issue tracker setup."
296 291 end
297 292 end
298   -
299 293 end
300 294  
301 295 describe "DELETE /apps/:app_id/problems/:id/unlink_issue" do
... ...