admin_test.rb 2.05 KB
Newer Older
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# redMine - project management software
# Copyright (C) 2006  Jean-Philippe Lang
#
# 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.
# 
# 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.
# 
# 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.

require "#{File.dirname(__FILE__)}/../test_helper"

class AdminTest < ActionController::IntegrationTest
21
  fixtures :all
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
22 23 24

  def test_add_user
    log_user("admin", "admin")
25
    get "/users/new"
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
26
    assert_response :success
27
    assert_template "users/new"
28
    post "/users/create", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09"
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
29
    
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
30
    user = User.find_by_login("psmith")
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
31
    assert_kind_of User, user
32 33
    assert_redirected_to "/users/#{ user.id }/edit"
    
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
34
    logged_user = User.try_to_login("psmith", "psmith09")
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
35
    assert_kind_of User, logged_user
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
36
    assert_equal "Paul", logged_user.firstname
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
37
    
38
    put "users/#{user.id}", :id => user.id, :user => { :status => User::STATUS_LOCKED }
39
    assert_redirected_to "/users/#{ user.id }/edit"
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
40
    locked_user = User.try_to_login("psmith", "psmith09")
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
41 42
    assert_equal nil, locked_user
  end
43 44

  test "Add a user as an anonymous user should fail" do
45
    post '/users/create', :user => { :login => 'psmith', :firstname => 'Paul'}, :password => "psmith09", :password_confirmation => "psmith09"
46
    assert_response :redirect
47
    assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers"
48
  end
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
49
end