cours0708/P5B/ruby/mon_projet/test/functional/utilisateurs_controller_test.rb

87 lines
2.6 KiB
Ruby
Raw Normal View History

2008-11-25 21:11:16 +00:00
require File.dirname(__FILE__) + '/../test_helper'
require 'utilisateurs_controller'
# Re-raise errors caught by the controller.
class UtilisateursController; def rescue_action(e) raise e end; end
class UtilisateursControllerTest < Test::Unit::TestCase
# Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
fixtures :utilisateurs
def setup
@controller = UtilisateursController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_should_allow_signup
assert_difference 'Utilisateur.count' do
create_utilisateur
assert_response :redirect
end
end
def test_should_require_login_on_signup
assert_no_difference 'Utilisateur.count' do
create_utilisateur(:login => nil)
assert assigns(:utilisateur).errors.on(:login)
assert_response :success
end
end
def test_should_require_password_on_signup
assert_no_difference 'Utilisateur.count' do
create_utilisateur(:password => nil)
assert assigns(:utilisateur).errors.on(:password)
assert_response :success
end
end
def test_should_require_password_confirmation_on_signup
assert_no_difference 'Utilisateur.count' do
create_utilisateur(:password_confirmation => nil)
assert assigns(:utilisateur).errors.on(:password_confirmation)
assert_response :success
end
end
def test_should_require_email_on_signup
assert_no_difference 'Utilisateur.count' do
create_utilisateur(:email => nil)
assert assigns(:utilisateur).errors.on(:email)
assert_response :success
end
end
def test_should_activate_user
assert_nil Utilisateur.authenticate('aaron', 'test')
get :activate, :activation_code => utilisateurs(:aaron).activation_code
assert_redirected_to '/'
assert_not_nil flash[:notice]
assert_equal utilisateurs(:aaron), Utilisateur.authenticate('aaron', 'test')
end
def test_should_not_activate_user_without_key
get :activate
assert_nil flash[:notice]
rescue ActionController::RoutingError
# in the event your routes deny this, we'll just bow out gracefully.
end
def test_should_not_activate_user_with_blank_key
get :activate, :activation_code => ''
assert_nil flash[:notice]
rescue ActionController::RoutingError
# well played, sir
end
protected
def create_utilisateur(options = {})
post :create, :utilisateur => { :login => 'quire', :email => 'quire@example.com',
:password => 'quire', :password_confirmation => 'quire' }.merge(options)
end
end