usher 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +10 -0
- data/README.markdown +158 -0
- data/Rakefile +47 -12
- data/benchmarks/rack_recognition_bm.rb +48 -0
- data/lib/usher/delimiters.rb +20 -8
- data/lib/usher/exceptions.rb +4 -0
- data/lib/usher/grapher.rb +38 -32
- data/lib/usher/interface/rack/builder.rb +39 -0
- data/lib/usher/interface/rack/middleware.rb +22 -0
- data/lib/usher/interface/rack.rb +6 -55
- data/lib/usher/interface/sinatra.rb +115 -56
- data/lib/usher/interface.rb +12 -22
- data/lib/usher/node/response.rb +3 -1
- data/lib/usher/node.rb +56 -75
- data/lib/usher/route/static.rb +2 -0
- data/lib/usher/route/variable.rb +1 -1
- data/lib/usher/route.rb +21 -18
- data/lib/usher/splitter.rb +4 -6
- data/lib/usher/util/generate.rb +50 -34
- data/lib/usher/util/parser.rb +12 -9
- data/lib/usher.rb +204 -162
- data/spec/private/generate_spec.rb +5 -0
- data/spec/private/recognize_spec.rb +12 -12
- data/spec/private/sinatra/recognize_spec.rb +102 -0
- data/spec/spec_helper.rb +1 -1
- data/usher.gemspec +8 -5
- metadata +75 -19
- data/README.rdoc +0 -158
- data/spec/rails2_2/compat.rb +0 -3
- data/spec/rails2_2/generate_spec.rb +0 -28
- data/spec/rails2_2/path_spec.rb +0 -16
- data/spec/rails2_2/recognize_spec.rb +0 -78
- data/spec/rails2_3/compat.rb +0 -2
- data/spec/rails2_3/generate_spec.rb +0 -28
- data/spec/rails2_3/path_spec.rb +0 -16
- data/spec/rails2_3/recognize_spec.rb +0 -78
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'compat'))
|
2
|
-
require "usher"
|
3
|
-
|
4
|
-
route_set = Usher::Interface.for(:rails23)
|
5
|
-
|
6
|
-
def build_request_mock_rails23(path, method, params)
|
7
|
-
request = mock "Request"
|
8
|
-
request.should_receive(:path).any_number_of_times.and_return(path)
|
9
|
-
request.should_receive(:method).any_number_of_times.and_return(method)
|
10
|
-
params = params.with_indifferent_access
|
11
|
-
request.should_receive(:path_parameters=).any_number_of_times.with(hash_including(params))
|
12
|
-
request.should_receive(:path_parameters).any_number_of_times.and_return(params)
|
13
|
-
request
|
14
|
-
end
|
15
|
-
|
16
|
-
SampleController = Object.new
|
17
|
-
|
18
|
-
describe "Usher (for rails 2.3) route recognition" do
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
route_set.reset!
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should recognize a simple request" do
|
25
|
-
route_set.add_route('/sample', :controller => 'sample', :action => 'action')
|
26
|
-
route_set.recognize(build_request_mock_rails23('/sample', 'get', {:controller => 'sample', :action => 'action'})).should == SampleController
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should interpolate action :index" do
|
30
|
-
route_set.add_route('/sample', :controller => 'sample')
|
31
|
-
route_set.recognize(build_request_mock_rails23('/sample', 'get', {:controller => 'sample', :action => 'index'})).should == SampleController
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should correctly distinguish between multiple request methods" do
|
35
|
-
route_set.add_route('/sample', :controller => 'not_sample', :conditions => {:method => :get})
|
36
|
-
correct_route = route_set.add_route('/sample', :controller => 'sample', :conditions => {:method => :post})
|
37
|
-
route_set.add_route('/sample', :controller => 'not_sample', :conditions => {:method => :put})
|
38
|
-
route_set.recognize(build_request_mock_rails23('/sample', :post, {:controller => 'sample', :action => 'index'})).should == SampleController
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should prefer the static route to the dynamic route" do
|
42
|
-
route_set.add_route('/sample/:action', :controller => 'not_sample')
|
43
|
-
route_set.add_route('/sample/test', :controller => 'sample', :action => 'action')
|
44
|
-
route_set.recognize(build_request_mock_rails23('/sample/test', 'get', {:controller => 'sample', :action => 'action'})).should == SampleController
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should raise based upon an invalid param" do
|
48
|
-
route_set.add_named_route(:sample, '/sample/:action', :controller => 'sample', :requirements => {:action => /\d+/})
|
49
|
-
proc { route_set.recognize(build_request_mock_rails23('/sample/asdqwe', :post, {})) }.should raise_error
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should raise based upon an invalid route" do
|
53
|
-
route_set.add_named_route(:sample, '/sample', :controller => 'sample', :action => 'test')
|
54
|
-
proc { route_set.recognize(build_request_mock_rails23('/test/asdqwe', :post, {})) }.should raise_error
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should add /:controller and /:controller/:action if /:controller/:action/:id is added" do
|
58
|
-
route_set.add_route('/:controller/:action/:id')
|
59
|
-
route_set.route_count.should == 3
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should correctly recognize a format (dynamic path path with . delimiter)" do
|
63
|
-
route_set.add_route('/:controller/:action/:id.:format')
|
64
|
-
route_set.recognize(build_request_mock_rails23('/sample/test/123.html', 'get', {:controller => 'sample', :action => 'test', :id => '123', :format => 'html'})).should == SampleController
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should support root nodes" do
|
68
|
-
route_set.add_route('/', :controller => 'sample')
|
69
|
-
route_set.recognize(build_request_mock_rails23('/', :get, {:controller => 'sample', :action => 'index'})).should == SampleController
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should default action to 'index' when controller (and not index) is specified" do
|
73
|
-
route_set.add_route('/:controller/:action')
|
74
|
-
route_set.recognize(build_request_mock_rails23('/sample', :get, {:controller => 'sample', :action => 'index'})).should == SampleController
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
end
|