members_controller_test.rb
109 lines
| 3.7 KiB
| text/x-ruby
|
RubyLexer
|
r2477 | # Redmine - project management software | ||
|
r6786 | # Copyright (C) 2006-2011 Jean-Philippe Lang | ||
|
r2477 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
|
r6786 | # | ||
|
r2477 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r6786 | # | ||
|
r2477 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|
r4395 | require File.expand_path('../../test_helper', __FILE__) | ||
|
r2315 | require 'members_controller' | ||
# Re-raise errors caught by the controller. | ||||
class MembersController; def rescue_action(e) raise e end; end | ||||
|
r2773 | class MembersControllerTest < ActionController::TestCase | ||
|
r2627 | fixtures :projects, :members, :member_roles, :roles, :users | ||
|
r6786 | |||
|
r2477 | def setup | ||
@controller = MembersController.new | ||||
@request = ActionController::TestRequest.new | ||||
@response = ActionController::TestResponse.new | ||||
User.current = nil | ||||
@request.session[:user_id] = 2 | ||||
end | ||||
|
r6786 | |||
|
r2546 | def test_create | ||
|
r2477 | assert_difference 'Member.count' do | ||
|
r2627 | post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7} | ||
|
r2477 | end | ||
assert_redirected_to '/projects/ecookbook/settings/members' | ||||
assert User.find(7).member_of?(Project.find(1)) | ||||
end | ||||
|
r6786 | |||
|
r2546 | def test_create_multiple | ||
assert_difference 'Member.count', 3 do | ||||
|
r2627 | post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | ||
|
r2546 | end | ||
assert_redirected_to '/projects/ecookbook/settings/members' | ||||
assert User.find(7).member_of?(Project.find(1)) | ||||
end | ||||
|
r3635 | |||
context "post :new in JS format" do | ||||
context "with successful saves" do | ||||
should "add membership for each user" do | ||||
post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | ||||
assert User.find(7).member_of?(Project.find(1)) | ||||
assert User.find(8).member_of?(Project.find(1)) | ||||
assert User.find(9).member_of?(Project.find(1)) | ||||
end | ||||
|
r6786 | |||
|
r3635 | should "replace the tab with RJS" do | ||
post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]} | ||||
assert_select_rjs :replace_html, 'tab-content-members' | ||||
end | ||||
|
r6786 | |||
|
r3635 | end | ||
context "with a failed save" do | ||||
should "not replace the tab with RJS" do | ||||
post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} | ||||
assert_select '#tab-content-members', 0 | ||||
end | ||||
|
r6786 | |||
|
r3635 | should "open an error message" do | ||
post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} | ||||
assert @response.body.match(/alert/i), "Alert message not sent" | ||||
end | ||||
end | ||||
end | ||||
|
r6786 | |||
|
r2477 | def test_edit | ||
assert_no_difference 'Member.count' do | ||||
|
r2627 | post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3} | ||
|
r2477 | end | ||
assert_redirected_to '/projects/ecookbook/settings/members' | ||||
end | ||||
|
r6786 | |||
|
r2477 | def test_destroy | ||
assert_difference 'Member.count', -1 do | ||||
post :destroy, :id => 2 | ||||
end | ||||
assert_redirected_to '/projects/ecookbook/settings/members' | ||||
assert !User.find(3).member_of?(Project.find(1)) | ||||
end | ||||
|
r6786 | |||
|
r2755 | def test_autocomplete_for_member | ||
get :autocomplete_for_member, :id => 1, :q => 'mis' | ||||
|
r2549 | assert_response :success | ||
|
r2755 | assert_template 'autocomplete_for_member' | ||
|
r6786 | |||
|
r2755 | assert_tag :label, :content => /User Misc/, | ||
:child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } } | ||||
|
r2549 | end | ||
|
r2315 | end | ||