Sha256: a689a6e87105a5bcb443b39408378c336916842c50c692f11153c3f936a4b716

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

require 'lib/usher'


describe "Usher grapher" do

  before(:each) do
    @route_set = Usher.new
    @route_set.reset!
    @url_generator = Usher::Generators::URL.new(@route_set)
  end

  it "should find a simple path" do
    @route_set.add_route('/:a/:b/:c')
    @url_generator.generate(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
  end

  it "should pick a more specific route" do
    @route_set.add_route('/:a/:b')
    @route_set.add_route('/:a/:b/:c')
    @url_generator.generate(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
  end

  it "should fail to generate a route when none matches" do
    @route_set.add_route('/:a/:b')
    proc {@url_generator.generate(nil, {:c => 'C', :d => 'D'}) }.should raise_error Usher::UnrecognizedException
  end

  it "should find the most specific route and append extra parts on as a query string" do
    @route_set.add_route('/:a/:b/:c')
    @route_set.add_route('/:a/:b')
    @url_generator.generate(nil, {:a => 'A', :b => 'B', :d => 'C'}).should == '/A/B?d=C'
  end
  
  # FIXME
  #it "should do a validity check against the incoming variables when asked to" do
  #  route_set.add_route('/:a/:b', :b => /\d+/)
  #  route_set.generate_url(nil, {:a => 'A', :b => 'B'}).should == '/A/B'
  #  proc{ route_set.generate_url(nil, {:a => 'A', :b => 'B'})}.should raise_error Usher::ValidationException
  #end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
joshbuddy-usher-0.4.5 spec/private/grapher_spec.rb
joshbuddy-usher-0.4.6 spec/private/grapher_spec.rb
joshbuddy-usher-0.4.7 spec/private/grapher_spec.rb
joshbuddy-usher-0.4.8 spec/private/grapher_spec.rb
usher-0.4.8 spec/private/grapher_spec.rb