comparison test/functional/documents_controller_test.rb @ 441:cbce1fd3b1b7 redmine-1.2

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