require File.dirname(__FILE__) + '/../test_helper' require 'chip_types_controller' # Re-raise errors caught by the controller. class ChipTypesController; def rescue_action(e) raise e end; end class ChipTypesControllerTest < Test::Unit::TestCase fixtures :chip_types, :chip_transactions, :users, :organisms def setup @controller = ChipTypesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new # chip type management is only accessible to admins # so use that login for all tests login_as_admin end def test_index get :index assert_response :success assert_template 'list' end def test_list get :list assert_response :success assert_template 'list' assert_not_nil assigns(:chip_types) end def test_new get :new assert_response :success assert_template 'new' assert_not_nil assigns(:chip_type) end def test_create num_chip_types = ChipType.count post :create, :chip_type => {:name => "Chippy", :short_name => "chpy", :organism_id => organisms(:first).id, :array_platform => "affy"} assert_response :redirect assert_redirected_to :action => 'list' assert_equal num_chip_types + 1, ChipType.count end def test_edit get :edit, :id => chip_types(:mouse).id assert_response :success assert_template 'edit' assert_not_nil assigns(:chip_type) assert assigns(:chip_type).valid? end def test_update post :update, :id => chip_types(:mouse).id assert_response :redirect assert_redirected_to :action => 'list', :id => chip_types(:mouse).id end def test_update_locked # grab the chip_type we're going to use twice chip_type1 = chip_types(:mouse) chip_type2 = chip_types(:mouse) # update it once, which should sucess post :update, :id => chip_types(:mouse).id, :chip_type => { :name => "chip type1", :lock_version => chip_type1.lock_version } # and then update again with stale info, and it should fail post :update, :id => chip_types(:mouse).id, :chip_type => { :name => "chip type2", :lock_version => chip_type2.lock_version } assert_response :success assert_template 'edit' assert_flash_warning assert_equal "chip type1", ChipType.find( chip_types(:mouse) ).name end def test_destroy_no_associated_transactions assert_not_nil ChipType.find( chip_types(:mouse).id ) post :destroy, :id => chip_types(:mouse).id assert_response :redirect assert_redirected_to :action => 'list' assert_raise(ActiveRecord::RecordNotFound) { ChipType.find( chip_types(:mouse).id ) } end def test_destroy_with_associated_transactions assert_not_nil ChipType.find( chip_types(:alligator).id ) post :destroy, :id => chip_types(:alligator).id assert_response :redirect assert_redirected_to :action => 'list' assert_raise(ActiveRecord::RecordNotFound) { ChipType.find( chip_types(:alligator).id ) } end end