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