Commit eaaa3696d6620e5c105b2f629ddb1de7499d0845

Authored by Arthur Neves
1 parent 37be920a
Exists in master and in 1 other branch production

Add more tests to create_issue action

spec/controllers/problems_controller_spec.rb
@@ -257,35 +257,50 @@ describe ProblemsController do @@ -257,35 +257,50 @@ describe ProblemsController do
257 end 257 end
258 258
259 describe "POST /apps/:app_id/problems/:id/create_issue" do 259 describe "POST /apps/:app_id/problems/:id/create_issue" do
  260 + before { sign_in admin }
260 261
261 - before(:each) do  
262 - sign_in admin  
263 - end  
264 -  
265 - context "successful issue creation" do 262 + context "when app has a issue tracker" do
266 let(:notice) { Fabricate :notice } 263 let(:notice) { Fabricate :notice }
267 let(:problem) { notice.problem } 264 let(:problem) { notice.problem }
268 - let(:issue_tracker) { Fabricate(:issue_tracker) } 265 + let(:issue_tracker) do
  266 + Fabricate(:issue_tracker).tap do |t|
  267 + t.instance_variable_set(:@tracker, ErrbitPlugin::MockIssueTracker.new(t.options))
  268 + end
  269 + end
269 270
270 before do 271 before do
271 problem.app.issue_tracker = issue_tracker 272 problem.app.issue_tracker = issue_tracker
272 - problem.app.save! 273 + controller.stub(:problem).and_return(problem)
273 controller.stub(:current_user).and_return(admin) 274 controller.stub(:current_user).and_return(admin)
274 - post :create_issue, app_id: problem.app.id, id: problem.id  
275 end 275 end
276 276
277 it "should redirect to problem page" do 277 it "should redirect to problem page" do
  278 + post :create_issue, app_id: problem.app.id, id: problem.id
278 expect(response).to redirect_to(app_problem_path(problem.app, problem)) 279 expect(response).to redirect_to(app_problem_path(problem.app, problem))
279 expect(flash[:error]).to be_blank 280 expect(flash[:error]).to be_blank
280 end 281 end
281 - end  
282 282
283 - context "error during request to a tracker" do  
284 - before do 283 + it "should save the right title" do
  284 + post :create_issue, app_id: problem.app.id, id: problem.id
  285 + title = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"
  286 + line = issue_tracker.tracker.output.shift
  287 + expect(line[0]).to eq(title)
  288 + end
  289 +
  290 + it "should save the right body" do
  291 + pending
  292 + end
  293 +
  294 + it "should update the problem" do
285 post :create_issue, app_id: problem.app.id, id: problem.id 295 post :create_issue, app_id: problem.app.id, id: problem.id
  296 + expect(problem.issue_link).to eq("http://example.com/mock-errbit")
  297 + expect(problem.issue_type).to eq("mock")
286 end 298 end
  299 + end
287 300
  301 + context "when app has no issue tracker" do
288 it "should redirect to problem page" do 302 it "should redirect to problem page" do
  303 + post :create_issue, app_id: problem.app.id, id: problem.id
289 expect(response).to redirect_to( app_problem_path(problem.app, problem) ) 304 expect(response).to redirect_to( app_problem_path(problem.app, problem) )
290 expect(flash[:error]).to eql "This app has no issue tracker setup." 305 expect(flash[:error]).to eql "This app has no issue tracker setup."
291 end 306 end
spec/errbit_plugin/mock_issue_tracker.rb
@@ -35,7 +35,7 @@ module ErrbitPlugin @@ -35,7 +35,7 @@ module ErrbitPlugin
35 35
36 def create_issue(title, body, user) 36 def create_issue(title, body, user)
37 @output << [title, body, user] 37 @output << [title, body, user]
38 - true 38 + "http://example.com/mock-errbit"
39 end 39 end
40 40
41 def url; ''; end 41 def url; ''; end