Skip to content
This repository
tree: 6d3fd7da4d
Fetching contributors…

Cannot retrieve contributors at this time

file 75 lines (59 sloc) 1.761 kb
1 2 3 4 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
require 'spec_helper'

module Jimson
  describe Router do

    let(:router) { Router.new }

    class RouterFooHandler
      extend Jimson::Handler

      def hi
        'hi'
      end
    end

    class RouterBarHandler
      extend Jimson::Handler

      def bye
        'bye'
      end
    end

    class RouterBazHandler
      extend Jimson::Handler

      def meh
        'mehkayla'
      end
    end


    describe '#draw' do
      context 'when given non-nested namespaces' do
        it 'takes a block with a DSL to set the root and namespaces' do
          router.draw do
            root RouterFooHandler
            namespace 'ns', RouterBarHandler
          end

          router.handler_for_method('hi').should be_a(RouterFooHandler)
          router.handler_for_method('ns.hi').should be_a(RouterBarHandler)
        end
      end

      context 'when given nested namespaces' do
        it 'takes a block with a DSL to set the root and namespaces' do
          router.draw do
            root RouterFooHandler
            namespace 'ns1' do
              root RouterBazHandler
              namespace 'ns2', RouterBarHandler
            end
          end

          router.handler_for_method('hi').should be_a(RouterFooHandler)
          router.handler_for_method('ns1.hi').should be_a(RouterBazHandler)
          router.handler_for_method('ns1.ns2.hi').should be_a(RouterBarHandler)
        end
      end
    end

    describe '#jimson_methods' do
      it 'returns an array of namespaced method names from all registered handlers' do
        router.draw do
          root RouterFooHandler
          namespace 'foo', RouterBarHandler
        end

        router.jimson_methods.sort.should == ['hi', 'foo.bye'].sort
      end
    end

  end
end
Something went wrong with that request. Please try again.