To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 21 / 217d8edc342d8c96ea1e479a7157b0c862da5448.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (3.75 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
require File.expand_path('../../test_helper', __FILE__)
19
require 'members_controller'
20

    
21
# Re-raise errors caught by the controller.
22
class MembersController; def rescue_action(e) raise e end; end
23

    
24

    
25
class MembersControllerTest < ActionController::TestCase
26
  fixtures :projects, :members, :member_roles, :roles, :users
27

    
28
  def setup
29
    @controller = MembersController.new
30
    @request    = ActionController::TestRequest.new
31
    @response   = ActionController::TestResponse.new
32
    User.current = nil
33
    @request.session[:user_id] = 2
34
  end
35

    
36
  def test_create
37
    assert_difference 'Member.count' do
38
      post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7}
39
    end
40
    assert_redirected_to '/projects/ecookbook/settings/members'
41
    assert User.find(7).member_of?(Project.find(1))
42
  end
43

    
44
  def test_create_multiple
45
    assert_difference 'Member.count', 3 do
46
      post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
47
    end
48
    assert_redirected_to '/projects/ecookbook/settings/members'
49
    assert User.find(7).member_of?(Project.find(1))
50
  end
51

    
52
  def test_xhr_create
53
    assert_difference 'Member.count', 3 do
54
      post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
55
    end
56
    assert_select_rjs :replace_html, 'tab-content-members'
57
    assert User.find(7).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))
60
  end
61

    
62
  def test_xhr_create_with_failure
63
    assert_no_difference 'Member.count' do
64
      post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
65
    end
66
    assert_select '#tab-content-members', 0
67
    assert @response.body.match(/alert/i), "Alert message not sent"
68
  end
69

    
70
  def test_edit
71
    assert_no_difference 'Member.count' do
72
      post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
73
    end
74
    assert_redirected_to '/projects/ecookbook/settings/members'
75
  end
76

    
77
  def test_xhr_edit
78
    assert_no_difference 'Member.count' do
79
      xhr :post, :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
80
    end
81
    assert_select_rjs :replace_html, 'tab-content-members'
82
    member = Member.find(2)
83
    assert_equal [1], member.role_ids
84
    assert_equal 3, member.user_id
85
  end
86

    
87
  def test_destroy
88
    assert_difference 'Member.count', -1 do
89
      post :destroy, :id => 2
90
    end
91
    assert_redirected_to '/projects/ecookbook/settings/members'
92
    assert !User.find(3).member_of?(Project.find(1))
93
  end
94

    
95
  def test_xhr_destroy
96
    assert_difference 'Member.count', -1 do
97
      xhr :post, :destroy, :id => 2
98
    end
99
    assert_select_rjs :replace_html, 'tab-content-members'
100
  end
101

    
102
  def test_autocomplete_for_member
103
    get :autocomplete_for_member, :id => 1, :q => 'mis'
104
    assert_response :success
105
    assert_template 'autocomplete_for_member'
106

    
107
    assert_tag :label, :content => /User Misc/,
108
                       :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
109
  end
110
end