require 'spec/helper'
class One
include Innate::Node
map '/'
def auto_route
UsingRouteSelf.new.route.to_s
end
end
class Two
include Innate::Node
map '/two'
def auto_route
UsingRouteSelf.new.route.to_s
end
end
class UsingRouteSelf
include Innate::Helper::Link
attr_reader :route
def initialize
@route = route_self(:elsewhere)
end
end
describe Innate::Helper::Link do
describe '#route' do
should 'respond with URI for node' do
One.route.should == URI('/')
Two.route.should == URI('/two/')
end
should 'respond with URI for node with path /' do
One.route('/').should == URI('/')
Two.route('/').should == URI('/two/')
end
should 'respond with URI for node with path /foo' do
One.route('/foo').should == URI('/foo')
One.route(:foo).should == URI('/foo')
Two.route('/foo').should == URI('/two/foo')
Two.route(:foo).should == URI('/two/foo')
end
should 'respond with URI for node with path /foo/bar' do
One.route('/foo/bar').should == URI('/foo/bar')
One.route(:foo, :bar).should == URI('/foo/bar')
Two.route('/foo/bar').should == URI('/two/foo/bar')
Two.route(:foo, :bar).should == URI('/two/foo/bar')
end
should 'respond with URI for node with path /foo/bar+baz' do
One.route('/foo/bar+baz').should == URI('/foo/bar+baz')
One.route(:foo, 'bar baz').should == URI('/foo/bar+baz')
Two.route('/foo/bar+baz').should == URI('/two/foo/bar+baz')
Two.route(:foo, 'bar baz').should == URI('/two/foo/bar+baz')
end
should 'respond with URI for node with GET params' do
One.route('/', :a => :b).should == URI('/?a=b')
One.route('/foo', :a => :b).should == URI('/foo?a=b')
One.route(:foo, :a => :b ).should == URI('/foo?a=b')
One.route('/foo/bar', :a => :b).should == URI('/foo/bar?a=b')
One.route(:foo, :bar, :a => :b).should == URI('/foo/bar?a=b')
Two.route('/', :a => :b).should == URI('/two/?a=b')
Two.route('foo', :a => :b).should == URI('/two/foo?a=b')
Two.route(:foo, :a => :b ).should == URI('/two/foo?a=b')
Two.route('/foo/bar', :a => :b).should == URI('/two/foo/bar?a=b')
Two.route(:foo, :bar, :a => :b).should == URI('/two/foo/bar?a=b')
end
should 'prefix the links as defined in the options' do
Innate.options.prefix = '/bar'
One.route('/foo').should == URI('/bar/foo')
Innate.options.prefix = '/'
end
end
describe '#anchor' do
should 'respond with a tag with default text' do
One.anchor('hello').should == 'hello'
Two.anchor('hello').should == 'hello'
end
should 'respond with a tag with explicit text' do
One.anchor('hello', :foo).should == 'hello'
Two.anchor('hello', :foo).should == 'hello'
end
should 'pass parameters to #route' do
One.anchor('hello', :foo, :a => :b).
should == 'hello'
Two.anchor('hello', :foo, :a => :b).
should == 'hello'
end
should 'escape text' do
One.anchor('