Module: SubdomainRoutes::RoutingAssertions

Includes:
RewriteSubdomainOptions
Defined in:
lib/subdomain_routes/assertions.rb

Instance Method Summary collapse

Methods included from RewriteSubdomainOptions

#rewrite_subdomain_options, #subdomain_procs

Instance Method Details

#assert_generates_with_host(expected_path, options, host, defaults = {}, extras = {}, message = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/subdomain_routes/assertions.rb', line 31

def assert_generates_with_host(expected_path, options, host, defaults={}, extras = {}, message=nil)
  if expected_path.is_a? Hash
    expected_host = expected_path[:host]
    expected_path = expected_path[:path]
  else
    expected_host = nil
  end
  rewrite_subdomain_options(options, host)
  if options.delete(:only_path) == false
    generated_host = options.delete(:host)
    msg = expected_host ? 
      build_message(message, "The route for <?> changed the host to <?> but this did not match expected host <?>", options, generated_host, expected_host) :
      build_message(message, "The route for <?> changed the host to <?> but the host was not expected to change", options, generated_host)
    assert_block(msg) { expected_host == generated_host }
  else
    msg = build_message(message, "The route for <?> was expected to change the host to <?> but did not change the host", options, expected_host)
    assert_block(msg) { expected_host == nil }
  end
  assert_generates(expected_path, options, defaults, extras, message)
end

#assert_recognizes_with_host(expected_options, path, extras = {}, message = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/subdomain_routes/assertions.rb', line 5

def assert_recognizes_with_host(expected_options, path, extras={}, message=nil)
  # copied from Rails source, with modification to set the the supplied host on the request
  if path.is_a? Hash
    request_method = path[:method]
    host           = path[:host]
    path           = path[:path]
  else
    request_method = nil
    host = nil
  end
  clean_backtrace do
    ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
    request = recognized_request_for_with_host(path, host, request_method)
    
    expected_options = expected_options.clone
    extras.each_key { |key| expected_options.delete key } unless extras.nil?

    expected_options.stringify_keys!
    routing_diff = expected_options.diff(request.path_parameters)
    
    msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",
        request.path_parameters, expected_options, expected_options.diff(request.path_parameters))
    assert_block(msg) { request.path_parameters == expected_options }
  end
end