annotate .svn/pristine/f3/f388a468f7bcce147f8cf82b4b0549106c8cc56a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'documents_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class DocumentsController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class DocumentsControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = DocumentsController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 User.current = nil
Chris@909 32 end
Chris@909 33
Chris@909 34 def test_index
Chris@909 35 # Sets a default category
Chris@909 36 e = Enumeration.find_by_name('Technical documentation')
Chris@909 37 e.update_attributes(:is_default => true)
Chris@909 38
Chris@909 39 get :index, :project_id => 'ecookbook'
Chris@909 40 assert_response :success
Chris@909 41 assert_template 'index'
Chris@909 42 assert_not_nil assigns(:grouped)
Chris@909 43
Chris@909 44 # Default category selected in the new document form
Chris@909 45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
Chris@909 46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
Chris@909 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@909 52 end
Chris@909 53
Chris@909 54 def test_index_with_long_description
Chris@909 55 # adds a long description to the first document
Chris@909 56 doc = documents(:documents_001)
Chris@909 57 doc.update_attributes(:description => <<LOREM)
Chris@909 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@909 59
Chris@909 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@909 61 LOREM
Chris@909 62
Chris@909 63 get :index, :project_id => 'ecookbook'
Chris@909 64 assert_response :success
Chris@909 65 assert_template 'index'
Chris@909 66
Chris@909 67 # should only truncate on new lines to avoid breaking wiki formatting
Chris@909 68 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
Chris@909 69 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
Chris@909 70 end
Chris@909 71
Chris@909 72 def test_new_with_one_attachment
Chris@909 73 ActionMailer::Base.deliveries.clear
Chris@909 74 Setting.notified_events << 'document_added'
Chris@909 75 @request.session[:user_id] = 2
Chris@909 76 set_tmp_attachments_directory
Chris@909 77
Chris@909 78 post :new, :project_id => 'ecookbook',
Chris@909 79 :document => { :title => 'DocumentsControllerTest#test_post_new',
Chris@909 80 :description => 'This is a new document',
Chris@909 81 :category_id => 2},
Chris@909 82 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@909 83
Chris@909 84 assert_redirected_to '/projects/ecookbook/documents'
Chris@909 85
Chris@909 86 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
Chris@909 87 assert_not_nil document
Chris@909 88 assert_equal Enumeration.find(2), document.category
Chris@909 89 assert_equal 1, document.attachments.size
Chris@909 90 assert_equal 'testfile.txt', document.attachments.first.filename
Chris@909 91 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@909 92 end
Chris@909 93
Chris@909 94 def test_destroy
Chris@909 95 @request.session[:user_id] = 2
Chris@909 96 post :destroy, :id => 1
Chris@909 97 assert_redirected_to '/projects/ecookbook/documents'
Chris@909 98 assert_nil Document.find_by_id(1)
Chris@909 99 end
Chris@909 100 end