macournoyer / invisible

The invisible framework

This URL has Read+Write access

macournoyer (author)
Tue Mar 24 18:32:34 -0700 2009
commit  2333383a458b24ededd8ce6fa3a6ade206cf7d12
tree    4904e35eb8a43ea936b047e31e7554e42223f538
parent  30454dd44d4b67b676d2d98fbb078c99ea49d464
invisible / spec / routing_spec.rb
100644 103 lines (79 sloc) 2.333 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require File.dirname(__FILE__) + "/spec_helper"
 
describe "routing" do
  before do
    @app = Invisible.new do
      get "/path" do
        render "/path"
      end
      
      get "/path.xml" do
        render "/path.xml"
      end
      
      get "/param/:name.xml" do
        render params[:name] + ".xml"
      end
      
      get "/param/:name" do
        render params[:name]
      end
      
      get "/param_with_underscore/:long_name" do
        render params[:long_name]
      end
      
      get "no/slash" do
        render "no-slash"
      end
      
      get "/" do
        render "get"
      end
      
      post "/" do
        render "post"
      end
      
      delete "/" do
        render "delete"
      end
      
      get "/wildcard*" do
        render "wildcard"
      end
    end
  end
  
  it "should route GET /" do
    @app.mock.get("/").body.should == "get"
  end
  
  it "should route POST /" do
    @app.mock.post("/").body.should == "post"
  end
  
  it "should route DELETE /" do
    @app.mock.delete("/").body.should == "delete"
  end
  
  it "should route DELETE with _method hack" do
    @app.mock.post("/", :input => "_method=DELETE").body.should == "delete"
  end
  
  it "should not route DELETE with _method hack on GET" do
    @app.mock.get("/?_method=DELETE").body.should_not == "delete"
  end
  
  it "should return 404 when no route" do
    @app.mock.get("/no-route").status.should == 404
  end
  
  it "should route /path" do
    @app.mock.get("/path").body.should == "/path"
  end
  
  it "should route /path.xml" do
    @app.mock.get("/path.xml").body.should == "/path.xml"
  end
  
  it "should route /param/:param" do
    @app.mock.get("/param/ohaie").body.should == "ohaie"
  end
 
  it "should route and set param with underscore" do
    @app.mock.get("/param_with_underscore/ohaie").body.should == "ohaie"
  end
  
  it "should route /param/:param.xml" do
    @app.mock.get("/param/ohaie.xml").body.should == "ohaie.xml"
  end
  
  it "should route with no leading slash" do
    @app.mock.get("/no/slash").body.should == "no-slash"
  end
  
  it "should route ignore trailing slash" do
    @app.mock.get("/no/slash/").body.should == "no-slash"
  end
  
  it "should allow wildcard in route" do
    @app.mock.get("/wildcard/something/else").body.should == "wildcard"
  end
end