pendragon 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,139 @@
1
+ require File.expand_path('../../lib/pendragon', __FILE__)
2
+ $:.unshift(File.dirname(__FILE__))
3
+ require 'helper'
4
+
5
+ describe Pendragon do
6
+ setup{ @pendragon = pendragon }
7
+
8
+ describe "normal routing" do
9
+ before(:each){ @pendragon.reset! }
10
+
11
+ should "basic route" do
12
+ @pendragon.add(:get, "/"){ "index" }
13
+ @pendragon.add(:get, "/users"){ "users" }
14
+ get("/")
15
+ assert_equal "index", body
16
+ get("/users")
17
+ assert_equal "users", body
18
+ end
19
+
20
+ should "ignore trailing delimiters for basic route" do
21
+ @pendragon.add(:get, "/"){ "index" }
22
+ @pendragon.add(:get, "/users"){ "users" }
23
+
24
+ get("")
25
+ assert_equal "index", body
26
+ get("/users/")
27
+ assert_equal "users", body
28
+ end
29
+
30
+ should "use pattern" do
31
+ @pendragon.add(:get, "/:id"){|params| "show #{params[:id]}" }
32
+ @pendragon.add(:get, "/:id.:ext"){|params| "show #{params[:id]}.#{params[:ext]}" }
33
+
34
+ get("/1")
35
+ assert_equal "show 1", body
36
+ get(URI.escape("/あいうえお"))
37
+ assert_equal "show あいうえお", body
38
+ get("/foo")
39
+ assert_equal "show foo", body
40
+ get("/1.json")
41
+ assert_equal "show 1.json", body
42
+ get("/foo.xml")
43
+ assert_equal "show foo.xml", body
44
+ end
45
+
46
+ should "use capture" do
47
+ id_route = @pendragon.add(:get, "/:id"){|params| "show #{params[:id]}" }
48
+ id_route.capture[:id] = /\d+/
49
+
50
+ id_with_ext_route = @pendragon.add(:get, "/:id.:ext"){|params| "show #{params[:id]}.#{params[:ext]}" }
51
+ id_with_ext_route.capture[:id] = /(foo|bar)/
52
+ id_with_ext_route.capture[:ext] = %w[html json]
53
+
54
+ get("/1")
55
+ assert_equal "show 1", body
56
+ get("/foo")
57
+ assert_equal "Not Found", body
58
+ get("/foo.json")
59
+ assert_equal "show foo.json", body
60
+ get("/baz.json")
61
+ assert_equal "Not Found", body
62
+ get("/foo.html")
63
+ assert_equal "show foo.html", body
64
+ get("/foo.xml")
65
+ assert_equal "Not Found", body
66
+ end
67
+
68
+ should "support verb methods" do
69
+ @pendragon.get("/"){ "get" }
70
+ @pendragon.post("/"){ "post" }
71
+ @pendragon.delete("/"){ "delete" }
72
+ @pendragon.put("/"){ "put" }
73
+ @pendragon.head("/"){ }
74
+ get("/")
75
+ assert_equal "get", body
76
+ post("/")
77
+ assert_equal "post", body
78
+ delete("/")
79
+ assert_equal "delete", body
80
+ put("/")
81
+ assert_equal "put", body
82
+ head("/")
83
+ assert_equal "", body
84
+ end
85
+ end
86
+ describe "regexp routing" do
87
+ before(:each){ @pendragon.reset! }
88
+
89
+ should "basic route of regexp" do
90
+ @pendragon.add(:get, /\/(\d+)/){|params| params[:captures].join(",") }
91
+ @pendragon.add(:get, /\/(foo|bar)(baz)?/){|params| params[:captures].compact.join(",") }
92
+
93
+ get("/123")
94
+ assert_equal "123", body
95
+ get("/foo")
96
+ assert_equal "foo", body
97
+ get("/foobaz")
98
+ assert_equal "foo,baz", body
99
+ end
100
+ end
101
+
102
+ describe "generate path" do
103
+ before(:each){ @pendragon.reset! }
104
+
105
+ should "basic route" do
106
+ index = @pendragon.add(:get, "/", :name => :index){}
107
+ foo_bar = @pendragon.add(:post, "/foo/bar", :name => :foo_bar){}
108
+ users = @pendragon.add(:get, "/users/:user_id", :name => :users){}
109
+
110
+ assert_equal @pendragon.path(:index), "/"
111
+ assert_equal @pendragon.path(:foo_bar), "/foo/bar"
112
+ assert_equal @pendragon.path(:users, :user_id => 1), "/users/1"
113
+ assert_equal @pendragon.path(:users, :user_id => 1, :query => "string"), "/users/1?query=string"
114
+ end
115
+
116
+ should "regexp" do
117
+ index = @pendragon.add(:get, /.+?/, :name => :index){}
118
+ foo_bar = @pendragon.add(:post, /\d+/, :name => :foo_bar){}
119
+
120
+ assert_equal @pendragon.path(:index), /.+?/
121
+ assert_equal @pendragon.path(:foo_bar), /\d+/
122
+ end
123
+ end
124
+
125
+ describe "#new allows block" do
126
+ should "#new support for block." do
127
+ @app = Pendragon.new do
128
+ foo = add(:get, "/", :name => :foo){"foo"}
129
+ bar = add(:post, "/", :name => :bar){"bar"}
130
+ end
131
+ get("/")
132
+ assert_equal "foo", body
133
+ post("/")
134
+ assert_equal "bar", body
135
+ assert_equal @app.path(:foo), "/"
136
+ assert_equal @app.path(:bar), "/"
137
+ end
138
+ end
139
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pendragon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - namusyaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mustermann
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: haml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: padrino-core
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.12.0.rc3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.0.rc3
111
+ description: Provides an HTTP router for use in Rack and Padrino.
112
+ email: namusyaka@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .travis.yml
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - README.md
121
+ - Rakefile
122
+ - config.ru
123
+ - lib/pendragon.rb
124
+ - lib/pendragon/compile_helpers.rb
125
+ - lib/pendragon/configuration.rb
126
+ - lib/pendragon/error_handler.rb
127
+ - lib/pendragon/matcher.rb
128
+ - lib/pendragon/padrino.rb
129
+ - lib/pendragon/padrino/ext/class_methods.rb
130
+ - lib/pendragon/padrino/ext/instance_methods.rb
131
+ - lib/pendragon/padrino/route.rb
132
+ - lib/pendragon/padrino/router.rb
133
+ - lib/pendragon/route.rb
134
+ - lib/pendragon/router.rb
135
+ - lib/pendragon/version.rb
136
+ - pendragon.gemspec
137
+ - test/compile_helper.rb
138
+ - test/helper.rb
139
+ - test/padrino_test.rb
140
+ - test/pendragon_test.rb
141
+ homepage: https://github.com/namusyaka/pendragon
142
+ licenses:
143
+ - MIT
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.0.2
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Provides an HTTP router for use in Rack and Padrino.
165
+ test_files:
166
+ - test/padrino_test.rb
167
+ - test/pendragon_test.rb
168
+ has_rdoc: