@@ -1,109 +1,109 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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 'members_controller' |
|
19 | require 'members_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class MembersController; def rescue_action(e) raise e end; end |
|
22 | class MembersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | class MembersControllerTest < ActionController::TestCase |
|
25 | class MembersControllerTest < ActionController::TestCase | |
26 | fixtures :projects, :members, :member_roles, :roles, :users |
|
26 | fixtures :projects, :members, :member_roles, :roles, :users | |
27 |
|
27 | |||
28 | def setup |
|
28 | def setup | |
29 | @controller = MembersController.new |
|
29 | @controller = MembersController.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 | @request.session[:user_id] = 2 |
|
33 | @request.session[:user_id] = 2 | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def test_create |
|
36 | def test_create | |
37 | assert_difference 'Member.count' do |
|
37 | assert_difference 'Member.count' do | |
38 | post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7} |
|
38 | post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7} | |
39 | end |
|
39 | end | |
40 | assert_redirected_to '/projects/ecookbook/settings/members' |
|
40 | assert_redirected_to '/projects/ecookbook/settings/members' | |
41 | assert User.find(7).member_of?(Project.find(1)) |
|
41 | assert User.find(7).member_of?(Project.find(1)) | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_create_multiple |
|
44 | def test_create_multiple | |
45 | assert_difference 'Member.count', 3 do |
|
45 | assert_difference 'Member.count', 3 do | |
46 | post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} |
|
46 | post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | |
47 | end |
|
47 | end | |
48 | assert_redirected_to '/projects/ecookbook/settings/members' |
|
48 | assert_redirected_to '/projects/ecookbook/settings/members' | |
49 | assert User.find(7).member_of?(Project.find(1)) |
|
49 | assert User.find(7).member_of?(Project.find(1)) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | context "post :new in JS format" do |
|
52 | context "post :new in JS format" do | |
53 | context "with successful saves" do |
|
53 | context "with successful saves" do | |
54 | should "add membership for each user" do |
|
54 | should "add membership for each user" do | |
55 | post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} |
|
55 | post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | |
56 |
|
56 | |||
57 | assert User.find(7).member_of?(Project.find(1)) |
|
57 | assert User.find(7).member_of?(Project.find(1)) | |
58 | assert User.find(8).member_of?(Project.find(1)) |
|
58 | assert User.find(8).member_of?(Project.find(1)) | |
59 | assert User.find(9).member_of?(Project.find(1)) |
|
59 | assert User.find(9).member_of?(Project.find(1)) | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | should "replace the tab with RJS" do |
|
62 | should "replace the tab with RJS" do | |
63 | post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} |
|
63 | post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | |
64 |
|
64 | |||
65 | assert_select_rjs :replace_html, 'tab-content-members' |
|
65 | assert_select_rjs :replace_html, 'tab-content-members' | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | context "with a failed save" do |
|
70 | context "with a failed save" do | |
71 | should "not replace the tab with RJS" do |
|
71 | should "not replace the tab with RJS" do | |
72 | post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} |
|
72 | post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} | |
73 |
|
73 | |||
74 | assert_select '#tab-content-members', 0 |
|
74 | assert_select '#tab-content-members', 0 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | should "open an error message" do |
|
77 | should "open an error message" do | |
78 | post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} |
|
78 | post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} | |
79 |
|
79 | |||
80 | assert @response.body.match(/alert/i), "Alert message not sent" |
|
80 | assert @response.body.match(/alert/i), "Alert message not sent" | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_edit |
|
86 | def test_edit | |
87 | assert_no_difference 'Member.count' do |
|
87 | assert_no_difference 'Member.count' do | |
88 | post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3} |
|
88 | post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3} | |
89 | end |
|
89 | end | |
90 | assert_redirected_to '/projects/ecookbook/settings/members' |
|
90 | assert_redirected_to '/projects/ecookbook/settings/members' | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_destroy |
|
93 | def test_destroy | |
94 | assert_difference 'Member.count', -1 do |
|
94 | assert_difference 'Member.count', -1 do | |
95 | post :destroy, :id => 2 |
|
95 | post :destroy, :id => 2 | |
96 | end |
|
96 | end | |
97 | assert_redirected_to '/projects/ecookbook/settings/members' |
|
97 | assert_redirected_to '/projects/ecookbook/settings/members' | |
98 | assert !User.find(3).member_of?(Project.find(1)) |
|
98 | assert !User.find(3).member_of?(Project.find(1)) | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | def test_autocomplete_for_member |
|
101 | def test_autocomplete_for_member | |
102 | get :autocomplete_for_member, :id => 1, :q => 'mis' |
|
102 | get :autocomplete_for_member, :id => 1, :q => 'mis' | |
103 | assert_response :success |
|
103 | assert_response :success | |
104 | assert_template 'autocomplete_for_member' |
|
104 | assert_template 'autocomplete_for_member' | |
105 |
|
105 | |||
106 | assert_tag :label, :content => /User Misc/, |
|
106 | assert_tag :label, :content => /User Misc/, | |
107 | :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } } |
|
107 | :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } } | |
108 | end |
|
108 | end | |
109 | end |
|
109 | end |
General Comments 0
You need to be logged in to leave comments.
Login now