comparison .svn/pristine/f3/f3202e275b36fcaa2493cbc5897c69215e65214b.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class DocumentsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :roles, :members, :member_roles,
22 :enabled_modules, :documents, :enumerations,
23 :groups_users, :attachments
24
25 def setup
26 User.current = nil
27 end
28
29 def test_index
30 # Sets a default category
31 e = Enumeration.find_by_name('Technical documentation')
32 e.update_attributes(:is_default => true)
33
34 get :index, :project_id => 'ecookbook'
35 assert_response :success
36 assert_template 'index'
37 assert_not_nil assigns(:grouped)
38
39 # Default category selected in the new document form
40 assert_tag :select, :attributes => {:name => 'document[category_id]'},
41 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
42 :content => 'Technical documentation'}
43
44 assert ! DocumentCategory.find(16).active?
45 assert_no_tag :option, :attributes => {:value => '16'},
46 :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
47 end
48
49 def test_index_grouped_by_date
50 get :index, :project_id => 'ecookbook', :sort_by => 'date'
51 assert_response :success
52 assert_tag 'h3', :content => '2007-02-12'
53 end
54
55 def test_index_grouped_by_title
56 get :index, :project_id => 'ecookbook', :sort_by => 'title'
57 assert_response :success
58 assert_tag 'h3', :content => 'T'
59 end
60
61 def test_index_grouped_by_author
62 get :index, :project_id => 'ecookbook', :sort_by => 'author'
63 assert_response :success
64 assert_tag 'h3', :content => 'John Smith'
65 end
66
67 def test_index_with_long_description
68 # adds a long description to the first document
69 doc = documents(:documents_001)
70 doc.update_attributes(:description => <<LOREM)
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
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 LOREM
75
76 get :index, :project_id => 'ecookbook'
77 assert_response :success
78 assert_template 'index'
79
80 # should only truncate on new lines to avoid breaking wiki formatting
81 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
82 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
83 end
84
85 def test_show
86 get :show, :id => 1
87 assert_response :success
88 assert_template 'show'
89 end
90
91 def test_new
92 @request.session[:user_id] = 2
93 get :new, :project_id => 1
94 assert_response :success
95 assert_template 'new'
96 end
97
98 def test_create_with_one_attachment
99 ActionMailer::Base.deliveries.clear
100 @request.session[:user_id] = 2
101 set_tmp_attachments_directory
102
103 with_settings :notified_events => %w(document_added) do
104 post :create, :project_id => 'ecookbook',
105 :document => { :title => 'DocumentsControllerTest#test_post_new',
106 :description => 'This is a new document',
107 :category_id => 2},
108 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
109 end
110 assert_redirected_to '/projects/ecookbook/documents'
111
112 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
113 assert_not_nil document
114 assert_equal Enumeration.find(2), document.category
115 assert_equal 1, document.attachments.size
116 assert_equal 'testfile.txt', document.attachments.first.filename
117 assert_equal 1, ActionMailer::Base.deliveries.size
118 end
119
120 def test_create_with_failure
121 @request.session[:user_id] = 2
122 assert_no_difference 'Document.count' do
123 post :create, :project_id => 'ecookbook', :document => { :title => ''}
124 end
125 assert_response :success
126 assert_template 'new'
127 end
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
146 def test_edit
147 @request.session[:user_id] = 2
148 get :edit, :id => 1
149 assert_response :success
150 assert_template 'edit'
151 end
152
153 def test_update
154 @request.session[:user_id] = 2
155 put :update, :id => 1, :document => {:title => 'test_update'}
156 assert_redirected_to '/documents/1'
157 document = Document.find(1)
158 assert_equal 'test_update', document.title
159 end
160
161 def test_update_with_failure
162 @request.session[:user_id] = 2
163 put :update, :id => 1, :document => {:title => ''}
164 assert_response :success
165 assert_template 'edit'
166 end
167
168 def test_destroy
169 @request.session[:user_id] = 2
170 assert_difference 'Document.count', -1 do
171 delete :destroy, :id => 1
172 end
173 assert_redirected_to '/projects/ecookbook/documents'
174 assert_nil Document.find_by_id(1)
175 end
176
177 def test_add_attachment
178 @request.session[:user_id] = 2
179 assert_difference 'Attachment.count' do
180 post :add_attachment, :id => 1,
181 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
182 end
183 attachment = Attachment.first(:order => 'id DESC')
184 assert_equal Document.find(1), attachment.container
185 end
186 end