@@ -0,0 +1,2 | |||||
|
1 | <% selector = ".#{watcher_css(watched)}" %> | |||
|
2 | $$("<%= selector %>").each(function(el){el.update("<%= escape_javascript watcher_link(watched, user) %>")}); |
@@ -0,0 +1,4 | |||||
|
1 | <% @users.each do |user| %> | |||
|
2 | $$("#issue_watcher_user_ids_<%= user.id %>").each(function(el){el.remove();}); | |||
|
3 | <% end %> | |||
|
4 | Element.insert('watchers_inputs', '<%= escape_javascript(watchers_checkboxes(nil, @users, true)) %>'); |
@@ -0,0 +1,2 | |||||
|
1 | Element.update('ajax-modal', '<%= escape_javascript(render(:partial => 'watchers/new', :locals => {:watched => @watched})) %>'); | |||
|
2 | Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); |
@@ -0,0 +1,1 | |||||
|
1 | Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); |
@@ -0,0 +1,3 | |||||
|
1 | Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'watchers/new', :locals => {:watched => @watched}) %>'); | |||
|
2 | showModal('ajax-modal', '400px'); | |||
|
3 | $('ajax-modal').addClassName('new-watcher'); |
@@ -1,128 +1,95 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class WatchersController < ApplicationController |
|
18 | class WatchersController < ApplicationController | |
19 | before_filter :find_project |
|
19 | before_filter :find_project | |
20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] |
|
20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] | |
21 | before_filter :authorize, :only => [:new, :destroy] |
|
21 | before_filter :authorize, :only => [:new, :destroy] | |
22 |
|
22 | |||
23 | def watch |
|
23 | def watch | |
24 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) |
|
24 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) | |
25 | render_403 |
|
25 | render_403 | |
26 | else |
|
26 | else | |
27 | set_watcher(User.current, true) |
|
27 | set_watcher(User.current, true) | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def unwatch |
|
31 | def unwatch | |
32 | set_watcher(User.current, false) |
|
32 | set_watcher(User.current, false) | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def new |
|
35 | def new | |
36 | respond_to do |format| |
|
|||
37 | format.js do |
|
|||
38 | render :update do |page| |
|
|||
39 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
|||
40 | page << "showModal('ajax-modal', '400px');" |
|
|||
41 | page << "$('ajax-modal').addClassName('new-watcher');" |
|
|||
42 | end |
|
|||
43 | end |
|
|||
44 | end |
|
|||
45 | end |
|
36 | end | |
46 |
|
37 | |||
47 | def create |
|
38 | def create | |
48 | if params[:watcher].is_a?(Hash) && request.post? |
|
39 | if params[:watcher].is_a?(Hash) && request.post? | |
49 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
|
40 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] | |
50 | user_ids.each do |user_id| |
|
41 | user_ids.each do |user_id| | |
51 | Watcher.create(:watchable => @watched, :user_id => user_id) |
|
42 | Watcher.create(:watchable => @watched, :user_id => user_id) | |
52 | end |
|
43 | end | |
53 | end |
|
44 | end | |
54 | respond_to do |format| |
|
45 | respond_to do |format| | |
55 | format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} |
|
46 | format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} | |
56 |
format.js |
|
47 | format.js | |
57 | render :update do |page| |
|
|||
58 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
|||
59 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
|||
60 | end |
|
|||
61 | end |
|
|||
62 | end |
|
48 | end | |
63 | end |
|
49 | end | |
64 |
|
50 | |||
65 | def append |
|
51 | def append | |
66 | if params[:watcher].is_a?(Hash) |
|
52 | if params[:watcher].is_a?(Hash) | |
67 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
|
53 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] | |
68 | users = User.active.find_all_by_id(user_ids) |
|
54 | @users = User.active.find_all_by_id(user_ids) | |
69 | respond_to do |format| |
|
|||
70 | format.js do |
|
|||
71 | render :update do |page| |
|
|||
72 | users.each do |user| |
|
|||
73 | page << %|$$("#issue_watcher_user_ids_#{user.id}").each(function(el){el.remove();});| |
|
|||
74 | end |
|
|||
75 | page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true) |
|
|||
76 | end |
|
|||
77 | end |
|
|||
78 | end |
|
|||
79 | end |
|
55 | end | |
80 | end |
|
56 | end | |
81 |
|
57 | |||
82 | def destroy |
|
58 | def destroy | |
83 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
|
59 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? | |
84 | respond_to do |format| |
|
60 | respond_to do |format| | |
85 | format.html { redirect_to :back } |
|
61 | format.html { redirect_to :back } | |
86 |
format.js |
|
62 | format.js | |
87 | render :update do |page| |
|
|||
88 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
|||
89 | end |
|
|||
90 | end |
|
|||
91 | end |
|
63 | end | |
92 | end |
|
64 | end | |
93 |
|
65 | |||
94 | def autocomplete_for_user |
|
66 | def autocomplete_for_user | |
95 | @users = User.active.like(params[:q]).find(:all, :limit => 100) |
|
67 | @users = User.active.like(params[:q]).find(:all, :limit => 100) | |
96 | if @watched |
|
68 | if @watched | |
97 | @users -= @watched.watcher_users |
|
69 | @users -= @watched.watcher_users | |
98 | end |
|
70 | end | |
99 | render :layout => false |
|
71 | render :layout => false | |
100 | end |
|
72 | end | |
101 |
|
73 | |||
102 | private |
|
74 | private | |
103 | def find_project |
|
75 | def find_project | |
104 | if params[:object_type] && params[:object_id] |
|
76 | if params[:object_type] && params[:object_id] | |
105 | klass = Object.const_get(params[:object_type].camelcase) |
|
77 | klass = Object.const_get(params[:object_type].camelcase) | |
106 | return false unless klass.respond_to?('watched_by') |
|
78 | return false unless klass.respond_to?('watched_by') | |
107 | @watched = klass.find(params[:object_id]) |
|
79 | @watched = klass.find(params[:object_id]) | |
108 | @project = @watched.project |
|
80 | @project = @watched.project | |
109 | elsif params[:project_id] |
|
81 | elsif params[:project_id] | |
110 | @project = Project.visible.find_by_param(params[:project_id]) |
|
82 | @project = Project.visible.find_by_param(params[:project_id]) | |
111 | end |
|
83 | end | |
112 | rescue |
|
84 | rescue | |
113 | render_404 |
|
85 | render_404 | |
114 | end |
|
86 | end | |
115 |
|
87 | |||
116 | def set_watcher(user, watching) |
|
88 | def set_watcher(user, watching) | |
117 | @watched.set_watcher(user, watching) |
|
89 | @watched.set_watcher(user, watching) | |
118 | respond_to do |format| |
|
90 | respond_to do |format| | |
119 | format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} |
|
91 | format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} | |
120 | format.js do |
|
92 | format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} } | |
121 | render(:update) do |page| |
|
|||
122 | c = watcher_css(@watched) |
|
|||
123 | page << %|$$(".#{c}").each(function(el){el.innerHTML="#{escape_javascript watcher_link(@watched, user)}"});| |
|
|||
124 | end |
|
|||
125 | end |
|
|||
126 | end |
|
93 | end | |
127 | end |
|
94 | end | |
128 | end |
|
95 | end |
@@ -1,167 +1,165 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'watchers_controller' |
|
19 | require 'watchers_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WatchersController; def rescue_action(e) raise e end; end |
|
22 | class WatchersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WatchersControllerTest < ActionController::TestCase |
|
24 | class WatchersControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | |
26 | :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers |
|
26 | :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers | |
27 |
|
27 | |||
28 | def setup |
|
28 | def setup | |
29 | @controller = WatchersController.new |
|
29 | @controller = WatchersController.new | |
30 | @request = ActionController::TestRequest.new |
|
30 | @request = ActionController::TestRequest.new | |
31 | @response = ActionController::TestResponse.new |
|
31 | @response = ActionController::TestResponse.new | |
32 | User.current = nil |
|
32 | User.current = nil | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_watch |
|
35 | def test_watch | |
36 | @request.session[:user_id] = 3 |
|
36 | @request.session[:user_id] = 3 | |
37 | assert_difference('Watcher.count') do |
|
37 | assert_difference('Watcher.count') do | |
38 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
|
38 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
39 | assert_response :success |
|
39 | assert_response :success | |
40 | assert @response.body.include?('$$(".issue-1-watcher")') |
|
40 | assert @response.body.include?('$$(".issue-1-watcher")') | |
41 | end |
|
41 | end | |
42 | assert Issue.find(1).watched_by?(User.find(3)) |
|
42 | assert Issue.find(1).watched_by?(User.find(3)) | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_watch_should_be_denied_without_permission |
|
45 | def test_watch_should_be_denied_without_permission | |
46 | Role.find(2).remove_permission! :view_issues |
|
46 | Role.find(2).remove_permission! :view_issues | |
47 | @request.session[:user_id] = 3 |
|
47 | @request.session[:user_id] = 3 | |
48 | assert_no_difference('Watcher.count') do |
|
48 | assert_no_difference('Watcher.count') do | |
49 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
|
49 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
50 | assert_response 403 |
|
50 | assert_response 403 | |
51 | end |
|
51 | end | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_watch_invalid_class_should_respond_with_404 |
|
54 | def test_watch_invalid_class_should_respond_with_404 | |
55 | @request.session[:user_id] = 3 |
|
55 | @request.session[:user_id] = 3 | |
56 | assert_no_difference('Watcher.count') do |
|
56 | assert_no_difference('Watcher.count') do | |
57 | xhr :post, :watch, :object_type => 'foo', :object_id => '1' |
|
57 | xhr :post, :watch, :object_type => 'foo', :object_id => '1' | |
58 | assert_response 404 |
|
58 | assert_response 404 | |
59 | end |
|
59 | end | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_watch_invalid_object_should_respond_with_404 |
|
62 | def test_watch_invalid_object_should_respond_with_404 | |
63 | @request.session[:user_id] = 3 |
|
63 | @request.session[:user_id] = 3 | |
64 | assert_no_difference('Watcher.count') do |
|
64 | assert_no_difference('Watcher.count') do | |
65 | xhr :post, :watch, :object_type => 'issue', :object_id => '999' |
|
65 | xhr :post, :watch, :object_type => 'issue', :object_id => '999' | |
66 | assert_response 404 |
|
66 | assert_response 404 | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_unwatch |
|
70 | def test_unwatch | |
71 | @request.session[:user_id] = 3 |
|
71 | @request.session[:user_id] = 3 | |
72 | assert_difference('Watcher.count', -1) do |
|
72 | assert_difference('Watcher.count', -1) do | |
73 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2' |
|
73 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2' | |
74 | assert_response :success |
|
74 | assert_response :success | |
75 | assert @response.body.include?('$$(".issue-2-watcher")') |
|
75 | assert @response.body.include?('$$(".issue-2-watcher")') | |
76 | end |
|
76 | end | |
77 | assert !Issue.find(1).watched_by?(User.find(3)) |
|
77 | assert !Issue.find(1).watched_by?(User.find(3)) | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_new |
|
80 | def test_new | |
81 | @request.session[:user_id] = 2 |
|
81 | @request.session[:user_id] = 2 | |
82 | xhr :get, :new, :object_type => 'issue', :object_id => '2' |
|
82 | xhr :get, :new, :object_type => 'issue', :object_id => '2' | |
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_select_rjs :replace_html, 'ajax-modal' |
|
84 | assert_match /ajax-modal/, response.body | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_new_for_new_record_with_id |
|
87 | def test_new_for_new_record_with_id | |
88 | @request.session[:user_id] = 2 |
|
88 | @request.session[:user_id] = 2 | |
89 | xhr :get, :new, :project_id => 1 |
|
89 | xhr :get, :new, :project_id => 1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_equal Project.find(1), assigns(:project) |
|
91 | assert_equal Project.find(1), assigns(:project) | |
92 | assert_select_rjs :replace_html, 'ajax-modal' |
|
92 | assert_match /ajax-modal/, response.body | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_new_for_new_record_with_identifier |
|
95 | def test_new_for_new_record_with_identifier | |
96 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
97 | xhr :get, :new, :project_id => 'ecookbook' |
|
97 | xhr :get, :new, :project_id => 'ecookbook' | |
98 | assert_response :success |
|
98 | assert_response :success | |
99 | assert_equal Project.find(1), assigns(:project) |
|
99 | assert_equal Project.find(1), assigns(:project) | |
100 | assert_select_rjs :replace_html, 'ajax-modal' |
|
100 | assert_match /ajax-modal/, response.body | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_create |
|
103 | def test_create | |
104 | @request.session[:user_id] = 2 |
|
104 | @request.session[:user_id] = 2 | |
105 | assert_difference('Watcher.count') do |
|
105 | assert_difference('Watcher.count') do | |
106 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} |
|
106 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} | |
107 | assert_response :success |
|
107 | assert_response :success | |
108 | assert_select_rjs :replace_html, 'watchers' |
|
108 | assert_match /watchers/, response.body | |
109 | assert_select_rjs :replace_html, 'ajax-modal' |
|
109 | assert_match /ajax-modal/, response.body | |
110 | end |
|
110 | end | |
111 | assert Issue.find(2).watched_by?(User.find(4)) |
|
111 | assert Issue.find(2).watched_by?(User.find(4)) | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def test_create_multiple |
|
114 | def test_create_multiple | |
115 | @request.session[:user_id] = 2 |
|
115 | @request.session[:user_id] = 2 | |
116 | assert_difference('Watcher.count', 2) do |
|
116 | assert_difference('Watcher.count', 2) do | |
117 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} |
|
117 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} | |
118 | assert_response :success |
|
118 | assert_response :success | |
119 | assert_select_rjs :replace_html, 'watchers' |
|
119 | assert_match /watchers/, response.body | |
120 | assert_select_rjs :replace_html, 'ajax-modal' |
|
120 | assert_match /ajax-modal/, response.body | |
121 | end |
|
121 | end | |
122 | assert Issue.find(2).watched_by?(User.find(4)) |
|
122 | assert Issue.find(2).watched_by?(User.find(4)) | |
123 | assert Issue.find(2).watched_by?(User.find(7)) |
|
123 | assert Issue.find(2).watched_by?(User.find(7)) | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def test_autocomplete_on_watchable_creation |
|
126 | def test_autocomplete_on_watchable_creation | |
127 | xhr :get, :autocomplete_for_user, :q => 'mi' |
|
127 | xhr :get, :autocomplete_for_user, :q => 'mi' | |
128 | assert_response :success |
|
128 | assert_response :success | |
129 | assert_select 'input', :count => 4 |
|
129 | assert_select 'input', :count => 4 | |
130 | assert_select 'input[name=?][value=1]', 'watcher[user_ids][]' |
|
130 | assert_select 'input[name=?][value=1]', 'watcher[user_ids][]' | |
131 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
|
131 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
132 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
|
132 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
133 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
|
133 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def test_autocomplete_on_watchable_update |
|
136 | def test_autocomplete_on_watchable_update | |
137 | xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue' |
|
137 | xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue' | |
138 | assert_response :success |
|
138 | assert_response :success | |
139 | assert_select 'input', :count => 3 |
|
139 | assert_select 'input', :count => 3 | |
140 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
|
140 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
141 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
|
141 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
142 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
|
142 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
143 |
|
143 | |||
144 | end |
|
144 | end | |
145 |
|
145 | |||
146 | def test_append |
|
146 | def test_append | |
147 | @request.session[:user_id] = 2 |
|
147 | @request.session[:user_id] = 2 | |
148 | assert_no_difference 'Watcher.count' do |
|
148 | assert_no_difference 'Watcher.count' do | |
149 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']} |
|
149 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']} | |
150 | assert_response :success |
|
150 | assert_response :success | |
151 |
assert_ |
|
151 | assert_include 'watchers_inputs', response.body | |
152 |
|
|
152 | assert_include 'issue[watcher_user_ids][]', response.body | |
153 | assert_select 'input[name=?][value=7]', 'issue[watcher_user_ids][]' |
|
|||
154 | end |
|
|||
155 | end |
|
153 | end | |
156 | end |
|
154 | end | |
157 |
|
155 | |||
158 | def test_remove_watcher |
|
156 | def test_remove_watcher | |
159 | @request.session[:user_id] = 2 |
|
157 | @request.session[:user_id] = 2 | |
160 | assert_difference('Watcher.count', -1) do |
|
158 | assert_difference('Watcher.count', -1) do | |
161 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
|
159 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
162 | assert_response :success |
|
160 | assert_response :success | |
163 | assert_select_rjs :replace_html, 'watchers' |
|
161 | assert_match /watchers/, response.body | |
164 | end |
|
162 | end | |
165 | assert !Issue.find(2).watched_by?(User.find(3)) |
|
163 | assert !Issue.find(2).watched_by?(User.find(3)) | |
166 | end |
|
164 | end | |
167 | end |
|
165 | end |
General Comments 0
You need to be logged in to leave comments.
Login now