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.

test_helper.rb 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # redMine - project management software
  2. # Copyright (C) 2006 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. ENV["RAILS_ENV"] ||= "test"
  18. require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
  19. require 'test_help'
  20. require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
  21. require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb')
  22. require File.expand_path(File.dirname(__FILE__) + '/object_daddy_helpers')
  23. include ObjectDaddyHelpers
  24. class ActiveSupport::TestCase
  25. # Transactional fixtures accelerate your tests by wrapping each test method
  26. # in a transaction that's rolled back on completion. This ensures that the
  27. # test database remains unchanged so your fixtures don't have to be reloaded
  28. # between every test method. Fewer database queries means faster tests.
  29. #
  30. # Read Mike Clark's excellent walkthrough at
  31. # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
  32. #
  33. # Every Active Record database supports transactions except MyISAM tables
  34. # in MySQL. Turn off transactional fixtures in this case; however, if you
  35. # don't care one way or the other, switching from MyISAM to InnoDB tables
  36. # is recommended.
  37. self.use_transactional_fixtures = true
  38. # Instantiated fixtures are slow, but give you @david where otherwise you
  39. # would need people(:david). If you don't want to migrate your existing
  40. # test cases which use the @david style and don't mind the speed hit (each
  41. # instantiated fixtures translates to a database query per test method),
  42. # then set this back to true.
  43. self.use_instantiated_fixtures = false
  44. # Add more helper methods to be used by all tests here...
  45. def log_user(login, password)
  46. User.anonymous
  47. get "/login"
  48. assert_equal nil, session[:user_id]
  49. assert_response :success
  50. assert_template "account/login"
  51. post "/login", :username => login, :password => password
  52. assert_equal login, User.find(session[:user_id]).login
  53. end
  54. def uploaded_test_file(name, mime)
  55. ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
  56. end
  57. # Use a temporary directory for attachment related tests
  58. def set_tmp_attachments_directory
  59. Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test")
  60. Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
  61. Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
  62. end
  63. def with_settings(options, &block)
  64. saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
  65. options.each {|k, v| Setting[k] = v}
  66. yield
  67. saved_settings.each {|k, v| Setting[k] = v}
  68. end
  69. end