Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@441: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@441: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: require 'documents_controller' Chris@0: Chris@0: # Re-raise errors caught by the controller. Chris@0: class DocumentsController; def rescue_action(e) raise e end; end Chris@0: Chris@0: class DocumentsControllerTest < ActionController::TestCase Chris@0: fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations Chris@441: Chris@0: def setup Chris@0: @controller = DocumentsController.new Chris@0: @request = ActionController::TestRequest.new Chris@0: @response = ActionController::TestResponse.new Chris@0: User.current = nil Chris@0: end Chris@441: Chris@0: def test_index Chris@0: # Sets a default category Chris@0: e = Enumeration.find_by_name('Technical documentation') Chris@0: e.update_attributes(:is_default => true) Chris@441: Chris@0: get :index, :project_id => 'ecookbook' Chris@0: assert_response :success Chris@0: assert_template 'index' Chris@0: assert_not_nil assigns(:grouped) Chris@441: Chris@0: # Default category selected in the new document form Chris@0: assert_tag :select, :attributes => {:name => 'document[category_id]'}, Chris@0: :child => {:tag => 'option', :attributes => {:selected => 'selected'}, Chris@0: :content => 'Technical documentation'} Chris@909: Chris@909: assert ! DocumentCategory.find(16).active? Chris@909: assert_no_tag :option, :attributes => {:value => '16'}, Chris@909: :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} } Chris@0: end Chris@441: Chris@0: def test_index_with_long_description Chris@0: # adds a long description to the first document Chris@0: doc = documents(:documents_001) Chris@0: doc.update_attributes(:description => < 'ecookbook' Chris@0: assert_response :success Chris@0: assert_template 'index' Chris@0: Chris@0: # should only truncate on new lines to avoid breaking wiki formatting Chris@0: assert_select '.wiki p', :text => (doc.description.split("\n").first + '...') Chris@0: assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere...")) Chris@0: end Chris@441: Chris@0: def test_new_with_one_attachment Chris@0: ActionMailer::Base.deliveries.clear Chris@0: Setting.notified_events << 'document_added' Chris@0: @request.session[:user_id] = 2 Chris@0: set_tmp_attachments_directory Chris@441: Chris@0: post :new, :project_id => 'ecookbook', Chris@0: :document => { :title => 'DocumentsControllerTest#test_post_new', Chris@0: :description => 'This is a new document', Chris@0: :category_id => 2}, Chris@0: :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} Chris@441: chris@37: assert_redirected_to '/projects/ecookbook/documents' Chris@441: Chris@0: document = Document.find_by_title('DocumentsControllerTest#test_post_new') Chris@0: assert_not_nil document Chris@0: assert_equal Enumeration.find(2), document.category Chris@0: assert_equal 1, document.attachments.size Chris@0: assert_equal 'testfile.txt', document.attachments.first.filename Chris@0: assert_equal 1, ActionMailer::Base.deliveries.size Chris@0: end Chris@441: Chris@0: def test_destroy Chris@0: @request.session[:user_id] = 2 Chris@0: post :destroy, :id => 1 chris@37: assert_redirected_to '/projects/ecookbook/documents' Chris@0: assert_nil Document.find_by_id(1) Chris@0: end Chris@0: end