annotate test/functional/members_controller_test.rb @ 850:e9e53db0c93a bug_213

Close obsolete branch bug_213
author Chris Cannam
date Sat, 13 Aug 2011 14:51:48 +0100
parents af80e5618e9b
children cbb26bc654de
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@117 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'members_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class MembersController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24
Chris@0 25 class MembersControllerTest < ActionController::TestCase
Chris@0 26 fixtures :projects, :members, :member_roles, :roles, :users
Chris@0 27
Chris@0 28 def setup
Chris@0 29 @controller = MembersController.new
Chris@0 30 @request = ActionController::TestRequest.new
Chris@0 31 @response = ActionController::TestResponse.new
Chris@0 32 User.current = nil
Chris@0 33 @request.session[:user_id] = 2
Chris@0 34 end
Chris@0 35
Chris@0 36 def test_create
Chris@0 37 assert_difference 'Member.count' do
Chris@0 38 post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7}
Chris@0 39 end
Chris@0 40 assert_redirected_to '/projects/ecookbook/settings/members'
Chris@0 41 assert User.find(7).member_of?(Project.find(1))
Chris@0 42 end
Chris@0 43
Chris@0 44 def test_create_multiple
Chris@0 45 assert_difference 'Member.count', 3 do
Chris@0 46 post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
Chris@0 47 end
Chris@0 48 assert_redirected_to '/projects/ecookbook/settings/members'
Chris@0 49 assert User.find(7).member_of?(Project.find(1))
Chris@0 50 end
Chris@0 51
Chris@0 52 context "post :new in JS format" do
Chris@0 53 context "with successful saves" do
Chris@0 54 should "add membership for each user" do
Chris@0 55 post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
Chris@0 56
Chris@0 57 assert User.find(7).member_of?(Project.find(1))
Chris@0 58 assert User.find(8).member_of?(Project.find(1))
Chris@0 59 assert User.find(9).member_of?(Project.find(1))
Chris@0 60 end
Chris@0 61
Chris@0 62 should "replace the tab with RJS" do
Chris@0 63 post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
Chris@0 64
Chris@0 65 assert_select_rjs :replace_html, 'tab-content-members'
Chris@0 66 end
Chris@0 67
Chris@0 68 end
Chris@0 69
Chris@0 70 context "with a failed save" do
Chris@0 71 should "not replace the tab with RJS" do
Chris@0 72 post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
Chris@0 73
Chris@0 74 assert_select '#tab-content-members', 0
Chris@0 75 end
Chris@0 76
Chris@0 77 should "open an error message" do
Chris@0 78 post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
Chris@0 79
Chris@0 80 assert @response.body.match(/alert/i), "Alert message not sent"
Chris@0 81 end
Chris@0 82 end
Chris@0 83
Chris@0 84 end
Chris@0 85
Chris@0 86 def test_edit
Chris@0 87 assert_no_difference 'Member.count' do
Chris@0 88 post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
Chris@0 89 end
Chris@0 90 assert_redirected_to '/projects/ecookbook/settings/members'
Chris@0 91 end
Chris@0 92
Chris@0 93 def test_destroy
Chris@0 94 assert_difference 'Member.count', -1 do
Chris@0 95 post :destroy, :id => 2
Chris@0 96 end
Chris@0 97 assert_redirected_to '/projects/ecookbook/settings/members'
Chris@0 98 assert !User.find(3).member_of?(Project.find(1))
Chris@0 99 end
Chris@0 100
Chris@0 101 def test_autocomplete_for_member
Chris@0 102 get :autocomplete_for_member, :id => 1, :q => 'mis'
Chris@0 103 assert_response :success
Chris@0 104 assert_template 'autocomplete_for_member'
Chris@0 105
Chris@0 106 assert_tag :label, :content => /User Misc/,
Chris@0 107 :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
Chris@0 108 end
Chris@0 109 end