spec/support/inject_engine_routes_into_application.rb
##
# Automatically append all of the current engine's routes to the main
# application's route set. This needs to be done for ALL functional tests that
# use engine routes, since the mounted routes don't work during tests.
#
# @param [Symbol] engine_symbol Optional; if provided, uses this symbol to
#   locate the engine class by name, otherwise uses the module of the calling
#   test case as the presumed name of the engine.
# 
# @author Jason Hamilton (jhamilton@greatherorift.com)
# @author Matthew Ratzloff (matt@urbaninfluence.com)
Automatically append all of the current engine's routes to the main
application's route set. This needs to be done for ALL functional tests that
use engine routes, since the mounted routes don't work during tests.
Automatically append all of the current engine ' s routes to the main application ' s route set . This needs to be done for ALL functional tests that use engine routes since the mounted routes don ' t work during tests .
def load_engine_routes(engine_symbol = nil)
        if engine_symbol
          engine_name = engine_symbol.to_s.camelize
        else
          engine_name = self.class.name.split("::").first.split("(").last
        end
        engine = ("#{engine_name}::Engine").constantize
        engine_name = 'oauth2'
        engine = Devise::Oauth2Providable::Engine
        named_routes   = engine.routes.named_routes.routes
        resourced_routes = []
        ::Rails.application.routes.draw do
          engine.routes.routes.each do |route|
            pre_path = route.path
            if pre_path.kind_of?(Journey::Path::Pattern) 
              path = pre_path = "/#{engine_name.underscore}#{pre_path.spec.to_s}"
            else
              path = "/#{engine_name.underscore}#{pre_path}"
            end
            requirements = route.requirements
            if path_helper = named_routes[route]
              requirements[:as] = path_helper
            elsif route.requirements[:controller].present?
              resourced_routes << route.requirements[:controller].gsub("#{engine_name.downcase}/", "").to_sym
            end
            pre_verb = (route.verb.blank? ? "GET" : route.verb)
            if pre_verb.to_s == "(?-mix:)"
              verb = :all
            elsif pre_verb.to_s == "(?-mix:^POST$)"
              verb = :post
            else
              raise "not handled verb : #{pre_verb}"
            end
            if verb == :all
              send(:match, path, requirements)
            else
              send(verb, path, requirements)
            end
          end
        end
        ::Rails.application.routes.finalize!
        ::Rails.application.routes.disable_clear_and_finalize = false
      end
def load_engine_routes ( engine_symbol = nil ) if engine_symbol engine_name = engine_symbol . to_s . camelize else engine_name = self . class . name . split ( "::" ) . first . split ( "(" ) . last end engine = ( "#{engine_name}::Engine" ) . constantize engine_name = 'oauth2' engine = Devise :: Oauth2Providable :: Engine named_routes = engine . routes . named_routes . routes resourced_routes = [ ] :: Rails . application . routes . draw do engine . routes . routes . each do | route | pre_path = route . path if pre_path . kind_of? ( Journey :: Path :: Pattern ) path = pre_path = "/#{engine_name.underscore}#{pre_path.spec.to_s}" else path = "/#{engine_name.underscore}#{pre_path}" end requirements = route . requirements if path_helper = named_routes [ route ] requirements [ :as ] = path_helper elsif route . requirements [ :controller ] . present? resourced_routes << route . requirements [ :controller ] . gsub ( "#{engine_name.downcase}/" , "" ) . to_sym end pre_verb = ( route . verb . blank? ? "GET" : route . verb ) if pre_verb . to_s == "(?-mix:)" verb = :all elsif pre_verb . to_s == "(?-mix:^POST$)" verb = :post else raise "not handled verb : #{pre_verb}" end if verb == :all send ( :match , path , requirements ) else send ( verb , path , requirements ) end end end :: Rails . application . routes . finalize! :: Rails . application . routes . disable_clear_and_finalize = false end
Automatically append all of the current engine's routes to the main
application's route set.
Automatically append all of the current engine ' s routes to the main application ' s route set .
# No engine provided, so presume the current engine is the one to load # Append the routes for this module to the existing routes # ::Rails.application.routes.disable_clear_and_finalize = true # ::Rails.application.routes.clear! # ::Rails.application.routes_reloader.paths.each { |path| load(path) } # unnamed_routes = engine.routes.routes - named_routes.values # Call the method by hand based on the symbol # seams that complexe types are now in use # Presume that all controllers referenced in routes should also be # resources and append that routing on the end so that *_path helpers # will still work # Add each route, once, to the end under a scope to trick path helpers. # This will probably break as soon as there is route name overlap, but # we'll cross that bridge when we get to it. # resourced_routes.uniq! # scope engine_name.downcase do #   resourced_routes.each do |resource| #     resources resource #   end # end # Finalize the routes
engine_symbol
<not_specific>
<not_specific>
engine_symbol Optional; if provided, uses this symbol to locate the engine class by name, otherwise uses the module of the calling test case as the presumed name of the engine.
engine_symbol Optional ; if provided uses this symbol to locate the engine class by name otherwise uses the module of the calling test case as the presumed name of the engine .
author
Jason Hamilton (jhamilton@greatherorift.com)
Jason Hamilton ( jhamilton@greatherorift . com )
author
Matthew Ratzloff (matt@urbaninfluence.com)
Matthew Ratzloff ( matt@urbaninfluence . com )