annotate .svn/pristine/ea/eac1f7f326d5153f2f4f2c39c2e4f9fcf2a8b080.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 #require 'shoulda'
Chris@1517 19 ENV["RAILS_ENV"] = "test"
Chris@1517 20 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
Chris@1517 21 require 'rails/test_help'
Chris@1517 22 require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
Chris@1517 23
Chris@1517 24 require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
Chris@1517 25 include ObjectHelpers
Chris@1517 26
Chris@1517 27 require 'awesome_nested_set/version'
Chris@1517 28
Chris@1517 29 class ActiveSupport::TestCase
Chris@1517 30 include ActionDispatch::TestProcess
Chris@1517 31
Chris@1517 32 self.use_transactional_fixtures = true
Chris@1517 33 self.use_instantiated_fixtures = false
Chris@1517 34
Chris@1517 35 ESCAPED_CANT = 'can&#x27;t'
Chris@1517 36 ESCAPED_UCANT = 'Can&#x27;t'
Chris@1517 37 # Rails 4.0.2
Chris@1517 38 #ESCAPED_CANT = 'can&#39;t'
Chris@1517 39 #ESCAPED_UCANT = 'Can&#39;t'
Chris@1517 40
Chris@1517 41 def log_user(login, password)
Chris@1517 42 User.anonymous
Chris@1517 43 get "/login"
Chris@1517 44 assert_equal nil, session[:user_id]
Chris@1517 45 assert_response :success
Chris@1517 46 assert_template "account/login"
Chris@1517 47 post "/login", :username => login, :password => password
Chris@1517 48 assert_equal login, User.find(session[:user_id]).login
Chris@1517 49 end
Chris@1517 50
Chris@1517 51 def uploaded_test_file(name, mime)
Chris@1517 52 fixture_file_upload("files/#{name}", mime, true)
Chris@1517 53 end
Chris@1517 54
Chris@1517 55 def credentials(user, password=nil)
Chris@1517 56 {'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)}
Chris@1517 57 end
Chris@1517 58
Chris@1517 59 # Mock out a file
Chris@1517 60 def self.mock_file
Chris@1517 61 file = 'a_file.png'
Chris@1517 62 file.stubs(:size).returns(32)
Chris@1517 63 file.stubs(:original_filename).returns('a_file.png')
Chris@1517 64 file.stubs(:content_type).returns('image/png')
Chris@1517 65 file.stubs(:read).returns(false)
Chris@1517 66 file
Chris@1517 67 end
Chris@1517 68
Chris@1517 69 def mock_file
Chris@1517 70 self.class.mock_file
Chris@1517 71 end
Chris@1517 72
Chris@1517 73 def mock_file_with_options(options={})
Chris@1517 74 file = ''
Chris@1517 75 file.stubs(:size).returns(32)
Chris@1517 76 original_filename = options[:original_filename] || nil
Chris@1517 77 file.stubs(:original_filename).returns(original_filename)
Chris@1517 78 content_type = options[:content_type] || nil
Chris@1517 79 file.stubs(:content_type).returns(content_type)
Chris@1517 80 file.stubs(:read).returns(false)
Chris@1517 81 file
Chris@1517 82 end
Chris@1517 83
Chris@1517 84 # Use a temporary directory for attachment related tests
Chris@1517 85 def set_tmp_attachments_directory
Chris@1517 86 Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test")
Chris@1517 87 unless File.directory?("#{Rails.root}/tmp/test/attachments")
Chris@1517 88 Dir.mkdir "#{Rails.root}/tmp/test/attachments"
Chris@1517 89 end
Chris@1517 90 Attachment.storage_path = "#{Rails.root}/tmp/test/attachments"
Chris@1517 91 end
Chris@1517 92
Chris@1517 93 def set_fixtures_attachments_directory
Chris@1517 94 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
Chris@1517 95 end
Chris@1517 96
Chris@1517 97 def with_settings(options, &block)
Chris@1517 98 saved_settings = options.keys.inject({}) do |h, k|
Chris@1517 99 h[k] = case Setting[k]
Chris@1517 100 when Symbol, false, true, nil
Chris@1517 101 Setting[k]
Chris@1517 102 else
Chris@1517 103 Setting[k].dup
Chris@1517 104 end
Chris@1517 105 h
Chris@1517 106 end
Chris@1517 107 options.each {|k, v| Setting[k] = v}
Chris@1517 108 yield
Chris@1517 109 ensure
Chris@1517 110 saved_settings.each {|k, v| Setting[k] = v} if saved_settings
Chris@1517 111 end
Chris@1517 112
Chris@1517 113 # Yields the block with user as the current user
Chris@1517 114 def with_current_user(user, &block)
Chris@1517 115 saved_user = User.current
Chris@1517 116 User.current = user
Chris@1517 117 yield
Chris@1517 118 ensure
Chris@1517 119 User.current = saved_user
Chris@1517 120 end
Chris@1517 121
Chris@1517 122 def with_locale(locale, &block)
Chris@1517 123 saved_localed = ::I18n.locale
Chris@1517 124 ::I18n.locale = locale
Chris@1517 125 yield
Chris@1517 126 ensure
Chris@1517 127 ::I18n.locale = saved_localed
Chris@1517 128 end
Chris@1517 129
Chris@1517 130 def change_user_password(login, new_password)
Chris@1517 131 user = User.where(:login => login).first
Chris@1517 132 user.password, user.password_confirmation = new_password, new_password
Chris@1517 133 user.save!
Chris@1517 134 end
Chris@1517 135
Chris@1517 136 def self.ldap_configured?
Chris@1517 137 @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389)
Chris@1517 138 return @test_ldap.bind
Chris@1517 139 rescue Exception => e
Chris@1517 140 # LDAP is not listening
Chris@1517 141 return nil
Chris@1517 142 end
Chris@1517 143
Chris@1517 144 def self.convert_installed?
Chris@1517 145 Redmine::Thumbnail.convert_available?
Chris@1517 146 end
Chris@1517 147
Chris@1517 148 # Returns the path to the test +vendor+ repository
Chris@1517 149 def self.repository_path(vendor)
Chris@1517 150 Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s
Chris@1517 151 end
Chris@1517 152
Chris@1517 153 # Returns the url of the subversion test repository
Chris@1517 154 def self.subversion_repository_url
Chris@1517 155 path = repository_path('subversion')
Chris@1517 156 path = '/' + path unless path.starts_with?('/')
Chris@1517 157 "file://#{path}"
Chris@1517 158 end
Chris@1517 159
Chris@1517 160 # Returns true if the +vendor+ test repository is configured
Chris@1517 161 def self.repository_configured?(vendor)
Chris@1517 162 File.directory?(repository_path(vendor))
Chris@1517 163 end
Chris@1517 164
Chris@1517 165 def repository_path_hash(arr)
Chris@1517 166 hs = {}
Chris@1517 167 hs[:path] = arr.join("/")
Chris@1517 168 hs[:param] = arr.join("/")
Chris@1517 169 hs
Chris@1517 170 end
Chris@1517 171
Chris@1517 172 def assert_save(object)
Chris@1517 173 saved = object.save
Chris@1517 174 message = "#{object.class} could not be saved"
Chris@1517 175 errors = object.errors.full_messages.map {|m| "- #{m}"}
Chris@1517 176 message << ":\n#{errors.join("\n")}" if errors.any?
Chris@1517 177 assert_equal true, saved, message
Chris@1517 178 end
Chris@1517 179
Chris@1517 180 def assert_error_tag(options={})
Chris@1517 181 assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options))
Chris@1517 182 end
Chris@1517 183
Chris@1517 184 def assert_include(expected, s, message=nil)
Chris@1517 185 assert s.include?(expected), (message || "\"#{expected}\" not found in \"#{s}\"")
Chris@1517 186 end
Chris@1517 187
Chris@1517 188 def assert_not_include(expected, s, message=nil)
Chris@1517 189 assert !s.include?(expected), (message || "\"#{expected}\" found in \"#{s}\"")
Chris@1517 190 end
Chris@1517 191
Chris@1517 192 def assert_select_in(text, *args, &block)
Chris@1517 193 d = HTML::Document.new(CGI::unescapeHTML(String.new(text))).root
Chris@1517 194 assert_select(d, *args, &block)
Chris@1517 195 end
Chris@1517 196
Chris@1517 197 def assert_mail_body_match(expected, mail, message=nil)
Chris@1517 198 if expected.is_a?(String)
Chris@1517 199 assert_include expected, mail_body(mail), message
Chris@1517 200 else
Chris@1517 201 assert_match expected, mail_body(mail), message
Chris@1517 202 end
Chris@1517 203 end
Chris@1517 204
Chris@1517 205 def assert_mail_body_no_match(expected, mail, message=nil)
Chris@1517 206 if expected.is_a?(String)
Chris@1517 207 assert_not_include expected, mail_body(mail), message
Chris@1517 208 else
Chris@1517 209 assert_no_match expected, mail_body(mail), message
Chris@1517 210 end
Chris@1517 211 end
Chris@1517 212
Chris@1517 213 def mail_body(mail)
Chris@1517 214 mail.parts.first.body.encoded
Chris@1517 215 end
Chris@1517 216
Chris@1517 217 # awesome_nested_set new node lft and rgt value changed this refactor revision.
Chris@1517 218 # https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb938e40200cd90714dc69247ef017c61
Chris@1517 219 # The reason of behavior change is that "self.class.base_class.unscoped" was added to this line.
Chris@1517 220 # https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb9#diff-f61b59a5e6319024e211b0ffdd0e4ef1R273
Chris@1517 221 # It seems correct behavior because of this line comment.
Chris@1517 222 # https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
Chris@1517 223 def new_issue_lft
Chris@1517 224 ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
Chris@1517 225 end
Chris@1517 226 end
Chris@1517 227
Chris@1517 228 module Redmine
Chris@1517 229 module ApiTest
Chris@1517 230 # Base class for API tests
Chris@1517 231 class Base < ActionDispatch::IntegrationTest
Chris@1517 232 # Test that a request allows the three types of API authentication
Chris@1517 233 #
Chris@1517 234 # * HTTP Basic with username and password
Chris@1517 235 # * HTTP Basic with an api key for the username
Chris@1517 236 # * Key based with the key=X parameter
Chris@1517 237 #
Chris@1517 238 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1517 239 # @param [String] url the request url
Chris@1517 240 # @param [optional, Hash] parameters additional request parameters
Chris@1517 241 # @param [optional, Hash] options additional options
Chris@1517 242 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1517 243 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1517 244 def self.should_allow_api_authentication(http_method, url, parameters={}, options={})
Chris@1517 245 should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters, options)
Chris@1517 246 should_allow_http_basic_auth_with_key(http_method, url, parameters, options)
Chris@1517 247 should_allow_key_based_auth(http_method, url, parameters, options)
Chris@1517 248 end
Chris@1517 249
Chris@1517 250 # Test that a request allows the username and password for HTTP BASIC
Chris@1517 251 #
Chris@1517 252 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1517 253 # @param [String] url the request url
Chris@1517 254 # @param [optional, Hash] parameters additional request parameters
Chris@1517 255 # @param [optional, Hash] options additional options
Chris@1517 256 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1517 257 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1517 258 def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={}, options={})
Chris@1517 259 success_code = options[:success_code] || :success
Chris@1517 260 failure_code = options[:failure_code] || :unauthorized
Chris@1517 261
Chris@1517 262 context "should allow http basic auth using a username and password for #{http_method} #{url}" do
Chris@1517 263 context "with a valid HTTP authentication" do
Chris@1517 264 setup do
Chris@1517 265 @user = User.generate! do |user|
Chris@1517 266 user.admin = true
Chris@1517 267 user.password = 'my_password'
Chris@1517 268 end
Chris@1517 269 send(http_method, url, parameters, credentials(@user.login, 'my_password'))
Chris@1517 270 end
Chris@1517 271
Chris@1517 272 should_respond_with success_code
Chris@1517 273 should_respond_with_content_type_based_on_url(url)
Chris@1517 274 should "login as the user" do
Chris@1517 275 assert_equal @user, User.current
Chris@1517 276 end
Chris@1517 277 end
Chris@1517 278
Chris@1517 279 context "with an invalid HTTP authentication" do
Chris@1517 280 setup do
Chris@1517 281 @user = User.generate!
Chris@1517 282 send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
Chris@1517 283 end
Chris@1517 284
Chris@1517 285 should_respond_with failure_code
Chris@1517 286 should_respond_with_content_type_based_on_url(url)
Chris@1517 287 should "not login as the user" do
Chris@1517 288 assert_equal User.anonymous, User.current
Chris@1517 289 end
Chris@1517 290 end
Chris@1517 291
Chris@1517 292 context "without credentials" do
Chris@1517 293 setup do
Chris@1517 294 send(http_method, url, parameters)
Chris@1517 295 end
Chris@1517 296
Chris@1517 297 should_respond_with failure_code
Chris@1517 298 should_respond_with_content_type_based_on_url(url)
Chris@1517 299 should "include_www_authenticate_header" do
Chris@1517 300 assert @controller.response.headers.has_key?('WWW-Authenticate')
Chris@1517 301 end
Chris@1517 302 end
Chris@1517 303 end
Chris@1517 304 end
Chris@1517 305
Chris@1517 306 # Test that a request allows the API key with HTTP BASIC
Chris@1517 307 #
Chris@1517 308 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1517 309 # @param [String] url the request url
Chris@1517 310 # @param [optional, Hash] parameters additional request parameters
Chris@1517 311 # @param [optional, Hash] options additional options
Chris@1517 312 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1517 313 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1517 314 def self.should_allow_http_basic_auth_with_key(http_method, url, parameters={}, options={})
Chris@1517 315 success_code = options[:success_code] || :success
Chris@1517 316 failure_code = options[:failure_code] || :unauthorized
Chris@1517 317
Chris@1517 318 context "should allow http basic auth with a key for #{http_method} #{url}" do
Chris@1517 319 context "with a valid HTTP authentication using the API token" do
Chris@1517 320 setup do
Chris@1517 321 @user = User.generate! do |user|
Chris@1517 322 user.admin = true
Chris@1517 323 end
Chris@1517 324 @token = Token.create!(:user => @user, :action => 'api')
Chris@1517 325 send(http_method, url, parameters, credentials(@token.value, 'X'))
Chris@1517 326 end
Chris@1517 327 should_respond_with success_code
Chris@1517 328 should_respond_with_content_type_based_on_url(url)
Chris@1517 329 should_be_a_valid_response_string_based_on_url(url)
Chris@1517 330 should "login as the user" do
Chris@1517 331 assert_equal @user, User.current
Chris@1517 332 end
Chris@1517 333 end
Chris@1517 334
Chris@1517 335 context "with an invalid HTTP authentication" do
Chris@1517 336 setup do
Chris@1517 337 @user = User.generate!
Chris@1517 338 @token = Token.create!(:user => @user, :action => 'feeds')
Chris@1517 339 send(http_method, url, parameters, credentials(@token.value, 'X'))
Chris@1517 340 end
Chris@1517 341 should_respond_with failure_code
Chris@1517 342 should_respond_with_content_type_based_on_url(url)
Chris@1517 343 should "not login as the user" do
Chris@1517 344 assert_equal User.anonymous, User.current
Chris@1517 345 end
Chris@1517 346 end
Chris@1517 347 end
Chris@1517 348 end
Chris@1517 349
Chris@1517 350 # Test that a request allows full key authentication
Chris@1517 351 #
Chris@1517 352 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1517 353 # @param [String] url the request url, without the key=ZXY parameter
Chris@1517 354 # @param [optional, Hash] parameters additional request parameters
Chris@1517 355 # @param [optional, Hash] options additional options
Chris@1517 356 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1517 357 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1517 358 def self.should_allow_key_based_auth(http_method, url, parameters={}, options={})
Chris@1517 359 success_code = options[:success_code] || :success
Chris@1517 360 failure_code = options[:failure_code] || :unauthorized
Chris@1517 361
Chris@1517 362 context "should allow key based auth using key=X for #{http_method} #{url}" do
Chris@1517 363 context "with a valid api token" do
Chris@1517 364 setup do
Chris@1517 365 @user = User.generate! do |user|
Chris@1517 366 user.admin = true
Chris@1517 367 end
Chris@1517 368 @token = Token.create!(:user => @user, :action => 'api')
Chris@1517 369 # Simple url parse to add on ?key= or &key=
Chris@1517 370 request_url = if url.match(/\?/)
Chris@1517 371 url + "&key=#{@token.value}"
Chris@1517 372 else
Chris@1517 373 url + "?key=#{@token.value}"
Chris@1517 374 end
Chris@1517 375 send(http_method, request_url, parameters)
Chris@1517 376 end
Chris@1517 377 should_respond_with success_code
Chris@1517 378 should_respond_with_content_type_based_on_url(url)
Chris@1517 379 should_be_a_valid_response_string_based_on_url(url)
Chris@1517 380 should "login as the user" do
Chris@1517 381 assert_equal @user, User.current
Chris@1517 382 end
Chris@1517 383 end
Chris@1517 384
Chris@1517 385 context "with an invalid api token" do
Chris@1517 386 setup do
Chris@1517 387 @user = User.generate! do |user|
Chris@1517 388 user.admin = true
Chris@1517 389 end
Chris@1517 390 @token = Token.create!(:user => @user, :action => 'feeds')
Chris@1517 391 # Simple url parse to add on ?key= or &key=
Chris@1517 392 request_url = if url.match(/\?/)
Chris@1517 393 url + "&key=#{@token.value}"
Chris@1517 394 else
Chris@1517 395 url + "?key=#{@token.value}"
Chris@1517 396 end
Chris@1517 397 send(http_method, request_url, parameters)
Chris@1517 398 end
Chris@1517 399 should_respond_with failure_code
Chris@1517 400 should_respond_with_content_type_based_on_url(url)
Chris@1517 401 should "not login as the user" do
Chris@1517 402 assert_equal User.anonymous, User.current
Chris@1517 403 end
Chris@1517 404 end
Chris@1517 405 end
Chris@1517 406
Chris@1517 407 context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do
Chris@1517 408 setup do
Chris@1517 409 @user = User.generate! do |user|
Chris@1517 410 user.admin = true
Chris@1517 411 end
Chris@1517 412 @token = Token.create!(:user => @user, :action => 'api')
Chris@1517 413 send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s})
Chris@1517 414 end
Chris@1517 415 should_respond_with success_code
Chris@1517 416 should_respond_with_content_type_based_on_url(url)
Chris@1517 417 should_be_a_valid_response_string_based_on_url(url)
Chris@1517 418 should "login as the user" do
Chris@1517 419 assert_equal @user, User.current
Chris@1517 420 end
Chris@1517 421 end
Chris@1517 422 end
Chris@1517 423
Chris@1517 424 # Uses should_respond_with_content_type based on what's in the url:
Chris@1517 425 #
Chris@1517 426 # '/project/issues.xml' => should_respond_with_content_type :xml
Chris@1517 427 # '/project/issues.json' => should_respond_with_content_type :json
Chris@1517 428 #
Chris@1517 429 # @param [String] url Request
Chris@1517 430 def self.should_respond_with_content_type_based_on_url(url)
Chris@1517 431 case
Chris@1517 432 when url.match(/xml/i)
Chris@1517 433 should "respond with XML" do
Chris@1517 434 assert_equal 'application/xml', @response.content_type
Chris@1517 435 end
Chris@1517 436 when url.match(/json/i)
Chris@1517 437 should "respond with JSON" do
Chris@1517 438 assert_equal 'application/json', @response.content_type
Chris@1517 439 end
Chris@1517 440 else
Chris@1517 441 raise "Unknown content type for should_respond_with_content_type_based_on_url: #{url}"
Chris@1517 442 end
Chris@1517 443 end
Chris@1517 444
Chris@1517 445 # Uses the url to assert which format the response should be in
Chris@1517 446 #
Chris@1517 447 # '/project/issues.xml' => should_be_a_valid_xml_string
Chris@1517 448 # '/project/issues.json' => should_be_a_valid_json_string
Chris@1517 449 #
Chris@1517 450 # @param [String] url Request
Chris@1517 451 def self.should_be_a_valid_response_string_based_on_url(url)
Chris@1517 452 case
Chris@1517 453 when url.match(/xml/i)
Chris@1517 454 should_be_a_valid_xml_string
Chris@1517 455 when url.match(/json/i)
Chris@1517 456 should_be_a_valid_json_string
Chris@1517 457 else
Chris@1517 458 raise "Unknown content type for should_be_a_valid_response_based_on_url: #{url}"
Chris@1517 459 end
Chris@1517 460 end
Chris@1517 461
Chris@1517 462 # Checks that the response is a valid JSON string
Chris@1517 463 def self.should_be_a_valid_json_string
Chris@1517 464 should "be a valid JSON string (or empty)" do
Chris@1517 465 assert(response.body.blank? || ActiveSupport::JSON.decode(response.body))
Chris@1517 466 end
Chris@1517 467 end
Chris@1517 468
Chris@1517 469 # Checks that the response is a valid XML string
Chris@1517 470 def self.should_be_a_valid_xml_string
Chris@1517 471 should "be a valid XML string" do
Chris@1517 472 assert REXML::Document.new(response.body)
Chris@1517 473 end
Chris@1517 474 end
Chris@1517 475
Chris@1517 476 def self.should_respond_with(status)
Chris@1517 477 should "respond with #{status}" do
Chris@1517 478 assert_response status
Chris@1517 479 end
Chris@1517 480 end
Chris@1517 481 end
Chris@1517 482 end
Chris@1517 483 end
Chris@1517 484
Chris@1517 485 # URL helpers do not work with config.threadsafe!
Chris@1517 486 # https://github.com/rspec/rspec-rails/issues/476#issuecomment-4705454
Chris@1517 487 ActionView::TestCase::TestController.instance_eval do
Chris@1517 488 helper Rails.application.routes.url_helpers
Chris@1517 489 end
Chris@1517 490 ActionView::TestCase::TestController.class_eval do
Chris@1517 491 def _routes
Chris@1517 492 Rails.application.routes
Chris@1517 493 end
Chris@1517 494 end