annotate test/functional/documents_controller_test.rb @ 1472:f0b798dad2d6 feature_526

Close obsolete branch feature_526
author Chris Cannam
date Tue, 20 Nov 2012 19:45:51 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'documents_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class DocumentsController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class DocumentsControllerTest < ActionController::TestCase
Chris@0 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
Chris@441 26
Chris@0 27 def setup
Chris@0 28 @controller = DocumentsController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @response = ActionController::TestResponse.new
Chris@0 31 User.current = nil
Chris@0 32 end
Chris@441 33
Chris@0 34 def test_index
Chris@0 35 # Sets a default category
Chris@0 36 e = Enumeration.find_by_name('Technical documentation')
Chris@0 37 e.update_attributes(:is_default => true)
Chris@441 38
Chris@0 39 get :index, :project_id => 'ecookbook'
Chris@0 40 assert_response :success
Chris@0 41 assert_template 'index'
Chris@0 42 assert_not_nil assigns(:grouped)
Chris@441 43
Chris@0 44 # Default category selected in the new document form
Chris@0 45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
Chris@0 46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
Chris@0 47 :content => 'Technical documentation'}
Chris@909 48
Chris@909 49 assert ! DocumentCategory.find(16).active?
Chris@909 50 assert_no_tag :option, :attributes => {:value => '16'},
Chris@909 51 :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
Chris@0 52 end
Chris@441 53
Chris@0 54 def test_index_with_long_description
Chris@0 55 # adds a long description to the first document
Chris@0 56 doc = documents(:documents_001)
Chris@0 57 doc.update_attributes(:description => <<LOREM)
Chris@0 58 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra. Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
Chris@0 59
Chris@0 60 Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Chris@0 61 LOREM
Chris@441 62
Chris@0 63 get :index, :project_id => 'ecookbook'
Chris@0 64 assert_response :success
Chris@0 65 assert_template 'index'
Chris@0 66
Chris@0 67 # should only truncate on new lines to avoid breaking wiki formatting
Chris@0 68 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
Chris@0 69 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
Chris@0 70 end
Chris@441 71
Chris@0 72 def test_new_with_one_attachment
Chris@0 73 ActionMailer::Base.deliveries.clear
Chris@0 74 Setting.notified_events << 'document_added'
Chris@0 75 @request.session[:user_id] = 2
Chris@0 76 set_tmp_attachments_directory
Chris@441 77
Chris@0 78 post :new, :project_id => 'ecookbook',
Chris@0 79 :document => { :title => 'DocumentsControllerTest#test_post_new',
Chris@0 80 :description => 'This is a new document',
Chris@0 81 :category_id => 2},
Chris@0 82 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@441 83
chris@37 84 assert_redirected_to '/projects/ecookbook/documents'
Chris@441 85
Chris@0 86 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
Chris@0 87 assert_not_nil document
Chris@0 88 assert_equal Enumeration.find(2), document.category
Chris@0 89 assert_equal 1, document.attachments.size
Chris@0 90 assert_equal 'testfile.txt', document.attachments.first.filename
Chris@0 91 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 92 end
Chris@441 93
Chris@0 94 def test_destroy
Chris@0 95 @request.session[:user_id] = 2
Chris@0 96 post :destroy, :id => 1
chris@37 97 assert_redirected_to '/projects/ecookbook/documents'
Chris@0 98 assert_nil Document.find_by_id(1)
Chris@0 99 end
Chris@0 100 end