require File.dirname(__FILE__) + '/../test_helper' require 'directory_controller' # Re-raise errors caught by the controller. class DirectoryController; def rescue_action(e) raise e end; end class DirectoryControllerTest < Test::Unit::TestCase privileged_actions :remove, :edit, :freshen def setup @controller = DirectoryController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_html get :html assert_response :success assert_template 'html' end def test_show get :show, :id => 1 assert_response :success end def test_index get :index assert_response :success end def test_list get :list assert_response :success end def test_edit put_user get :edit, :id => 1 assert_response :success end def test_create put_user company_name = 'Company X' post :create, :company => {:name => company_name, :url => 'http://xyz.com/'} assert_redirected_to :action => 'show' company = Company.find_by_name company_name assert_not_nil company assert_equal session[:user], company.account end def test_new put_user user = @request.session[:user] user.company = Company.new user.company.name = 'ABC Company' user.company.url = 'http://www.example.com' assert user.company.save assert user.save get :new assert_redirected_to :action => 'edit' end def test_freshen put_user old_name = Company.find(1).name new_name = 'Company Z' new_url = 'http://z.com' post :freshen, :id => 1, :company => {:name => new_name, :url => new_url} assert_redirected_to :action => 'show' company = Company.find 1 assert_not_nil company assert_equal new_name, company.name assert_equal new_url, company.url assert_nil Company.find_by_name(old_name) end def test_remove put_user old_company_name = Company.find(1).name post :remove, :id => 1 assert_redirected_to :action => 'list' assert_nil Company.find_by_name(old_company_name) end end