require File.dirname(__FILE__) + '/../test_helper' require 'payment_controller' # Re-raise errors caught by the controller. class PaymentController; def rescue_action(e) raise e end; end class PaymentControllerTest < Test::Unit::TestCase fixtures :accounts, :payments privileged_actions :list, :show, :edit, :update, :destroy, :new, :create def setup @controller = PaymentController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_index get :index assert_response :success assert_template 'index' end def test_how get :how assert_response :redirect assert_redirected_to :action => 'index' end def test_list put_admin get :list assert_response :success assert_template 'list' assert_not_nil assigns(:payments) end def test_show put_user get :show, :id => 1 assert_response :success assert_template 'show' assert_not_nil assigns(:payment) assert assigns(:payment).valid? end def test_new put_admin get :new assert_response :success assert_template 'new' assert_not_nil assigns(:payment) end def test_create_with_new_account put_admin new_account_login = 'newaccount@oaktop.com' num_payments = Payment.count post :create, :payment => {:medium => 'Check', :amount => '40'}, :lookup => new_account_login assert_response :redirect assert_redirected_to :action => 'new' assert_equal num_payments + 1, Payment.count assert_not_nil Account.find_by_login(new_account_login) end def test_edit put_admin get :edit, :id => 1 assert_response :success assert_template 'edit' assert_not_nil assigns(:payment) assert assigns(:payment).valid? end def test_update put_admin post :update, :id => 1 assert_response :redirect assert_redirected_to :action => 'show', :id => 1 end def test_destroy put_admin assert_not_nil Payment.find(1) post :destroy, :id => 1 assert_response :redirect assert_redirected_to :action => 'list' assert_raise(ActiveRecord::RecordNotFound) { Payment.find(1) } end end