Use POST/DELETE to watch/unwatch an item.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11343 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
75129aaa1b
commit
deffd81ada
|
@ -31,14 +31,13 @@ module WatchersHelper
|
||||||
watched = objects.any? {|object| object.watched_by?(user)}
|
watched = objects.any? {|object| object.watched_by?(user)}
|
||||||
css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
|
css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
|
||||||
text = watched ? l(:button_unwatch) : l(:button_watch)
|
text = watched ? l(:button_unwatch) : l(:button_watch)
|
||||||
url = {
|
url = watch_path(
|
||||||
:controller => 'watchers',
|
|
||||||
:action => (watched ? 'unwatch' : 'watch'),
|
|
||||||
:object_type => objects.first.class.to_s.underscore,
|
:object_type => objects.first.class.to_s.underscore,
|
||||||
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
||||||
}
|
)
|
||||||
|
method = watched ? 'delete' : 'post'
|
||||||
|
|
||||||
link_to text, url, :remote => true, :method => 'post', :class => css
|
link_to text, url, :remote => true, :method => method, :class => css
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the css class used to identify watch links for a given +object+
|
# Returns the css class used to identify watch links for a given +object+
|
||||||
|
|
|
@ -77,12 +77,12 @@ RedmineApp::Application.routes.draw do
|
||||||
match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete
|
match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete
|
||||||
match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships'
|
match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships'
|
||||||
|
|
||||||
|
post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
|
||||||
|
delete 'watchers/watch', :to => 'watchers#unwatch'
|
||||||
get 'watchers/new', :to => 'watchers#new'
|
get 'watchers/new', :to => 'watchers#new'
|
||||||
post 'watchers', :to => 'watchers#create'
|
post 'watchers', :to => 'watchers#create'
|
||||||
post 'watchers/append', :to => 'watchers#append'
|
post 'watchers/append', :to => 'watchers#append'
|
||||||
post 'watchers/destroy', :to => 'watchers#destroy'
|
post 'watchers/destroy', :to => 'watchers#destroy'
|
||||||
post 'watchers/watch', :to => 'watchers#watch'
|
|
||||||
post 'watchers/unwatch', :to => 'watchers#unwatch'
|
|
||||||
get 'watchers/autocomplete_for_user', :to => 'watchers#autocomplete_for_user'
|
get 'watchers/autocomplete_for_user', :to => 'watchers#autocomplete_for_user'
|
||||||
# Specific routes for issue watchers API
|
# Specific routes for issue watchers API
|
||||||
post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
|
post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
|
||||||
|
|
|
@ -84,7 +84,7 @@ class WatchersControllerTest < ActionController::TestCase
|
||||||
def test_unwatch
|
def test_unwatch
|
||||||
@request.session[:user_id] = 3
|
@request.session[:user_id] = 3
|
||||||
assert_difference('Watcher.count', -1) do
|
assert_difference('Watcher.count', -1) do
|
||||||
xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
|
xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_include '$(".issue-2-watcher")', response.body
|
assert_include '$(".issue-2-watcher")', response.body
|
||||||
end
|
end
|
||||||
|
@ -97,7 +97,7 @@ class WatchersControllerTest < ActionController::TestCase
|
||||||
Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
|
Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
|
||||||
|
|
||||||
assert_difference('Watcher.count', -2) do
|
assert_difference('Watcher.count', -2) do
|
||||||
xhr :post, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
|
xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_include '$(".issue-bulk-watcher")', response.body
|
assert_include '$(".issue-bulk-watcher")', response.body
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ class RoutingWatchersTest < ActionController::IntegrationTest
|
||||||
{ :controller => 'watchers', :action => 'watch' }
|
{ :controller => 'watchers', :action => 'watch' }
|
||||||
)
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :method => 'post', :path => "/watchers/unwatch" },
|
{ :method => 'delete', :path => "/watchers/watch" },
|
||||||
{ :controller => 'watchers', :action => 'unwatch' }
|
{ :controller => 'watchers', :action => 'unwatch' }
|
||||||
)
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
|
|
Loading…
Reference in New Issue