Commit eaaa3696d6620e5c105b2f629ddb1de7499d0845
1 parent
37be920a
Exists in
master
and in
1 other branch
Add more tests to create_issue action
Showing
2 changed files
with
27 additions
and
12 deletions
Show diff stats
spec/controllers/problems_controller_spec.rb
... | ... | @@ -257,35 +257,50 @@ describe ProblemsController do |
257 | 257 | end |
258 | 258 | |
259 | 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 | 263 | let(:notice) { Fabricate :notice } |
267 | 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 | 271 | before do |
271 | 272 | problem.app.issue_tracker = issue_tracker |
272 | - problem.app.save! | |
273 | + controller.stub(:problem).and_return(problem) | |
273 | 274 | controller.stub(:current_user).and_return(admin) |
274 | - post :create_issue, app_id: problem.app.id, id: problem.id | |
275 | 275 | end |
276 | 276 | |
277 | 277 | it "should redirect to problem page" do |
278 | + post :create_issue, app_id: problem.app.id, id: problem.id | |
278 | 279 | expect(response).to redirect_to(app_problem_path(problem.app, problem)) |
279 | 280 | expect(flash[:error]).to be_blank |
280 | 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 | 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 | 298 | end |
299 | + end | |
287 | 300 | |
301 | + context "when app has no issue tracker" do | |
288 | 302 | it "should redirect to problem page" do |
303 | + post :create_issue, app_id: problem.app.id, id: problem.id | |
289 | 304 | expect(response).to redirect_to( app_problem_path(problem.app, problem) ) |
290 | 305 | expect(flash[:error]).to eql "This app has no issue tracker setup." |
291 | 306 | end | ... | ... |