@@ -62,12 +62,14 class WatchersController < ApplicationController | |||||
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def destroy |
|
64 | def destroy | |
65 |
@watched.set_watcher(User |
|
65 | @watched.set_watcher(User.find(params[:user_id]), false) | |
66 | respond_to do |format| |
|
66 | respond_to do |format| | |
67 | format.html { redirect_to :back } |
|
67 | format.html { redirect_to :back } | |
68 | format.js |
|
68 | format.js | |
69 | format.api { render_api_ok } |
|
69 | format.api { render_api_ok } | |
70 | end |
|
70 | end | |
|
71 | rescue ActiveRecord::RecordNotFound | |||
|
72 | render_404 | |||
71 | end |
|
73 | end | |
72 |
|
74 | |||
73 | def autocomplete_for_user |
|
75 | def autocomplete_for_user |
@@ -259,7 +259,7 class WatchersControllerTest < ActionController::TestCase | |||||
259 | assert response.body.blank? |
|
259 | assert response.body.blank? | |
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 |
def test_ |
|
262 | def test_destroy | |
263 | @request.session[:user_id] = 2 |
|
263 | @request.session[:user_id] = 2 | |
264 | assert_difference('Watcher.count', -1) do |
|
264 | assert_difference('Watcher.count', -1) do | |
265 | xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
|
265 | xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
@@ -268,4 +268,26 class WatchersControllerTest < ActionController::TestCase | |||||
268 | end |
|
268 | end | |
269 | assert !Issue.find(2).watched_by?(User.find(3)) |
|
269 | assert !Issue.find(2).watched_by?(User.find(3)) | |
270 | end |
|
270 | end | |
|
271 | ||||
|
272 | def test_destroy_locked_user | |||
|
273 | user = User.find(3) | |||
|
274 | user.lock! | |||
|
275 | assert user.reload.locked? | |||
|
276 | ||||
|
277 | @request.session[:user_id] = 2 | |||
|
278 | assert_difference('Watcher.count', -1) do | |||
|
279 | xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |||
|
280 | assert_response :success | |||
|
281 | assert_match /watchers/, response.body | |||
|
282 | end | |||
|
283 | assert !Issue.find(2).watched_by?(User.find(3)) | |||
|
284 | end | |||
|
285 | ||||
|
286 | def test_destroy_invalid_user_should_respond_with_404 | |||
|
287 | @request.session[:user_id] = 2 | |||
|
288 | assert_no_difference('Watcher.count') do | |||
|
289 | delete :destroy, :object_type => 'issue', :object_id => '2', :user_id => '999' | |||
|
290 | assert_response 404 | |||
|
291 | end | |||
|
292 | end | |||
271 | end |
|
293 | end |
General Comments 0
You need to be logged in to leave comments.
Login now