usher 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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