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

files_controller_test.rb 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 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 FilesControllerTest < ActionController::TestCase
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :journals, :journal_details,
  27. :attachments,
  28. :versions
  29. def setup
  30. @request.session[:user_id] = nil
  31. Setting.default_language = 'en'
  32. end
  33. def test_index
  34. get :index, :project_id => 1
  35. assert_response :success
  36. assert_template 'index'
  37. assert_not_nil assigns(:containers)
  38. # file attached to the project
  39. assert_tag :a, :content => 'project_file.zip',
  40. :attributes => { :href => '/attachments/download/8/project_file.zip' }
  41. # file attached to a project's version
  42. assert_tag :a, :content => 'version_file.zip',
  43. :attributes => { :href => '/attachments/download/9/version_file.zip' }
  44. end
  45. def test_new
  46. @request.session[:user_id] = 2
  47. get :new, :project_id => 1
  48. assert_response :success
  49. assert_template 'new'
  50. assert_tag 'select', :attributes => {:name => 'version_id'}
  51. end
  52. def test_new_without_versions
  53. Version.delete_all
  54. @request.session[:user_id] = 2
  55. get :new, :project_id => 1
  56. assert_response :success
  57. assert_template 'new'
  58. assert_no_tag 'select', :attributes => {:name => 'version_id'}
  59. end
  60. def test_create_file
  61. set_tmp_attachments_directory
  62. @request.session[:user_id] = 2
  63. ActionMailer::Base.deliveries.clear
  64. with_settings :notified_events => %w(file_added) do
  65. assert_difference 'Attachment.count' do
  66. post :create, :project_id => 1, :version_id => '',
  67. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
  68. assert_response :redirect
  69. end
  70. end
  71. assert_redirected_to '/projects/ecookbook/files'
  72. a = Attachment.order('created_on DESC').first
  73. assert_equal 'testfile.txt', a.filename
  74. assert_equal Project.find(1), a.container
  75. mail = ActionMailer::Base.deliveries.last
  76. assert_not_nil mail
  77. assert_equal "[eCookbook] New file", mail.subject
  78. assert_mail_body_match 'testfile.txt', mail
  79. end
  80. def test_create_version_file
  81. set_tmp_attachments_directory
  82. @request.session[:user_id] = 2
  83. assert_difference 'Attachment.count' do
  84. post :create, :project_id => 1, :version_id => '2',
  85. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
  86. assert_response :redirect
  87. end
  88. assert_redirected_to '/projects/ecookbook/files'
  89. a = Attachment.order('created_on DESC').first
  90. assert_equal 'testfile.txt', a.filename
  91. assert_equal Version.find(2), a.container
  92. end
  93. end