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