Sha256: 6476d4b574ac91ee1daf574b20062ea7edfbae8db9ab29cdf8e06f69fbe12755

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module PluginAWeek #:nodoc:
  module PluginTestHelper #:nodoc:
    module Extensions #:nodoc:
      # Overrides where the path of the application routes is located so that
      # it defaults to this helper's implementation or can be overridden by the
      # plugin using this helper
      module Routing
        def self.included(base)
          base.class_eval do
            alias_method :load_routes!, :load_routes_with_test_helper!
          end
        end
        
        # Load routes from either the helper or the plugin
        def load_routes_with_test_helper!
          if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
            routes_path = File.join("#{RAILS_ROOT}/config/routes.rb")
            routes_path = File.join("#{HELPER_RAILS_ROOT}/config/routes.rb") if !File.exists?(routes_path)
            
            load File.join(routes_path)
          else
            add_route ":controller/:action/:id"
          end
        end
      end
    end
  end
end

ActionController::Routing::RouteSet.class_eval do
  include PluginAWeek::PluginTestHelper::Extensions::Routing
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plugin_test_helper-0.0.2 lib/plugin_test_helper/extensions/routing.rb
plugin_test_helper-0.0.1 lib/plugin_test_helper/extensions/routing.rb