##// END OF EJS Templates
Merged r10219 from trunk to 2.0-stable (#11665)...
Toshi MARUYAMA -
r10046:004a98df8662
parent child
Show More
@@ -1,169 +1,186
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 19
20 20 class DocumentsControllerTest < ActionController::TestCase
21 21 fixtures :projects, :users, :roles, :members, :member_roles,
22 22 :enabled_modules, :documents, :enumerations,
23 23 :groups_users, :attachments
24 24
25 25 def setup
26 26 User.current = nil
27 27 end
28 28
29 29 def test_index
30 30 # Sets a default category
31 31 e = Enumeration.find_by_name('Technical documentation')
32 32 e.update_attributes(:is_default => true)
33 33
34 34 get :index, :project_id => 'ecookbook'
35 35 assert_response :success
36 36 assert_template 'index'
37 37 assert_not_nil assigns(:grouped)
38 38
39 39 # Default category selected in the new document form
40 40 assert_tag :select, :attributes => {:name => 'document[category_id]'},
41 41 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
42 42 :content => 'Technical documentation'}
43 43
44 44 assert ! DocumentCategory.find(16).active?
45 45 assert_no_tag :option, :attributes => {:value => '16'},
46 46 :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
47 47 end
48 48
49 49 def test_index_grouped_by_date
50 50 get :index, :project_id => 'ecookbook', :sort_by => 'date'
51 51 assert_response :success
52 52 assert_tag 'h3', :content => '2007-02-12'
53 53 end
54 54
55 55 def test_index_grouped_by_title
56 56 get :index, :project_id => 'ecookbook', :sort_by => 'title'
57 57 assert_response :success
58 58 assert_tag 'h3', :content => 'T'
59 59 end
60 60
61 61 def test_index_grouped_by_author
62 62 get :index, :project_id => 'ecookbook', :sort_by => 'author'
63 63 assert_response :success
64 64 assert_tag 'h3', :content => 'John Smith'
65 65 end
66 66
67 67 def test_index_with_long_description
68 68 # adds a long description to the first document
69 69 doc = documents(:documents_001)
70 70 doc.update_attributes(:description => <<LOREM)
71 71 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
72 72
73 73 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.
74 74 LOREM
75 75
76 76 get :index, :project_id => 'ecookbook'
77 77 assert_response :success
78 78 assert_template 'index'
79 79
80 80 # should only truncate on new lines to avoid breaking wiki formatting
81 81 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
82 82 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
83 83 end
84 84
85 85 def test_show
86 86 get :show, :id => 1
87 87 assert_response :success
88 88 assert_template 'show'
89 89 end
90 90
91 91 def test_new
92 92 @request.session[:user_id] = 2
93 93 get :new, :project_id => 1
94 94 assert_response :success
95 95 assert_template 'new'
96 96 end
97 97
98 98 def test_create_with_one_attachment
99 99 ActionMailer::Base.deliveries.clear
100 100 Setting.notified_events << 'document_added'
101 101 @request.session[:user_id] = 2
102 102 set_tmp_attachments_directory
103 103
104 104 post :create, :project_id => 'ecookbook',
105 105 :document => { :title => 'DocumentsControllerTest#test_post_new',
106 106 :description => 'This is a new document',
107 107 :category_id => 2},
108 108 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
109 109
110 110 assert_redirected_to '/projects/ecookbook/documents'
111 111
112 112 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
113 113 assert_not_nil document
114 114 assert_equal Enumeration.find(2), document.category
115 115 assert_equal 1, document.attachments.size
116 116 assert_equal 'testfile.txt', document.attachments.first.filename
117 117 assert_equal 1, ActionMailer::Base.deliveries.size
118 118 end
119 119
120 120 def test_create_with_failure
121 121 @request.session[:user_id] = 2
122 122 assert_no_difference 'Document.count' do
123 123 post :create, :project_id => 'ecookbook', :document => { :title => ''}
124 124 end
125 125 assert_response :success
126 126 assert_template 'new'
127 127 end
128 128
129 def test_create_non_default_category
130 @request.session[:user_id] = 2
131 category2 = Enumeration.find_by_name('User documentation')
132 category2.update_attributes(:is_default => true)
133 category1 = Enumeration.find_by_name('Uncategorized')
134 post :create,
135 :project_id => 'ecookbook',
136 :document => { :title => 'no default',
137 :description => 'This is a new document',
138 :category_id => category1.id }
139 assert_redirected_to '/projects/ecookbook/documents'
140 doc = Document.find_by_title('no default')
141 assert_not_nil doc
142 assert_equal category1.id, doc.category_id
143 assert_equal category1, doc.category
144 end
145
129 146 def test_edit
130 147 @request.session[:user_id] = 2
131 148 get :edit, :id => 1
132 149 assert_response :success
133 150 assert_template 'edit'
134 151 end
135 152
136 153 def test_update
137 154 @request.session[:user_id] = 2
138 155 put :update, :id => 1, :document => {:title => 'test_update'}
139 156 assert_redirected_to '/documents/1'
140 157 document = Document.find(1)
141 158 assert_equal 'test_update', document.title
142 159 end
143 160
144 161 def test_update_with_failure
145 162 @request.session[:user_id] = 2
146 163 put :update, :id => 1, :document => {:title => ''}
147 164 assert_response :success
148 165 assert_template 'edit'
149 166 end
150 167
151 168 def test_destroy
152 169 @request.session[:user_id] = 2
153 170 assert_difference 'Document.count', -1 do
154 171 delete :destroy, :id => 1
155 172 end
156 173 assert_redirected_to '/projects/ecookbook/documents'
157 174 assert_nil Document.find_by_id(1)
158 175 end
159 176
160 177 def test_add_attachment
161 178 @request.session[:user_id] = 2
162 179 assert_difference 'Attachment.count' do
163 180 post :add_attachment, :id => 1,
164 181 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
165 182 end
166 183 attachment = Attachment.first(:order => 'id DESC')
167 184 assert_equal Document.find(1), attachment.container
168 185 end
169 186 end
General Comments 0
You need to be logged in to leave comments. Login now