diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb index 423faf6c9..77abc7efd 100644 --- a/test/functional/documents_controller_test.rb +++ b/test/functional/documents_controller_test.rb @@ -51,6 +51,24 @@ class DocumentsControllerTest < ActionController::TestCase :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} } end + def test_index_grouped_by_date + get :index, :project_id => 'ecookbook', :sort_by => 'date' + assert_response :success + assert_tag 'h3', :content => '2007-02-12' + end + + def test_index_grouped_by_title + get :index, :project_id => 'ecookbook', :sort_by => 'title' + assert_response :success + assert_tag 'h3', :content => 'T' + end + + def test_index_grouped_by_author + get :index, :project_id => 'ecookbook', :sort_by => 'author' + assert_response :success + assert_tag 'h3', :content => 'John Smith' + end + def test_index_with_long_description # adds a long description to the first document doc = documents(:documents_001) @@ -69,6 +87,12 @@ LOREM assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere...")) end + def test_show + get :show, :id => 1 + assert_response :success + assert_template 'show' + end + def test_new_with_one_attachment ActionMailer::Base.deliveries.clear Setting.notified_events << 'document_added' @@ -91,10 +115,37 @@ LOREM assert_equal 1, ActionMailer::Base.deliveries.size end + def test_edit + @request.session[:user_id] = 2 + get :edit, :id => 1 + assert_response :success + assert_template 'edit' + end + + def test_update + @request.session[:user_id] = 2 + post :edit, :id => 1, :document => {:title => 'test_update'} + assert_redirected_to '/documents/1' + document = Document.find(1) + assert_equal 'test_update', document.title + end + def test_destroy @request.session[:user_id] = 2 - post :destroy, :id => 1 + assert_difference 'Document.count', -1 do + post :destroy, :id => 1 + end assert_redirected_to '/projects/ecookbook/documents' assert_nil Document.find_by_id(1) end + + def test_add_attachment + @request.session[:user_id] = 2 + assert_difference 'Attachment.count' do + post :add_attachment, :id => 1, + :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} + end + attachment = Attachment.first(:order => 'id DESC') + assert_equal Document.find(1), attachment.container + end end