Class: AePageObjects::ApplicationRouter::Recognizer::Rails23

Inherits:
Base
  • Object
show all
Defined in:
lib/ae_page_objects/core/application_router.rb

Instance Method Summary collapse

Methods inherited from Base

#generate_path

Instance Method Details

#recognizes?(path, url) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ae_page_objects/core/application_router.rb', line 17

def recognizes?(path, url)
  ["GET", "PUT", "POST", "DELETE", "PATCH"].map(&:downcase).map(&:to_sym).each do |method|
    path_route_result = ActionController::Routing::Routes.named_routes[path].requirements
    recognized_result = nil

    begin
      recognized_result = ActionController::Routing::Routes.recognize_path(url, {:method => method}).select do
      |key, _|
        key.to_s.match(/(controller|action)/)
      end
    rescue ActionController::MethodNotAllowed
    end

    # Only the first recognized path returned by Rails is considered,
    # which means, we only want highest prioritized route.
    if recognized_result && path_route_result == Hash[recognized_result]
      return true
    else
      next
    end
  end

  false
end