PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/test/url_rewriter_test.rb

https://github.com/technicalpickles/ssl_requirement
Ruby | 77 lines | 65 code | 11 blank | 1 comment | 0 complexity | 96f7583b364e329166d7960b5c758ca3 MD5 | raw file
  1. $:.unshift(File.dirname(__FILE__) + '/../lib')
  2. require 'rubygems'
  3. require 'test/unit'
  4. require 'action_controller'
  5. require 'action_controller/test_process'
  6. require "ssl_requirement"
  7. # Show backtraces for deprecated behavior for quicker cleanup.
  8. ActiveSupport::Deprecation.debug = true
  9. ActionController::Base.logger = nil
  10. ActionController::Routing::Routes.reload rescue nil
  11. class UrlRewriterTest < Test::Unit::TestCase
  12. def setup
  13. @request = ActionController::TestRequest.new
  14. @params = {}
  15. @rewriter = ActionController::UrlRewriter.new(@request, @params)
  16. puts @url_rewriter.to_s
  17. end
  18. def test_rewrite_secure_false
  19. SslRequirement.disable_ssl_check = false
  20. assert_equal('http://test.host/c/a',
  21. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false)
  22. )
  23. assert_equal('http://test.host/c/a',
  24. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false, :only_path => true)
  25. )
  26. SslRequirement.disable_ssl_check = true
  27. assert_equal('http://test.host/c/a',
  28. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false)
  29. )
  30. assert_equal('/c/a',
  31. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false, :only_path => true)
  32. )
  33. end
  34. def test_rewrite_secure_true
  35. SslRequirement.disable_ssl_check = false
  36. assert_equal('https://test.host/c/a',
  37. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true)
  38. )
  39. assert_equal('https://test.host/c/a',
  40. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true, :only_path => true)
  41. )
  42. SslRequirement.disable_ssl_check = true
  43. assert_equal('http://test.host/c/a',
  44. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true)
  45. )
  46. assert_equal('/c/a',
  47. @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true, :only_path => true)
  48. )
  49. end
  50. def test_rewrite_secure_not_specified
  51. SslRequirement.disable_ssl_check = false
  52. assert_equal('http://test.host/c/a',
  53. @rewriter.rewrite(:controller => 'c', :action => 'a')
  54. )
  55. assert_equal('/c/a',
  56. @rewriter.rewrite(:controller => 'c', :action => 'a', :only_path => true)
  57. )
  58. SslRequirement.disable_ssl_check = true
  59. assert_equal('http://test.host/c/a',
  60. @rewriter.rewrite(:controller => 'c', :action => 'a')
  61. )
  62. assert_equal('/c/a',
  63. @rewriter.rewrite(:controller => 'c', :action => 'a', :only_path => true)
  64. )
  65. end
  66. end