##// END OF EJS Templates
Test class cleanup....
Jean-Philippe Lang -
r7886:e25caff16f06
parent child
Show More
@@ -1,151 +1,144
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'documents_controller'
20
21 # Re-raise errors caught by the controller.
22 class DocumentsController; def rescue_action(e) raise e end; end
23 19
24 20 class DocumentsControllerTest < ActionController::TestCase
25 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
26 22
27 23 def setup
28 @controller = DocumentsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 24 User.current = nil
32 25 end
33 26
34 27 def test_index
35 28 # Sets a default category
36 29 e = Enumeration.find_by_name('Technical documentation')
37 30 e.update_attributes(:is_default => true)
38 31
39 32 get :index, :project_id => 'ecookbook'
40 33 assert_response :success
41 34 assert_template 'index'
42 35 assert_not_nil assigns(:grouped)
43 36
44 37 # Default category selected in the new document form
45 38 assert_tag :select, :attributes => {:name => 'document[category_id]'},
46 39 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
47 40 :content => 'Technical documentation'}
48 41
49 42 assert ! DocumentCategory.find(16).active?
50 43 assert_no_tag :option, :attributes => {:value => '16'},
51 44 :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
52 45 end
53 46
54 47 def test_index_grouped_by_date
55 48 get :index, :project_id => 'ecookbook', :sort_by => 'date'
56 49 assert_response :success
57 50 assert_tag 'h3', :content => '2007-02-12'
58 51 end
59 52
60 53 def test_index_grouped_by_title
61 54 get :index, :project_id => 'ecookbook', :sort_by => 'title'
62 55 assert_response :success
63 56 assert_tag 'h3', :content => 'T'
64 57 end
65 58
66 59 def test_index_grouped_by_author
67 60 get :index, :project_id => 'ecookbook', :sort_by => 'author'
68 61 assert_response :success
69 62 assert_tag 'h3', :content => 'John Smith'
70 63 end
71 64
72 65 def test_index_with_long_description
73 66 # adds a long description to the first document
74 67 doc = documents(:documents_001)
75 68 doc.update_attributes(:description => <<LOREM)
76 69 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
77 70
78 71 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.
79 72 LOREM
80 73
81 74 get :index, :project_id => 'ecookbook'
82 75 assert_response :success
83 76 assert_template 'index'
84 77
85 78 # should only truncate on new lines to avoid breaking wiki formatting
86 79 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
87 80 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
88 81 end
89 82
90 83 def test_show
91 84 get :show, :id => 1
92 85 assert_response :success
93 86 assert_template 'show'
94 87 end
95 88
96 89 def test_new_with_one_attachment
97 90 ActionMailer::Base.deliveries.clear
98 91 Setting.notified_events << 'document_added'
99 92 @request.session[:user_id] = 2
100 93 set_tmp_attachments_directory
101 94
102 95 post :new, :project_id => 'ecookbook',
103 96 :document => { :title => 'DocumentsControllerTest#test_post_new',
104 97 :description => 'This is a new document',
105 98 :category_id => 2},
106 99 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
107 100
108 101 assert_redirected_to '/projects/ecookbook/documents'
109 102
110 103 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
111 104 assert_not_nil document
112 105 assert_equal Enumeration.find(2), document.category
113 106 assert_equal 1, document.attachments.size
114 107 assert_equal 'testfile.txt', document.attachments.first.filename
115 108 assert_equal 1, ActionMailer::Base.deliveries.size
116 109 end
117 110
118 111 def test_edit
119 112 @request.session[:user_id] = 2
120 113 get :edit, :id => 1
121 114 assert_response :success
122 115 assert_template 'edit'
123 116 end
124 117
125 118 def test_update
126 119 @request.session[:user_id] = 2
127 120 post :edit, :id => 1, :document => {:title => 'test_update'}
128 121 assert_redirected_to '/documents/1'
129 122 document = Document.find(1)
130 123 assert_equal 'test_update', document.title
131 124 end
132 125
133 126 def test_destroy
134 127 @request.session[:user_id] = 2
135 128 assert_difference 'Document.count', -1 do
136 129 post :destroy, :id => 1
137 130 end
138 131 assert_redirected_to '/projects/ecookbook/documents'
139 132 assert_nil Document.find_by_id(1)
140 133 end
141 134
142 135 def test_add_attachment
143 136 @request.session[:user_id] = 2
144 137 assert_difference 'Attachment.count' do
145 138 post :add_attachment, :id => 1,
146 139 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
147 140 end
148 141 attachment = Attachment.first(:order => 'id DESC')
149 142 assert_equal Document.find(1), attachment.container
150 143 end
151 144 end
General Comments 0
You need to be logged in to leave comments. Login now