@@ -1,146 +1,148 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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 UsersController < ApplicationController |
|
18 | class UsersController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => :show |
|
21 | before_filter :require_admin, :except => :show | |
22 |
|
22 | |||
23 | helper :sort |
|
23 | helper :sort | |
24 | include SortHelper |
|
24 | include SortHelper | |
25 | helper :custom_fields |
|
25 | helper :custom_fields | |
26 | include CustomFieldsHelper |
|
26 | include CustomFieldsHelper | |
27 |
|
27 | |||
28 | def index |
|
28 | def index | |
29 | sort_init 'login', 'asc' |
|
29 | sort_init 'login', 'asc' | |
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
31 |
|
31 | |||
32 | @status = params[:status] ? params[:status].to_i : 1 |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
34 |
|
34 | |||
35 | unless params[:name].blank? |
|
35 | unless params[:name].blank? | |
36 | name = "%#{params[:name].strip.downcase}%" |
|
36 | name = "%#{params[:name].strip.downcase}%" | |
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | @user_count = User.count(:conditions => c.conditions) |
|
40 | @user_count = User.count(:conditions => c.conditions) | |
41 | @user_pages = Paginator.new self, @user_count, |
|
41 | @user_pages = Paginator.new self, @user_count, | |
42 | per_page_option, |
|
42 | per_page_option, | |
43 | params['page'] |
|
43 | params['page'] | |
44 | @users = User.find :all,:order => sort_clause, |
|
44 | @users = User.find :all,:order => sort_clause, | |
45 | :conditions => c.conditions, |
|
45 | :conditions => c.conditions, | |
46 | :limit => @user_pages.items_per_page, |
|
46 | :limit => @user_pages.items_per_page, | |
47 | :offset => @user_pages.current.offset |
|
47 | :offset => @user_pages.current.offset | |
48 |
|
48 | |||
49 | render :layout => !request.xhr? |
|
49 | render :layout => !request.xhr? | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def show |
|
52 | def show | |
53 |
@user = User |
|
53 | @user = User.find(params[:id]) | |
54 | @custom_values = @user.custom_values |
|
54 | @custom_values = @user.custom_values | |
55 |
|
55 | |||
56 | # show only public projects and private projects that the logged in user is also a member of |
|
56 | # show only public projects and private projects that the logged in user is also a member of | |
57 | @memberships = @user.memberships.select do |membership| |
|
57 | @memberships = @user.memberships.select do |membership| | |
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) |
|
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
62 | @events_by_day = events.group_by(&:event_date) |
|
62 | @events_by_day = events.group_by(&:event_date) | |
63 |
|
63 | |||
64 | if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty? |
|
64 | unless User.current.admin? | |
|
65 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) | |||
65 | render_404 |
|
66 | render_404 | |
66 | return |
|
67 | return | |
67 | end |
|
68 | end | |
|
69 | end | |||
68 | render :layout => 'base' |
|
70 | render :layout => 'base' | |
69 |
|
71 | |||
70 | rescue ActiveRecord::RecordNotFound |
|
72 | rescue ActiveRecord::RecordNotFound | |
71 | render_404 |
|
73 | render_404 | |
72 | end |
|
74 | end | |
73 |
|
75 | |||
74 | def add |
|
76 | def add | |
75 | if request.get? |
|
77 | if request.get? | |
76 | @user = User.new(:language => Setting.default_language) |
|
78 | @user = User.new(:language => Setting.default_language) | |
77 | else |
|
79 | else | |
78 | @user = User.new(params[:user]) |
|
80 | @user = User.new(params[:user]) | |
79 | @user.admin = params[:user][:admin] || false |
|
81 | @user.admin = params[:user][:admin] || false | |
80 | @user.login = params[:user][:login] |
|
82 | @user.login = params[:user][:login] | |
81 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
83 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id | |
82 | if @user.save |
|
84 | if @user.save | |
83 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
85 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] | |
84 | flash[:notice] = l(:notice_successful_create) |
|
86 | flash[:notice] = l(:notice_successful_create) | |
85 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : |
|
87 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : | |
86 | {:controller => 'users', :action => 'edit', :id => @user}) |
|
88 | {:controller => 'users', :action => 'edit', :id => @user}) | |
87 | return |
|
89 | return | |
88 | end |
|
90 | end | |
89 | end |
|
91 | end | |
90 | @auth_sources = AuthSource.find(:all) |
|
92 | @auth_sources = AuthSource.find(:all) | |
91 | end |
|
93 | end | |
92 |
|
94 | |||
93 | def edit |
|
95 | def edit | |
94 | @user = User.find(params[:id]) |
|
96 | @user = User.find(params[:id]) | |
95 | if request.post? |
|
97 | if request.post? | |
96 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
98 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
97 | @user.login = params[:user][:login] if params[:user][:login] |
|
99 | @user.login = params[:user][:login] if params[:user][:login] | |
98 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id |
|
100 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id | |
99 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] |
|
101 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] | |
100 | @user.attributes = params[:user] |
|
102 | @user.attributes = params[:user] | |
101 | # Was the account actived ? (do it before User#save clears the change) |
|
103 | # Was the account actived ? (do it before User#save clears the change) | |
102 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
104 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |
103 | if @user.save |
|
105 | if @user.save | |
104 | if was_activated |
|
106 | if was_activated | |
105 | Mailer.deliver_account_activated(@user) |
|
107 | Mailer.deliver_account_activated(@user) | |
106 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |
|
108 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? | |
107 | Mailer.deliver_account_information(@user, params[:password]) |
|
109 | Mailer.deliver_account_information(@user, params[:password]) | |
108 | end |
|
110 | end | |
109 | flash[:notice] = l(:notice_successful_update) |
|
111 | flash[:notice] = l(:notice_successful_update) | |
110 | redirect_to :back |
|
112 | redirect_to :back | |
111 | end |
|
113 | end | |
112 | end |
|
114 | end | |
113 | @auth_sources = AuthSource.find(:all) |
|
115 | @auth_sources = AuthSource.find(:all) | |
114 | @membership ||= Member.new |
|
116 | @membership ||= Member.new | |
115 | rescue ::ActionController::RedirectBackError |
|
117 | rescue ::ActionController::RedirectBackError | |
116 | redirect_to :controller => 'users', :action => 'edit', :id => @user |
|
118 | redirect_to :controller => 'users', :action => 'edit', :id => @user | |
117 | end |
|
119 | end | |
118 |
|
120 | |||
119 | def edit_membership |
|
121 | def edit_membership | |
120 | @user = User.find(params[:id]) |
|
122 | @user = User.find(params[:id]) | |
121 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user) |
|
123 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user) | |
122 | @membership.attributes = params[:membership] |
|
124 | @membership.attributes = params[:membership] | |
123 | @membership.save if request.post? |
|
125 | @membership.save if request.post? | |
124 | respond_to do |format| |
|
126 | respond_to do |format| | |
125 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
127 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
126 | format.js { |
|
128 | format.js { | |
127 | render(:update) {|page| |
|
129 | render(:update) {|page| | |
128 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' |
|
130 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' | |
129 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
131 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
130 | } |
|
132 | } | |
131 | } |
|
133 | } | |
132 | end |
|
134 | end | |
133 | end |
|
135 | end | |
134 |
|
136 | |||
135 | def destroy_membership |
|
137 | def destroy_membership | |
136 | @user = User.find(params[:id]) |
|
138 | @user = User.find(params[:id]) | |
137 | @membership = Member.find(params[:membership_id]) |
|
139 | @membership = Member.find(params[:membership_id]) | |
138 | if request.post? && @membership.deletable? |
|
140 | if request.post? && @membership.deletable? | |
139 | @membership.destroy |
|
141 | @membership.destroy | |
140 | end |
|
142 | end | |
141 | respond_to do |format| |
|
143 | respond_to do |format| | |
142 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
144 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
143 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
145 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } | |
144 | end |
|
146 | end | |
145 | end |
|
147 | end | |
146 | end |
|
148 | end |
@@ -1,223 +1,229 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'users_controller' |
|
19 | require 'users_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class UsersController; def rescue_action(e) raise e end; end |
|
22 | class UsersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class UsersControllerTest < ActionController::TestCase |
|
24 | class UsersControllerTest < ActionController::TestCase | |
25 | include Redmine::I18n |
|
25 | include Redmine::I18n | |
26 |
|
26 | |||
27 | fixtures :users, :projects, :members, :member_roles, :roles |
|
27 | fixtures :users, :projects, :members, :member_roles, :roles | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = UsersController.new |
|
30 | @controller = UsersController.new | |
31 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
32 | @response = ActionController::TestResponse.new |
|
32 | @response = ActionController::TestResponse.new | |
33 | User.current = nil |
|
33 | User.current = nil | |
34 | @request.session[:user_id] = 1 # admin |
|
34 | @request.session[:user_id] = 1 # admin | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_index_routing |
|
37 | def test_index_routing | |
38 | assert_generates( |
|
38 | assert_generates( | |
39 | '/users', |
|
39 | '/users', | |
40 | :controller => 'users', :action => 'index' |
|
40 | :controller => 'users', :action => 'index' | |
41 | ) |
|
41 | ) | |
42 | assert_routing( |
|
42 | assert_routing( | |
43 | {:method => :get, :path => '/users'}, |
|
43 | {:method => :get, :path => '/users'}, | |
44 | :controller => 'users', :action => 'index' |
|
44 | :controller => 'users', :action => 'index' | |
45 | ) |
|
45 | ) | |
46 | assert_recognizes( |
|
46 | assert_recognizes( | |
47 | {:controller => 'users', :action => 'index'}, |
|
47 | {:controller => 'users', :action => 'index'}, | |
48 | {:method => :get, :path => '/users'} |
|
48 | {:method => :get, :path => '/users'} | |
49 | ) |
|
49 | ) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_index |
|
52 | def test_index | |
53 | get :index |
|
53 | get :index | |
54 | assert_response :success |
|
54 | assert_response :success | |
55 | assert_template 'index' |
|
55 | assert_template 'index' | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_index |
|
58 | def test_index | |
59 | get :index |
|
59 | get :index | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'index' |
|
61 | assert_template 'index' | |
62 | assert_not_nil assigns(:users) |
|
62 | assert_not_nil assigns(:users) | |
63 | # active users only |
|
63 | # active users only | |
64 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
64 | assert_nil assigns(:users).detect {|u| !u.active?} | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_index_with_name_filter |
|
67 | def test_index_with_name_filter | |
68 | get :index, :name => 'john' |
|
68 | get :index, :name => 'john' | |
69 | assert_response :success |
|
69 | assert_response :success | |
70 | assert_template 'index' |
|
70 | assert_template 'index' | |
71 | users = assigns(:users) |
|
71 | users = assigns(:users) | |
72 | assert_not_nil users |
|
72 | assert_not_nil users | |
73 | assert_equal 1, users.size |
|
73 | assert_equal 1, users.size | |
74 | assert_equal 'John', users.first.firstname |
|
74 | assert_equal 'John', users.first.firstname | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_show_routing |
|
77 | def test_show_routing | |
78 | assert_routing( |
|
78 | assert_routing( | |
79 | {:method => :get, :path => '/users/44'}, |
|
79 | {:method => :get, :path => '/users/44'}, | |
80 | :controller => 'users', :action => 'show', :id => '44' |
|
80 | :controller => 'users', :action => 'show', :id => '44' | |
81 | ) |
|
81 | ) | |
82 | assert_recognizes( |
|
82 | assert_recognizes( | |
83 | {:controller => 'users', :action => 'show', :id => '44'}, |
|
83 | {:controller => 'users', :action => 'show', :id => '44'}, | |
84 | {:method => :get, :path => '/users/44'} |
|
84 | {:method => :get, :path => '/users/44'} | |
85 | ) |
|
85 | ) | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_show |
|
88 | def test_show | |
89 | @request.session[:user_id] = nil |
|
89 | @request.session[:user_id] = nil | |
90 | get :show, :id => 2 |
|
90 | get :show, :id => 2 | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'show' |
|
92 | assert_template 'show' | |
93 | assert_not_nil assigns(:user) |
|
93 | assert_not_nil assigns(:user) | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_show_should_not_fail_when_custom_values_are_nil |
|
96 | def test_show_should_not_fail_when_custom_values_are_nil | |
97 | user = User.find(2) |
|
97 | user = User.find(2) | |
98 |
|
98 | |||
99 | # Create a custom field to illustrate the issue |
|
99 | # Create a custom field to illustrate the issue | |
100 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') |
|
100 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') | |
101 | custom_value = user.custom_values.build(:custom_field => custom_field).save! |
|
101 | custom_value = user.custom_values.build(:custom_field => custom_field).save! | |
102 |
|
102 | |||
103 | get :show, :id => 2 |
|
103 | get :show, :id => 2 | |
104 | assert_response :success |
|
104 | assert_response :success | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 |
|
||||
108 | def test_show_inactive |
|
107 | def test_show_inactive | |
|
108 | @request.session[:user_id] = nil | |||
109 | get :show, :id => 5 |
|
109 | get :show, :id => 5 | |
110 | assert_response 404 |
|
110 | assert_response 404 | |
111 | assert_nil assigns(:user) |
|
|||
112 | end |
|
111 | end | |
113 |
|
112 | |||
114 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project |
|
113 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project | |
115 | @request.session[:user_id] = nil |
|
114 | @request.session[:user_id] = nil | |
116 | get :show, :id => 9 |
|
115 | get :show, :id => 9 | |
117 | assert_response 404 |
|
116 | assert_response 404 | |
118 | end |
|
117 | end | |
119 |
|
118 | |||
|
119 | def test_show_inactive_by_admin | |||
|
120 | @request.session[:user_id] = 1 | |||
|
121 | get :show, :id => 5 | |||
|
122 | assert_response 200 | |||
|
123 | assert_not_nil assigns(:user) | |||
|
124 | end | |||
|
125 | ||||
120 | def test_add_routing |
|
126 | def test_add_routing | |
121 | assert_routing( |
|
127 | assert_routing( | |
122 | {:method => :get, :path => '/users/new'}, |
|
128 | {:method => :get, :path => '/users/new'}, | |
123 | :controller => 'users', :action => 'add' |
|
129 | :controller => 'users', :action => 'add' | |
124 | ) |
|
130 | ) | |
125 | assert_recognizes( |
|
131 | assert_recognizes( | |
126 | #TODO: remove this and replace with POST to collection, need to modify form |
|
132 | #TODO: remove this and replace with POST to collection, need to modify form | |
127 | {:controller => 'users', :action => 'add'}, |
|
133 | {:controller => 'users', :action => 'add'}, | |
128 | {:method => :post, :path => '/users/new'} |
|
134 | {:method => :post, :path => '/users/new'} | |
129 | ) |
|
135 | ) | |
130 | assert_recognizes( |
|
136 | assert_recognizes( | |
131 | {:controller => 'users', :action => 'add'}, |
|
137 | {:controller => 'users', :action => 'add'}, | |
132 | {:method => :post, :path => '/users'} |
|
138 | {:method => :post, :path => '/users'} | |
133 | ) |
|
139 | ) | |
134 | end |
|
140 | end | |
135 |
|
141 | |||
136 | def test_edit_routing |
|
142 | def test_edit_routing | |
137 | assert_routing( |
|
143 | assert_routing( | |
138 | {:method => :get, :path => '/users/444/edit'}, |
|
144 | {:method => :get, :path => '/users/444/edit'}, | |
139 | :controller => 'users', :action => 'edit', :id => '444' |
|
145 | :controller => 'users', :action => 'edit', :id => '444' | |
140 | ) |
|
146 | ) | |
141 | assert_routing( |
|
147 | assert_routing( | |
142 | {:method => :get, :path => '/users/222/edit/membership'}, |
|
148 | {:method => :get, :path => '/users/222/edit/membership'}, | |
143 | :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' |
|
149 | :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' | |
144 | ) |
|
150 | ) | |
145 | assert_recognizes( |
|
151 | assert_recognizes( | |
146 | #TODO: use PUT on user_path, modify form |
|
152 | #TODO: use PUT on user_path, modify form | |
147 | {:controller => 'users', :action => 'edit', :id => '444'}, |
|
153 | {:controller => 'users', :action => 'edit', :id => '444'}, | |
148 | {:method => :post, :path => '/users/444/edit'} |
|
154 | {:method => :post, :path => '/users/444/edit'} | |
149 | ) |
|
155 | ) | |
150 | end |
|
156 | end | |
151 |
|
157 | |||
152 | def test_edit |
|
158 | def test_edit | |
153 | ActionMailer::Base.deliveries.clear |
|
159 | ActionMailer::Base.deliveries.clear | |
154 | post :edit, :id => 2, :user => {:firstname => 'Changed'} |
|
160 | post :edit, :id => 2, :user => {:firstname => 'Changed'} | |
155 | assert_equal 'Changed', User.find(2).firstname |
|
161 | assert_equal 'Changed', User.find(2).firstname | |
156 | assert ActionMailer::Base.deliveries.empty? |
|
162 | assert ActionMailer::Base.deliveries.empty? | |
157 | end |
|
163 | end | |
158 |
|
164 | |||
159 | def test_edit_with_activation_should_send_a_notification |
|
165 | def test_edit_with_activation_should_send_a_notification | |
160 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
|
166 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | |
161 | u.login = 'foo' |
|
167 | u.login = 'foo' | |
162 | u.status = User::STATUS_REGISTERED |
|
168 | u.status = User::STATUS_REGISTERED | |
163 | u.save! |
|
169 | u.save! | |
164 | ActionMailer::Base.deliveries.clear |
|
170 | ActionMailer::Base.deliveries.clear | |
165 | Setting.bcc_recipients = '1' |
|
171 | Setting.bcc_recipients = '1' | |
166 |
|
172 | |||
167 | post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} |
|
173 | post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} | |
168 | assert u.reload.active? |
|
174 | assert u.reload.active? | |
169 | mail = ActionMailer::Base.deliveries.last |
|
175 | mail = ActionMailer::Base.deliveries.last | |
170 | assert_not_nil mail |
|
176 | assert_not_nil mail | |
171 | assert_equal ['foo.bar@somenet.foo'], mail.bcc |
|
177 | assert_equal ['foo.bar@somenet.foo'], mail.bcc | |
172 | assert mail.body.include?(ll('fr', :notice_account_activated)) |
|
178 | assert mail.body.include?(ll('fr', :notice_account_activated)) | |
173 | end |
|
179 | end | |
174 |
|
180 | |||
175 | def test_edit_with_password_change_should_send_a_notification |
|
181 | def test_edit_with_password_change_should_send_a_notification | |
176 | ActionMailer::Base.deliveries.clear |
|
182 | ActionMailer::Base.deliveries.clear | |
177 | Setting.bcc_recipients = '1' |
|
183 | Setting.bcc_recipients = '1' | |
178 |
|
184 | |||
179 | u = User.find(2) |
|
185 | u = User.find(2) | |
180 | post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' |
|
186 | post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' | |
181 | assert_equal User.hash_password('newpass'), u.reload.hashed_password |
|
187 | assert_equal User.hash_password('newpass'), u.reload.hashed_password | |
182 |
|
188 | |||
183 | mail = ActionMailer::Base.deliveries.last |
|
189 | mail = ActionMailer::Base.deliveries.last | |
184 | assert_not_nil mail |
|
190 | assert_not_nil mail | |
185 | assert_equal [u.mail], mail.bcc |
|
191 | assert_equal [u.mail], mail.bcc | |
186 | assert mail.body.include?('newpass') |
|
192 | assert mail.body.include?('newpass') | |
187 | end |
|
193 | end | |
188 |
|
194 | |||
189 | def test_add_membership_routing |
|
195 | def test_add_membership_routing | |
190 | assert_routing( |
|
196 | assert_routing( | |
191 | {:method => :post, :path => '/users/123/memberships'}, |
|
197 | {:method => :post, :path => '/users/123/memberships'}, | |
192 | :controller => 'users', :action => 'edit_membership', :id => '123' |
|
198 | :controller => 'users', :action => 'edit_membership', :id => '123' | |
193 | ) |
|
199 | ) | |
194 | end |
|
200 | end | |
195 |
|
201 | |||
196 | def test_edit_membership_routing |
|
202 | def test_edit_membership_routing | |
197 | assert_routing( |
|
203 | assert_routing( | |
198 | {:method => :post, :path => '/users/123/memberships/55'}, |
|
204 | {:method => :post, :path => '/users/123/memberships/55'}, | |
199 | :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' |
|
205 | :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' | |
200 | ) |
|
206 | ) | |
201 | end |
|
207 | end | |
202 |
|
208 | |||
203 | def test_edit_membership |
|
209 | def test_edit_membership | |
204 | post :edit_membership, :id => 2, :membership_id => 1, |
|
210 | post :edit_membership, :id => 2, :membership_id => 1, | |
205 | :membership => { :role_ids => [2]} |
|
211 | :membership => { :role_ids => [2]} | |
206 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
212 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
207 | assert_equal [2], Member.find(1).role_ids |
|
213 | assert_equal [2], Member.find(1).role_ids | |
208 | end |
|
214 | end | |
209 |
|
215 | |||
210 | def test_destroy_membership |
|
216 | def test_destroy_membership | |
211 | assert_routing( |
|
217 | assert_routing( | |
212 | #TODO: use DELETE method on user_membership_path, modify form |
|
218 | #TODO: use DELETE method on user_membership_path, modify form | |
213 | {:method => :post, :path => '/users/567/memberships/12/destroy'}, |
|
219 | {:method => :post, :path => '/users/567/memberships/12/destroy'}, | |
214 | :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' |
|
220 | :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' | |
215 | ) |
|
221 | ) | |
216 | end |
|
222 | end | |
217 |
|
223 | |||
218 | def test_destroy_membership |
|
224 | def test_destroy_membership | |
219 | post :destroy_membership, :id => 2, :membership_id => 1 |
|
225 | post :destroy_membership, :id => 2, :membership_id => 1 | |
220 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
226 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
221 | assert_nil Member.find_by_id(1) |
|
227 | assert_nil Member.find_by_id(1) | |
222 | end |
|
228 | end | |
223 | end |
|
229 | end |
General Comments 0
You need to be logged in to leave comments.
Login now