From 9b1e831fa67e88d9ae25670ee7ab7598b87b26b5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 16 Dec 2011 23:35:05 +0000 Subject: [PATCH] Change tests to use ruby/rails assertions. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8249 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/functional/account_controller_test.rb | 72 ++++++++++------------ test/test_helper.rb | 9 --- 2 files changed, 32 insertions(+), 49 deletions(-) diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 3226544e3..1adb92eea 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -161,33 +161,26 @@ class AccountControllerTest < ActionController::TestCase assert_nil @request.session[:user_id] end - context "GET #register" do - context "with self registration on" do - setup do - Setting.self_registration = '3' - get :register - end - - should_respond_with :success - should_render_template :register - should_assign_to :user + def test_get_register_with_registration_on + with_settings :self_registration => '3' do + get :register + assert_response :success + assert_template 'register' + assert_not_nil assigns(:user) end + end - context "with self registration off" do - setup do - Setting.self_registration = '0' - get :register - end - - should_redirect_to('/') { home_url } + def test_get_register_with_registration_off_should_redirect + with_settings :self_registration => '0' do + get :register + assert_redirected_to '/' end end # See integration/account_test.rb for the full test - context "POST #register" do - context "with self registration on automatic" do - setup do - Setting.self_registration = '3' + def test_post_register_with_registration_on + with_settings :self_registration => '3' do + assert_difference 'User.count' do post :register, :user => { :login => 'register', :password => 'test', @@ -196,28 +189,27 @@ class AccountControllerTest < ActionController::TestCase :lastname => 'Doe', :mail => 'register@example.com' } + assert_redirected_to '/my/account' end - - should_respond_with :redirect - should_assign_to :user - should_redirect_to('my page') { {:controller => 'my', :action => 'account'} } - - should_create_a_new_user { User.last(:conditions => {:login => 'register'}) } - - should 'set the user status to active' do - user = User.last(:conditions => {:login => 'register'}) - assert user - assert_equal User::STATUS_ACTIVE, user.status - end + user = User.first(:order => 'id DESC') + assert_equal 'register', user.login + assert user.active? end - - context "with self registration off" do - setup do - Setting.self_registration = '0' - post :register + end + + def test_post_register_with_registration_off_should_redirect + with_settings :self_registration => '0' do + assert_no_difference 'User.count' do + post :register, :user => { + :login => 'register', + :password => 'test', + :password_confirmation => 'test', + :firstname => 'John', + :lastname => 'Doe', + :mail => 'register@example.com' + } + assert_redirected_to '/' end - - should_redirect_to('/') { home_url } end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7ff3434be..09d9c3bb0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -207,15 +207,6 @@ class ActiveSupport::TestCase end end - def self.should_create_a_new_user(&block) - should "create a new user" do - user = instance_eval &block - assert user - assert_kind_of User, user - assert !user.new_record? - end - end - # Test that a request allows the three types of API authentication # # * HTTP Basic with username and password