Sha256: 708d6879ffe858a63bb5c3cebe186403431937783d62e8e5310bb4812b725bcb

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

module RulesEngine
  module RouteMatcher
    class Matcher
      attr_reader :route_params, :with_params
      def initialize(params = {})
        @route_params = params
        @with_params = params.map{|key, value| ":#{key} => #{value}"}.join(' ')
      end  
    end
    
    def with_route_params(params, &block)
      @route_matcher = RulesEngine::RouteMatcher::Matcher.new(params)
      yield
      @route_matcher = nil
    end
    
    def match_route html_method, controller, routes
      matcher = @route_matcher || RulesEngine::RouteMatcher::Matcher.new()

      routes.each do |method, path| 
        it "routes #{html_method} #{path} to #{controller}##{method} #{matcher.with_params}" do
          { html_method => "#{path}" }.should route_to(
            {:controller => controller.to_s,
            :action => method.to_s }.merge(matcher.route_params)
          )
        end
      end

    end    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rules_engine-0.3.3 spec/support/route_matcher.rb
rules_engine-0.3.2 spec/support/route_matcher.rb
rules_engine-0.3.1 spec/support/route_matcher.rb
rules_engine-0.3.0 spec/support/route_matcher.rb