public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
merb-core / spec / public / router / special_spec.rb
100644 61 lines (50 sloc) 2.27 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
require File.join(File.dirname(__FILE__), "spec_helper")
 
describe "Regex-based routes" do
 
  it "should process a simple regex" do
    prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
    route_to("/foo/bar/baz").should have_route(:controller => "foo", :action => "bar", :id => "baz")
    route_to("/foos/baz/bam").should have_route(:controller => "foo", :action => "baz", :id => "bam")
  end
 
  it "should support inbound user agents" do
    Merb::Router.prepare do |r|
      r.match(%r[^/foo/(.+)], :user_agent => /(MSIE|Gecko)/).
        to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
    end
    route_to("/foo/bar", :user_agent => /MSIE/).should have_route(
      :controller => "foo", :action => "show", :title => "bar", :agent => "MSIE"
    )
  end
 
end
 
describe "Routes that are restricted based on incoming params" do
 
  it "should allow you to restrict routes to POST requests" do
    Merb::Router.prepare do |r|
      r.match("/:controller/create/:id", :method => :post).
        to(:action => "create")
    end
    route_to("/foo/create/12", :method => "post").should have_route(
      :controller => "foo", :action => "create", :id => "12"
    )
 
    route_to("/foo/create/12", :method => "get").should_not have_route(
      :controller => "foo", :action => "create", :id => "12"
    )
  end
 
  it "should allow you to restrict routes based on protocol" do
    Merb::Router.prepare do |r|
      r.match(:protocol => "http://").to(:controller => "foo", :action => "bar")
      r.default_routes
    end
    route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar")
    route_to("/boo/hoo", :protocol => "https://").should have_route(:controller => "boo", :action => "hoo")
  end
 
  it "does not require explicit specifying of params" do
    Merb::Router.prepare do |r|
      r.match!("/fb/:callback_path/:controller/:action")
    end
 
    route_to("/fb/callybacky/products/search").should have_route(
      :controller => "products", :action => "search", :callback_path => "callybacky"
    )
    route_to("/fb/ping/products/search").should have_route(
      :controller => "products", :action => "search", :callback_path => "ping"
    )
  end
 
end