@@ -31,14 +31,13 module WatchersHelper | |||||
31 | watched = objects.any? {|object| object.watched_by?(user)} |
|
31 | watched = objects.any? {|object| object.watched_by?(user)} | |
32 | css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ') |
|
32 | css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ') | |
33 | text = watched ? l(:button_unwatch) : l(:button_watch) |
|
33 | text = watched ? l(:button_unwatch) : l(:button_watch) | |
34 |
url = |
|
34 | url = watch_path( | |
35 | :controller => 'watchers', |
|
|||
36 | :action => (watched ? 'unwatch' : 'watch'), |
|
|||
37 | :object_type => objects.first.class.to_s.underscore, |
|
35 | :object_type => objects.first.class.to_s.underscore, | |
38 | :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) |
|
36 | :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) | |
39 |
|
|
37 | ) | |
|
38 | method = watched ? 'delete' : 'post' | |||
40 |
|
39 | |||
41 |
link_to text, url, :remote => true, :method => |
|
40 | link_to text, url, :remote => true, :method => method, :class => css | |
42 | end |
|
41 | end | |
43 |
|
42 | |||
44 | # Returns the css class used to identify watch links for a given +object+ |
|
43 | # Returns the css class used to identify watch links for a given +object+ |
@@ -77,12 +77,12 RedmineApp::Application.routes.draw do | |||||
77 | match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete |
|
77 | match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete | |
78 | match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships' |
|
78 | match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships' | |
79 |
|
79 | |||
|
80 | post 'watchers/watch', :to => 'watchers#watch', :as => 'watch' | |||
|
81 | delete 'watchers/watch', :to => 'watchers#unwatch' | |||
80 | get 'watchers/new', :to => 'watchers#new' |
|
82 | get 'watchers/new', :to => 'watchers#new' | |
81 | post 'watchers', :to => 'watchers#create' |
|
83 | post 'watchers', :to => 'watchers#create' | |
82 | post 'watchers/append', :to => 'watchers#append' |
|
84 | post 'watchers/append', :to => 'watchers#append' | |
83 | post 'watchers/destroy', :to => 'watchers#destroy' |
|
85 | post 'watchers/destroy', :to => 'watchers#destroy' | |
84 | post 'watchers/watch', :to => 'watchers#watch' |
|
|||
85 | post 'watchers/unwatch', :to => 'watchers#unwatch' |
|
|||
86 | get 'watchers/autocomplete_for_user', :to => 'watchers#autocomplete_for_user' |
|
86 | get 'watchers/autocomplete_for_user', :to => 'watchers#autocomplete_for_user' | |
87 | # Specific routes for issue watchers API |
|
87 | # Specific routes for issue watchers API | |
88 | post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue' |
|
88 | post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue' |
@@ -84,7 +84,7 class WatchersControllerTest < ActionController::TestCase | |||||
84 | def test_unwatch |
|
84 | def test_unwatch | |
85 | @request.session[:user_id] = 3 |
|
85 | @request.session[:user_id] = 3 | |
86 | assert_difference('Watcher.count', -1) do |
|
86 | assert_difference('Watcher.count', -1) do | |
87 |
xhr : |
|
87 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2' | |
88 | assert_response :success |
|
88 | assert_response :success | |
89 | assert_include '$(".issue-2-watcher")', response.body |
|
89 | assert_include '$(".issue-2-watcher")', response.body | |
90 | end |
|
90 | end | |
@@ -97,7 +97,7 class WatchersControllerTest < ActionController::TestCase | |||||
97 | Watcher.create!(:user_id => 3, :watchable => Issue.find(3)) |
|
97 | Watcher.create!(:user_id => 3, :watchable => Issue.find(3)) | |
98 |
|
98 | |||
99 | assert_difference('Watcher.count', -2) do |
|
99 | assert_difference('Watcher.count', -2) do | |
100 |
xhr : |
|
100 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3'] | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_include '$(".issue-bulk-watcher")', response.body |
|
102 | assert_include '$(".issue-bulk-watcher")', response.body | |
103 | end |
|
103 | end |
@@ -44,7 +44,7 class RoutingWatchersTest < ActionController::IntegrationTest | |||||
44 | { :controller => 'watchers', :action => 'watch' } |
|
44 | { :controller => 'watchers', :action => 'watch' } | |
45 | ) |
|
45 | ) | |
46 | assert_routing( |
|
46 | assert_routing( | |
47 |
{ :method => ' |
|
47 | { :method => 'delete', :path => "/watchers/watch" }, | |
48 | { :controller => 'watchers', :action => 'unwatch' } |
|
48 | { :controller => 'watchers', :action => 'unwatch' } | |
49 | ) |
|
49 | ) | |
50 | assert_routing( |
|
50 | assert_routing( |
General Comments 0
You need to be logged in to leave comments.
Login now