@@ -0,0 +1,4 | |||||
|
1 | Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>'); | |||
|
2 | <% @users.each do |user| %> | |||
|
3 | new Effect.Highlight('user-<%= user.id %>'); | |||
|
4 | <% end %> |
@@ -0,0 +1,1 | |||||
|
1 | Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>'); |
@@ -0,0 +1,6 | |||||
|
1 | <% if @membership.valid? %> | |||
|
2 | Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>'); | |||
|
3 | new Effect.Highlight('member-<%= @membership.id %>'); | |||
|
4 | <% else %> | |||
|
5 | alert('<%= escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) %>'); | |||
|
6 | <% end %> |
@@ -0,0 +1,1 | |||||
|
1 | Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>'); |
@@ -1,158 +1,140 | |||||
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 GroupsController < ApplicationController |
|
18 | class GroupsController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin |
|
21 | before_filter :require_admin | |
22 | before_filter :find_group, :except => [:index, :new, :create] |
|
22 | before_filter :find_group, :except => [:index, :new, :create] | |
23 | accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user |
|
23 | accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user | |
24 |
|
24 | |||
25 | helper :custom_fields |
|
25 | helper :custom_fields | |
26 |
|
26 | |||
27 | def index |
|
27 | def index | |
28 | @groups = Group.sorted.all |
|
28 | @groups = Group.sorted.all | |
29 |
|
29 | |||
30 | respond_to do |format| |
|
30 | respond_to do |format| | |
31 | format.html |
|
31 | format.html | |
32 | format.api |
|
32 | format.api | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def show |
|
36 | def show | |
37 | respond_to do |format| |
|
37 | respond_to do |format| | |
38 | format.html |
|
38 | format.html | |
39 | format.api |
|
39 | format.api | |
40 | end |
|
40 | end | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def new |
|
43 | def new | |
44 | @group = Group.new |
|
44 | @group = Group.new | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def create |
|
47 | def create | |
48 | @group = Group.new |
|
48 | @group = Group.new | |
49 | @group.safe_attributes = params[:group] |
|
49 | @group.safe_attributes = params[:group] | |
50 |
|
50 | |||
51 | respond_to do |format| |
|
51 | respond_to do |format| | |
52 | if @group.save |
|
52 | if @group.save | |
53 | format.html { |
|
53 | format.html { | |
54 | flash[:notice] = l(:notice_successful_create) |
|
54 | flash[:notice] = l(:notice_successful_create) | |
55 | redirect_to(params[:continue] ? new_group_path : groups_path) |
|
55 | redirect_to(params[:continue] ? new_group_path : groups_path) | |
56 | } |
|
56 | } | |
57 | format.api { render :action => 'show', :status => :created, :location => group_url(@group) } |
|
57 | format.api { render :action => 'show', :status => :created, :location => group_url(@group) } | |
58 | else |
|
58 | else | |
59 | format.html { render :action => "new" } |
|
59 | format.html { render :action => "new" } | |
60 | format.api { render_validation_errors(@group) } |
|
60 | format.api { render_validation_errors(@group) } | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def edit |
|
65 | def edit | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def update |
|
68 | def update | |
69 | @group.safe_attributes = params[:group] |
|
69 | @group.safe_attributes = params[:group] | |
70 |
|
70 | |||
71 | respond_to do |format| |
|
71 | respond_to do |format| | |
72 | if @group.save |
|
72 | if @group.save | |
73 | flash[:notice] = l(:notice_successful_update) |
|
73 | flash[:notice] = l(:notice_successful_update) | |
74 | format.html { redirect_to(groups_path) } |
|
74 | format.html { redirect_to(groups_path) } | |
75 | format.api { render_api_ok } |
|
75 | format.api { render_api_ok } | |
76 | else |
|
76 | else | |
77 | format.html { render :action => "edit" } |
|
77 | format.html { render :action => "edit" } | |
78 | format.api { render_validation_errors(@group) } |
|
78 | format.api { render_validation_errors(@group) } | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def destroy |
|
83 | def destroy | |
84 | @group.destroy |
|
84 | @group.destroy | |
85 |
|
85 | |||
86 | respond_to do |format| |
|
86 | respond_to do |format| | |
87 | format.html { redirect_to(groups_url) } |
|
87 | format.html { redirect_to(groups_url) } | |
88 | format.api { render_api_ok } |
|
88 | format.api { render_api_ok } | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def add_users |
|
92 | def add_users | |
93 | users = User.find_all_by_id(params[:user_id] || params[:user_ids]) |
|
93 | @users = User.find_all_by_id(params[:user_id] || params[:user_ids]) | |
94 | @group.users << users if request.post? |
|
94 | @group.users << @users if request.post? | |
95 | respond_to do |format| |
|
95 | respond_to do |format| | |
96 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
96 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
97 |
format.js |
|
97 | format.js | |
98 | render(:update) {|page| |
|
|||
99 | page.replace_html "tab-content-users", :partial => 'groups/users' |
|
|||
100 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } |
|
|||
101 | } |
|
|||
102 | } |
|
|||
103 | format.api { render_api_ok } |
|
98 | format.api { render_api_ok } | |
104 | end |
|
99 | end | |
105 | end |
|
100 | end | |
106 |
|
101 | |||
107 | def remove_user |
|
102 | def remove_user | |
108 | @group.users.delete(User.find(params[:user_id])) if request.delete? |
|
103 | @group.users.delete(User.find(params[:user_id])) if request.delete? | |
109 | respond_to do |format| |
|
104 | respond_to do |format| | |
110 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
105 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
111 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } |
|
106 | format.js | |
112 | format.api { render_api_ok } |
|
107 | format.api { render_api_ok } | |
113 | end |
|
108 | end | |
114 | end |
|
109 | end | |
115 |
|
110 | |||
116 | def autocomplete_for_user |
|
111 | def autocomplete_for_user | |
117 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) |
|
112 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) | |
118 | render :layout => false |
|
113 | render :layout => false | |
119 | end |
|
114 | end | |
120 |
|
115 | |||
121 | def edit_membership |
|
116 | def edit_membership | |
122 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) |
|
117 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) | |
123 | @membership.save if request.post? |
|
118 | @membership.save if request.post? | |
124 | respond_to do |format| |
|
119 | respond_to do |format| | |
125 | if @membership.valid? |
|
120 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
126 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
121 | format.js | |
127 | format.js { |
|
|||
128 | render(:update) {|page| |
|
|||
129 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' |
|
|||
130 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
|||
131 | } |
|
|||
132 | } |
|
|||
133 | else |
|
|||
134 | format.js { |
|
|||
135 | render(:update) {|page| |
|
|||
136 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) |
|
|||
137 | } |
|
|||
138 | } |
|
|||
139 | end |
|
|||
140 | end |
|
122 | end | |
141 | end |
|
123 | end | |
142 |
|
124 | |||
143 | def destroy_membership |
|
125 | def destroy_membership | |
144 | Member.find(params[:membership_id]).destroy if request.post? |
|
126 | Member.find(params[:membership_id]).destroy if request.post? | |
145 | respond_to do |format| |
|
127 | respond_to do |format| | |
146 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
128 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
147 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } |
|
129 | format.js | |
148 | end |
|
130 | end | |
149 | end |
|
131 | end | |
150 |
|
132 | |||
151 | private |
|
133 | private | |
152 |
|
134 | |||
153 | def find_group |
|
135 | def find_group | |
154 | @group = Group.find(params[:id]) |
|
136 | @group = Group.find(params[:id]) | |
155 | rescue ActiveRecord::RecordNotFound |
|
137 | rescue ActiveRecord::RecordNotFound | |
156 | render_404 |
|
138 | render_404 | |
157 | end |
|
139 | end | |
158 | end |
|
140 | end |
@@ -1,180 +1,202 | |||||
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 |
|
19 | |||
20 | class GroupsControllerTest < ActionController::TestCase |
|
20 | class GroupsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :groups_users |
|
21 | fixtures :projects, :users, :members, :member_roles, :groups_users | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @request.session[:user_id] = 1 |
|
24 | @request.session[:user_id] = 1 | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_index |
|
27 | def test_index | |
28 | get :index |
|
28 | get :index | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_template 'index' |
|
30 | assert_template 'index' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_show |
|
33 | def test_show | |
34 | get :show, :id => 10 |
|
34 | get :show, :id => 10 | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'show' |
|
36 | assert_template 'show' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_show_invalid_should_return_404 |
|
39 | def test_show_invalid_should_return_404 | |
40 | get :show, :id => 99 |
|
40 | get :show, :id => 99 | |
41 | assert_response 404 |
|
41 | assert_response 404 | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_new |
|
44 | def test_new | |
45 | get :new |
|
45 | get :new | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'new' |
|
47 | assert_template 'new' | |
48 | assert_select 'input[name=?]', 'group[name]' |
|
48 | assert_select 'input[name=?]', 'group[name]' | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def test_create |
|
51 | def test_create | |
52 | assert_difference 'Group.count' do |
|
52 | assert_difference 'Group.count' do | |
53 | post :create, :group => {:name => 'New group'} |
|
53 | post :create, :group => {:name => 'New group'} | |
54 | end |
|
54 | end | |
55 | assert_redirected_to '/groups' |
|
55 | assert_redirected_to '/groups' | |
56 | group = Group.first(:order => 'id DESC') |
|
56 | group = Group.first(:order => 'id DESC') | |
57 | assert_equal 'New group', group.name |
|
57 | assert_equal 'New group', group.name | |
58 | assert_equal [], group.users |
|
58 | assert_equal [], group.users | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_create_and_continue |
|
61 | def test_create_and_continue | |
62 | assert_difference 'Group.count' do |
|
62 | assert_difference 'Group.count' do | |
63 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' |
|
63 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' | |
64 | end |
|
64 | end | |
65 | assert_redirected_to '/groups/new' |
|
65 | assert_redirected_to '/groups/new' | |
66 | group = Group.first(:order => 'id DESC') |
|
66 | group = Group.first(:order => 'id DESC') | |
67 | assert_equal 'New group', group.name |
|
67 | assert_equal 'New group', group.name | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_create_with_failure |
|
70 | def test_create_with_failure | |
71 | assert_no_difference 'Group.count' do |
|
71 | assert_no_difference 'Group.count' do | |
72 | post :create, :group => {:name => ''} |
|
72 | post :create, :group => {:name => ''} | |
73 | end |
|
73 | end | |
74 | assert_response :success |
|
74 | assert_response :success | |
75 | assert_template 'new' |
|
75 | assert_template 'new' | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_edit |
|
78 | def test_edit | |
79 | get :edit, :id => 10 |
|
79 | get :edit, :id => 10 | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_template 'edit' |
|
81 | assert_template 'edit' | |
82 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} |
|
82 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} | |
83 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} |
|
83 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_update |
|
86 | def test_update | |
87 | new_name = 'New name' |
|
87 | new_name = 'New name' | |
88 | put :update, :id => 10, :group => {:name => new_name} |
|
88 | put :update, :id => 10, :group => {:name => new_name} | |
89 | assert_redirected_to '/groups' |
|
89 | assert_redirected_to '/groups' | |
90 | group = Group.find(10) |
|
90 | group = Group.find(10) | |
91 | assert_equal new_name, group.name |
|
91 | assert_equal new_name, group.name | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_update_with_failure |
|
94 | def test_update_with_failure | |
95 | put :update, :id => 10, :group => {:name => ''} |
|
95 | put :update, :id => 10, :group => {:name => ''} | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'edit' |
|
97 | assert_template 'edit' | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_destroy |
|
100 | def test_destroy | |
101 | assert_difference 'Group.count', -1 do |
|
101 | assert_difference 'Group.count', -1 do | |
102 | post :destroy, :id => 10 |
|
102 | post :destroy, :id => 10 | |
103 | end |
|
103 | end | |
104 | assert_redirected_to '/groups' |
|
104 | assert_redirected_to '/groups' | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_add_users |
|
107 | def test_add_users | |
108 | assert_difference 'Group.find(10).users.count', 2 do |
|
108 | assert_difference 'Group.find(10).users.count', 2 do | |
109 | post :add_users, :id => 10, :user_ids => ['2', '3'] |
|
109 | post :add_users, :id => 10, :user_ids => ['2', '3'] | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_xhr_add_users |
|
113 | def test_xhr_add_users | |
114 | assert_difference 'Group.find(10).users.count', 2 do |
|
114 | assert_difference 'Group.find(10).users.count', 2 do | |
115 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] |
|
115 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] | |
|
116 | assert_response :success | |||
|
117 | assert_template 'add_users' | |||
|
118 | assert_equal 'text/javascript', response.content_type | |||
116 | end |
|
119 | end | |
117 | assert_select_rjs :replace_html, 'tab-content-users' |
|
120 | assert_match /John Smith/, response.body | |
118 | end |
|
121 | end | |
119 |
|
122 | |||
120 | def test_remove_user |
|
123 | def test_remove_user | |
121 | assert_difference 'Group.find(10).users.count', -1 do |
|
124 | assert_difference 'Group.find(10).users.count', -1 do | |
122 | delete :remove_user, :id => 10, :user_id => '8' |
|
125 | delete :remove_user, :id => 10, :user_id => '8' | |
123 | end |
|
126 | end | |
124 | end |
|
127 | end | |
125 |
|
128 | |||
126 | def test_xhr_remove_user |
|
129 | def test_xhr_remove_user | |
127 | assert_difference 'Group.find(10).users.count', -1 do |
|
130 | assert_difference 'Group.find(10).users.count', -1 do | |
128 | xhr :delete, :remove_user, :id => 10, :user_id => '8' |
|
131 | xhr :delete, :remove_user, :id => 10, :user_id => '8' | |
|
132 | assert_response :success | |||
|
133 | assert_template 'remove_user' | |||
|
134 | assert_equal 'text/javascript', response.content_type | |||
129 | end |
|
135 | end | |
130 | assert_select_rjs :replace_html, 'tab-content-users' |
|
|||
131 | end |
|
136 | end | |
132 |
|
137 | |||
133 | def test_new_membership |
|
138 | def test_new_membership | |
134 | assert_difference 'Group.find(10).members.count' do |
|
139 | assert_difference 'Group.find(10).members.count' do | |
135 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
140 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | |
136 | end |
|
141 | end | |
137 | end |
|
142 | end | |
138 |
|
143 | |||
139 | def test_xhr_new_membership |
|
144 | def test_xhr_new_membership | |
140 | assert_difference 'Group.find(10).members.count' do |
|
145 | assert_difference 'Group.find(10).members.count' do | |
141 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
146 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | |
|
147 | assert_response :success | |||
|
148 | assert_template 'edit_membership' | |||
|
149 | assert_equal 'text/javascript', response.content_type | |||
142 | end |
|
150 | end | |
143 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
151 | assert_match /OnlineStore/, response.body | |
144 | end |
|
152 | end | |
145 |
|
153 | |||
146 | def test_xhr_new_membership_with_failure |
|
154 | def test_xhr_new_membership_with_failure | |
147 | assert_no_difference 'Group.find(10).members.count' do |
|
155 | assert_no_difference 'Group.find(10).members.count' do | |
148 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} |
|
156 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} | |
|
157 | assert_response :success | |||
|
158 | assert_template 'edit_membership' | |||
|
159 | assert_equal 'text/javascript', response.content_type | |||
149 | end |
|
160 | end | |
150 |
assert |
|
161 | assert_match /alert/, response.body, "Alert message not sent" | |
151 | end |
|
162 | end | |
152 |
|
163 | |||
153 | def test_edit_membership |
|
164 | def test_edit_membership | |
154 | assert_no_difference 'Group.find(10).members.count' do |
|
165 | assert_no_difference 'Group.find(10).members.count' do | |
155 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} |
|
166 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} | |
156 | end |
|
167 | end | |
157 | end |
|
168 | end | |
158 |
|
169 | |||
|
170 | def test_xhr_edit_membership | |||
|
171 | assert_no_difference 'Group.find(10).members.count' do | |||
|
172 | xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} | |||
|
173 | assert_response :success | |||
|
174 | assert_template 'edit_membership' | |||
|
175 | assert_equal 'text/javascript', response.content_type | |||
|
176 | end | |||
|
177 | end | |||
|
178 | ||||
159 | def test_destroy_membership |
|
179 | def test_destroy_membership | |
160 | assert_difference 'Group.find(10).members.count', -1 do |
|
180 | assert_difference 'Group.find(10).members.count', -1 do | |
161 | post :destroy_membership, :id => 10, :membership_id => 6 |
|
181 | post :destroy_membership, :id => 10, :membership_id => 6 | |
162 | end |
|
182 | end | |
163 | end |
|
183 | end | |
164 |
|
184 | |||
165 | def test_xhr_destroy_membership |
|
185 | def test_xhr_destroy_membership | |
166 | assert_difference 'Group.find(10).members.count', -1 do |
|
186 | assert_difference 'Group.find(10).members.count', -1 do | |
167 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 |
|
187 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 | |
|
188 | assert_response :success | |||
|
189 | assert_template 'destroy_membership' | |||
|
190 | assert_equal 'text/javascript', response.content_type | |||
168 | end |
|
191 | end | |
169 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
|||
170 | end |
|
192 | end | |
171 |
|
193 | |||
172 | def test_autocomplete_for_user |
|
194 | def test_autocomplete_for_user | |
173 | get :autocomplete_for_user, :id => 10, :q => 'mis' |
|
195 | get :autocomplete_for_user, :id => 10, :q => 'mis' | |
174 | assert_response :success |
|
196 | assert_response :success | |
175 | users = assigns(:users) |
|
197 | users = assigns(:users) | |
176 | assert_not_nil users |
|
198 | assert_not_nil users | |
177 | assert users.any? |
|
199 | assert users.any? | |
178 | assert !users.include?(Group.find(10).users.first) |
|
200 | assert !users.include?(Group.find(10).users.first) | |
179 | end |
|
201 | end | |
180 | end |
|
202 | end |
General Comments 0
You need to be logged in to leave comments.
Login now