require File.dirname(__FILE__) + '/../test_helper' require 'works_controller' # Re-raise errors caught by the controller. class WorksController; def rescue_action(e) raise e end; end class WorksControllerTest < Test::Unit::TestCase fixtures :parties, :users, :groups, :groups_users, :work_accounts, :backlogs, :periods, :tasks, :task_files, :works, :estimates def setup @controller = WorksController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @request.session[:user_id] = 1000001 assert_sequences end def teardown assert_sequences 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(:works) end def test_show get :show, :id => 1 assert_response :success assert_template 'show' assert_not_nil assigns(:work) assert assigns(:work).valid? end def test_new get :new, :work => {:task_id => 1} assert_response :success assert_template 'new' assert_not_nil assigns(:work) end def test_create num_works = Work.count post :create, :work => {:task_id => 1, :started_at => Time.now.iso8601, :work_account_id => '1'} assert_response :redirect assert_redirected_to :controller => 'periods', :action => 'show', :id => periods(:past).id, :task_id => 1 assert_equal num_works + 1, Work.count end def test_edit get :edit, :id => 1 assert_response :success assert_template 'edit' assert_not_nil assigns(:work) assert assigns(:work).valid? end def test_update post :update, :id => 1 assert_response :redirect assert_redirected_to :controller => 'periods', :action => 'show', :id => periods(:past).id end def test_destroy assert_not_nil Work.find(1) post :destroy, :id => 1 assert_response :redirect assert_redirected_to :controller => 'periods', :action => 'list_work' assert_raise(ActiveRecord::RecordNotFound) { Work.find(1) } end def test_update_with_finish num_tasks = Task.count num_open_tasks = Task.find_open.size task = tasks(:started) work = works(:started) post :update, "commit"=>"Lagre", "action"=>"update", "id"=>work.id.to_s, "controller"=>"works", "estimate"=>{"todo"=>"0"}, "work"=>{"completed_at"=>"2007-08-02 14:15", "task_id"=> task.id.to_s, "user_id"=>"1000001", "started_at"=>"2007-08-02 14:00"} assert_response :redirect assert_redirected_to :controller => 'periods', :action => :show, :id => task.period, :task => nil assert_equal num_tasks, Task.count assert_equal num_open_tasks - 1, Task.find_open.size end def test_weekly_work_sheet get :weekly_work_sheet, :id => 24 end end