require File.dirname(__FILE__) + '/../test_helper' require 'patches_controller' # Re-raise errors caught by the controller. class PatchesController; def rescue_action(e) raise e end; end class PatchesControllerTest < Test::Unit::TestCase fixtures :roles, :users, :roles_users, :patches, :programs def setup @controller = PatchesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_index get :index assert_response :success assert_template 'index' assert_not_nil assigns(:latest_unapplied_patches) end def test_list get :list assert_response :success assert_template 'list' assert_not_nil assigns(:patches) end def test_show get :show, :id => 1 assert_response :success assert_template 'edit' assert_not_nil assigns(:patch) assert assigns(:patch).valid? end def test_add_item num_patches = Patch.count create_session 'admin' post :add_item, :new_item => {:filename => 'some_silly_test_patch.diff', :title => 'First Patch Test', :program_id => 1, :description => 'Some Patch Test To Do/Fix Something'}, :new_item_version => {:for_upstream_version => '1.0'}, :patch_file => fixture_file_upload('/files/some_silly_test_patch.diff', 'text/plain') assert_response :redirect assert_redirected_to :action => 'show', :id => Patch.find(:first, :order => "created_at DESC").id assert_equal num_patches + 1, Patch.count end def test_add_item_unauthorized post :add_item, :new_item => {:filename => 'some_silly_test_patch.diff', :title => 'First Patch Test', :program_id => 1, :description => 'Some Patch Test To Do/Fix Something'}, :new_item_version => {:for_upstream_version => '1.0'}, :patch_file => fixture_file_upload('/files/some_silly_test_patch.diff', 'text/plain') assert_response :redirect assert_redirected_to {} assert(flash[:notice] =~ /log/) end def test_edit get :edit, :id => 1 assert_response :success assert_template 'edit' assert_not_nil assigns(:patch) assert assigns(:patch).valid? end def test_update create_session 'admin' post :update, :id => 1, :patch => {} assert_response :redirect assert_redirected_to :action => 'show', :id => 1 end def test_unapplied get :unapplied assert_response :success assert_template 'unapplied' assert_not_nil assigns(:unapplied_patches) end def test_users_and_roles_links_admin create_session 'admin' get :index assert_response :success assert_template 'index' role_link = find_tag :tag => 'a', :attributes => { :alt => 'Roles' }, :content => 'Roles' assert(role_link) user_link = find_tag :tag => 'a', :attributes => { :alt => 'Users' }, :content => 'Users' assert(user_link) end def test_users_and_roles_links_developer create_session 'developer' get :index assert_response :success assert_template 'index' role_links = find_all_tag :tag => 'a', :attributes => { :alt => 'Roles' }, :content => 'Roles' assert(role_links.empty?) user_links = find_all_tag :tag => 'a', :attributes => { :alt => 'Users' }, :content => 'Users' assert(user_links.empty?) end def test_users_and_roles_links_non_logged_in get :index assert_response :success assert_template 'index' role_link = find_tag :tag => 'a', :attributes => { :alt => 'Roles' }, :content => 'Roles' assert_nil(role_link) user_link = find_tag :tag => 'a', :attributes => { :alt => 'Users' }, :content => 'Users' assert_nil(user_link) end protected def create_session(user_login) u = User.find_by_login(user_login) if u @request.session[:rbac_user_id] = u.id else raise ArgumentError, "Can't find user #{user_login}" end end end