You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

documents_controller_test.rb 7.5 kB

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

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...