joshbuddy-usher 0.4.3 → 0.4.5

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.
@@ -1,39 +1,41 @@
1
1
  require 'lib/usher'
2
2
 
3
- route_set = Usher.new
4
3
 
5
4
  describe "Usher grapher" do
6
5
 
7
6
  before(:each) do
8
- route_set.reset!
7
+ @route_set = Usher.new
8
+ @route_set.reset!
9
+ @url_generator = Usher::Generators::URL.new(@route_set)
9
10
  end
10
11
 
11
12
  it "should find a simple path" do
12
- route_set.add_route('/:a/:b/:c')
13
- route_set.generate_url(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
13
+ @route_set.add_route('/:a/:b/:c')
14
+ @url_generator.generate(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
14
15
  end
15
16
 
16
17
  it "should pick a more specific route" do
17
- route_set.add_route('/:a/:b')
18
- route_set.add_route('/:a/:b/:c')
19
- route_set.generate_url(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
18
+ @route_set.add_route('/:a/:b')
19
+ @route_set.add_route('/:a/:b/:c')
20
+ @url_generator.generate(nil, {:a => 'A', :b => 'B', :c => 'C'}).should == '/A/B/C'
20
21
  end
21
22
 
22
23
  it "should fail to generate a route when none matches" do
23
- route_set.add_route('/:a/:b')
24
- proc {route_set.generate_url(nil, {:c => 'C', :d => 'D'}) }.should raise_error Usher::UnrecognizedException
24
+ @route_set.add_route('/:a/:b')
25
+ proc {@url_generator.generate(nil, {:c => 'C', :d => 'D'}) }.should raise_error Usher::UnrecognizedException
25
26
  end
26
27
 
27
28
  it "should find the most specific route and append extra parts on as a query string" do
28
- route_set.add_route('/:a/:b/:c')
29
- route_set.add_route('/:a/:b')
30
- route_set.generate_url(nil, {:a => 'A', :b => 'B', :d => 'C'}).should == '/A/B?d=C'
29
+ @route_set.add_route('/:a/:b/:c')
30
+ @route_set.add_route('/:a/:b')
31
+ @url_generator.generate(nil, {:a => 'A', :b => 'B', :d => 'C'}).should == '/A/B?d=C'
31
32
  end
32
33
 
33
- it "should do a validity check against the incoming variables when asked to" do
34
- route_set.add_route('/:a/:b', :b => /\d+/)
35
- route_set.generate_url(nil, {:a => 'A', :b => 'B'}).should == '/A/B'
36
- proc{ route_set.generate_url(nil, {:a => 'A', :b => 'B'}, :check_variables => true).should == '/A/B?d=C'}.should raise_error Usher::ValidationException
37
- end
34
+ # FIXME
35
+ #it "should do a validity check against the incoming variables when asked to" do
36
+ # route_set.add_route('/:a/:b', :b => /\d+/)
37
+ # route_set.generate_url(nil, {:a => 'A', :b => 'B'}).should == '/A/B'
38
+ # proc{ route_set.generate_url(nil, {:a => 'A', :b => 'B'})}.should raise_error Usher::ValidationException
39
+ #end
38
40
 
39
41
  end
@@ -22,12 +22,12 @@ describe "Usher route adding" do
22
22
  it "should add every kind of optional route possible" do
23
23
  route_set.add_route('/a/b(/c)(/d(/e))')
24
24
  route_set.routes.first.paths.collect{|a| a.parts }.should == [
25
- [:/, "a", :/, "b"],
26
- [:/, "a", :/, "b", :/, "c", :/, "d"],
27
- [:/, "a", :/, "b", :/, "d", :/, "e"],
28
- [:/, "a", :/, "b", :/, "c"],
29
- [:/, "a", :/, "b", :/, "d"],
30
- [:/, "a", :/, "b", :/, "c", :/, "d", :/, "e"]
25
+ ['/', "a", '/', "b"],
26
+ ['/', "a", '/', "b", '/', "c", '/', "d"],
27
+ ['/', "a", '/', "b", '/', "d", '/', "e"],
28
+ ['/', "a", '/', "b", '/', "c"],
29
+ ['/', "a", '/', "b", '/', "d"],
30
+ ['/', "a", '/', "b", '/', "c", '/', "d", '/', "e"]
31
31
  ]
32
32
 
33
33
  end
@@ -39,7 +39,7 @@ describe "Usher route adding" do
39
39
  it "should calculate depths for nodes" do
40
40
  route_set.add_named_route(:route, '/bad/route/three/four')
41
41
  route_set.tree.depth.should == 0
42
- route_set.tree.lookup[:/].depth.should == 1
42
+ route_set.tree.lookup['/'].depth.should == 1
43
43
  end
44
44
 
45
45
  it "should pp for nodes" do
@@ -47,19 +47,19 @@ describe "Usher route adding" do
47
47
  route_set.tree.depth.should == 0
48
48
  old_out = $stdout
49
49
  $stdout = (output = StringIO.new)
50
- route_set.tree.lookup[:/].lookup['bad'].lookup[:/].pp
50
+ route_set.tree.lookup['/'].lookup['bad'].lookup['/'].pp
51
51
  $stdout = old_out
52
52
  output.rewind
53
53
  output.read.should == <<-HEREDOC
54
- 3: :/ false
54
+ 3: "/" false
55
55
  route ==>
56
56
  4: "route" false
57
57
  / ==>
58
- 5: :/ false
58
+ 5: "/" false
59
59
  three ==>
60
60
  6: "three" false
61
61
  / ==>
62
- 7: :/ false
62
+ 7: "/" false
63
63
  four ==>
64
64
  8: "four" true
65
65
  HEREDOC
File without changes
@@ -1,9 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), 'compat')
2
2
  require 'lib/usher'
3
3
 
4
- route_set = Usher::Interface.for(:rails2)
4
+ route_set = Usher::Interface.for(:rails2_2)
5
5
 
6
- describe "Usher (for rails) URL generation" do
6
+ describe "Usher (for rails 2.2) URL generation" do
7
7
 
8
8
  before(:each) do
9
9
  route_set.reset!
@@ -1,9 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), 'compat')
2
2
  require 'lib/usher'
3
3
 
4
- route_set = Usher::Interface.for(:rails2)
4
+ route_set = Usher::Interface.for(:rails2_2)
5
5
 
6
- describe "Usher (for rails) route adding" do
6
+ describe "Usher (for rails 2.2) route adding" do
7
7
 
8
8
  before(:each) do
9
9
  route_set.reset!
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'compat')
2
2
  require 'lib/usher'
3
3
  require 'action_controller'
4
4
 
5
- route_set = Usher::Interface.for(:rails2)
5
+ route_set = Usher::Interface.for(:rails2_2)
6
6
 
7
7
  def build_request_mock(path, method, params)
8
8
  request = mock "Request"
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  SampleController = Object.new
18
18
 
19
- describe "Usher (for rails) route recognition" do
19
+ describe "Usher (for rails 2.2) route recognition" do
20
20
 
21
21
  before(:each) do
22
22
  route_set.reset!
@@ -0,0 +1 @@
1
+ require 'activesupport'
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'compat')
2
+ require 'lib/usher'
3
+
4
+ route_set = Usher::Interface.for(:rails2_3)
5
+
6
+ describe "Usher (for rails 2.3) URL generation" do
7
+
8
+ before(:each) do
9
+ route_set.reset!
10
+ end
11
+
12
+ it "should fill in the controller from recall" do
13
+ route_set.add_route('/:controller/:action/:id')
14
+ route_set.generate({:action => 'thingy'}, {:controller => 'sample', :action => 'index', :id => 123}, :generate).should == '/sample/thingy'
15
+ end
16
+
17
+ it "should skip the action if not provided" do
18
+ route_set.add_route('/:controller/:action/:id')
19
+ route_set.generate({:controller => 'thingy'}, {:controller => 'sample', :action => 'index', :id => 123}, :generate).should == '/thingy'
20
+ end
21
+
22
+ it "should pick the correct param from optional parts" do
23
+ route_set.add_route('/:controller/:action(.:format)')
24
+ route_set.generate({:action => 'thingy', :format => 'html'}, {:controller => 'sample', :action => 'index', :id => 123}, :generate).should == '/sample/thingy.html'
25
+ route_set.generate({:action => 'thingy'}, {:controller => 'sample', :action => 'index', :id => 123}, :generate).should == '/sample/thingy'
26
+ end
27
+
28
+ end
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), 'compat')
2
+ require 'lib/usher'
3
+
4
+ route_set = Usher::Interface.for(:rails2_3)
5
+
6
+ describe "Usher (for rails 2.3) route adding" do
7
+
8
+ before(:each) do
9
+ route_set.reset!
10
+ end
11
+
12
+ it "shouldn't allow routes without a controller to be added" do
13
+ proc { route_set.add_route('/bad/route') }.should raise_error
14
+ end
15
+
16
+ end
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), 'compat')
2
+ require 'lib/usher'
3
+ require 'action_controller'
4
+
5
+ route_set = Usher::Interface.for(:rails2_3)
6
+
7
+ def build_request_mock(path, method, params)
8
+ request = mock "Request"
9
+ request.should_receive(:path).any_number_of_times.and_return(path)
10
+ request.should_receive(:method).any_number_of_times.and_return(method)
11
+ params = params.with_indifferent_access
12
+ request.should_receive(:path_parameters=).any_number_of_times.with(params)
13
+ request.should_receive(:path_parameters).any_number_of_times.and_return(params)
14
+ request
15
+ end
16
+
17
+ SampleController = Object.new
18
+
19
+ describe "Usher (for rails 2.3) route recognition" do
20
+
21
+ before(:each) do
22
+ route_set.reset!
23
+ end
24
+
25
+ it "should recognize a simple request" do
26
+ route_set.add_route('/sample', :controller => 'sample', :action => 'action')
27
+ route_set.recognize(build_request_mock('/sample', 'get', {:controller => 'sample', :action => 'action'})).should == SampleController
28
+ end
29
+
30
+ it "should interpolate action :index" do
31
+ route_set.add_route('/sample', :controller => 'sample')
32
+ route_set.recognize(build_request_mock('/sample', 'get', {:controller => 'sample', :action => 'index'})).should == SampleController
33
+ end
34
+
35
+ it "should correctly distinguish between multiple request methods" do
36
+ route_set.add_route('/sample', :controller => 'not_sample', :conditions => {:method => :get})
37
+ correct_route = route_set.add_route('/sample', :controller => 'sample', :conditions => {:method => :post})
38
+ route_set.add_route('/sample', :controller => 'not_sample', :conditions => {:method => :put})
39
+ route_set.recognize(build_request_mock('/sample', :post, {:controller => 'sample', :action => 'index'})).should == SampleController
40
+ end
41
+
42
+ it "should prefer the static route to the dynamic route" do
43
+ route_set.add_route('/sample/:action', :controller => 'not_sample')
44
+ route_set.add_route('/sample/test', :controller => 'sample', :action => 'action')
45
+ route_set.recognize(build_request_mock('/sample/test', 'get', {:controller => 'sample', :action => 'action'})).should == SampleController
46
+ end
47
+
48
+ it "should raise based upon an invalid param" do
49
+ route_set.add_named_route(:sample, '/sample/:action', :controller => 'sample', :requirements => {:action => /\d+/})
50
+ proc { route_set.recognize(build_request_mock('/sample/asdqwe', :post, {})) }.should raise_error
51
+ end
52
+
53
+ it "should raise based upon an invalid route" do
54
+ route_set.add_named_route(:sample, '/sample', :controller => 'sample', :action => 'test')
55
+ proc { route_set.recognize(build_request_mock('/test/asdqwe', :post, {})) }.should raise_error
56
+ end
57
+
58
+ it "should add /:controller and /:controller/:action if /:controller/:action/:id is added" do
59
+ route_set.add_route('/:controller/:action/:id')
60
+ route_set.route_count.should == 3
61
+ end
62
+
63
+ it "should correctly recognize a format (dynamic path path with . delimiter)" do
64
+ route_set.add_route('/:controller/:action/:id.:format')
65
+ route_set.recognize(build_request_mock('/sample/test/123.html', 'get', {:controller => 'sample', :action => 'test', :id => '123', :format => 'html'})).should == SampleController
66
+ end
67
+
68
+ it "should support root nodes" do
69
+ route_set.add_route('/', :controller => 'sample')
70
+ route_set.recognize(build_request_mock('/', :get, {:controller => 'sample', :action => 'index'})).should == SampleController
71
+ end
72
+
73
+ it "should default action to 'index' when controller (and not index) is specified" do
74
+ route_set.add_route('/:controller/:action')
75
+ route_set.recognize(build_request_mock('/sample', :get, {:controller => 'sample', :action => 'index'})).should == SampleController
76
+ end
77
+
78
+
79
+ end
@@ -4,62 +4,62 @@ describe "Usher route tokenizing" do
4
4
 
5
5
 
6
6
  it "should split / delimited routes" do
7
- Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this/split').should == [[:/, 'test', :/,'this', :/, 'split']]
7
+ Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this/split').should == [['/', 'test', '/','this', '/', 'split']]
8
8
  end
9
9
 
10
10
  it "should split / delimited routes with a regex in it" do
11
11
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').
12
- split('/test/{this}/split').should == [[:/, 'test', :/, /this/, :/, 'split']]
12
+ split('/test/{this}/split').should == [['/', 'test', '/', /this/, '/', 'split']]
13
13
  end
14
14
 
15
15
  it "should split on ' ' delimited routes as well" do
16
- Usher::Splitter.for_delimiters([' '], '[0-9A-Za-z\$\-_\+!\*\',]+').split('test this split').should == [['test', :' ', 'this', :' ', 'split']]
16
+ Usher::Splitter.for_delimiters([' '], '[0-9A-Za-z\$\-_\+!\*\',]+').split('test this split').should == [['test', ' ', 'this', ' ', 'split']]
17
17
  end
18
18
 
19
19
  it "should split on email delimiters as well" do
20
- Usher::Splitter.for_delimiters(['@', '+', '-', '.'], '[a-zA-Z0-9]+').split('one+more.12345-09876-alphanum3ric5@domain.com').should == [["one", :+, "more", :".", "12345", :-, "09876", :-, "alphanum3ric5", :"@", "domain", :".", "com"]]
20
+ Usher::Splitter.for_delimiters(['@', '+', '-', '.'], '[a-zA-Z0-9]+').split('one+more.12345-09876-alphanum3ric5@domain.com').should == [["one", '+', "more", ".", "12345", '-', "09876", '-', "alphanum3ric5", "@", "domain", ".", "com"]]
21
21
  end
22
22
 
23
23
  it "should split on ' ' delimited routes for more complex routes as well" do
24
- Usher::Splitter.for_delimiters([' '], '[0-9A-Za-z\$\-_\+!\*\',]+').split('(test|this) split').should == [['test', :' ', 'split'], ['this', :' ', 'split']]
24
+ Usher::Splitter.for_delimiters([' '], '[0-9A-Za-z\$\-_\+!\*\',]+').split('(test|this) split').should == [['test', ' ', 'split'], ['this', ' ', 'split']]
25
25
  end
26
26
 
27
27
  it "should group optional parts with brackets" do
28
28
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this(/split)').should == [
29
- [:/, 'test', :/, 'this'],
30
- [:/, 'test', :/, 'this', :/, 'split']
29
+ ['/', 'test', '/', 'this'],
30
+ ['/', 'test', '/', 'this', '/', 'split']
31
31
  ]
32
32
  end
33
33
 
34
34
  it "should group exclusive optional parts with brackets and pipes" do
35
35
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this(/split|/split2)').should == [
36
- [:/, 'test', :/, 'this',:/, 'split'],
37
- [:/, 'test', :/, 'this',:/, 'split2']
36
+ ['/', 'test', '/', 'this','/', 'split'],
37
+ ['/', 'test', '/', 'this','/', 'split2']
38
38
  ]
39
39
  end
40
40
 
41
41
  it "should group exclusive optional-optional parts with brackets and pipes" do
42
42
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this((/split|/split2))').should == [
43
- [:/, 'test',:/, 'this'],
44
- [:/, 'test',:/, 'this', :/, 'split'],
45
- [:/, 'test',:/, 'this', :/, 'split2']
43
+ ['/', 'test','/', 'this'],
44
+ ['/', 'test','/', 'this', '/', 'split'],
45
+ ['/', 'test','/', 'this', '/', 'split2']
46
46
  ]
47
47
  end
48
48
 
49
49
  it "should group optional parts with brackets (for non overlapping groups)" do
50
50
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this(/split)(/split2)') == [
51
- [:/, "test", :/, "this"],
52
- [:/, "test", :/, "this", :/, "split"],
53
- [:/, "test", :/, "this", :/, "split2"],
54
- [:/, "test", :/, "this", :/, "split", :/, "split2"]
51
+ ['/', "test", '/', "this"],
52
+ ['/', "test", '/', "this", '/', "split"],
53
+ ['/', "test", '/', "this", '/', "split2"],
54
+ ['/', "test", '/', "this", '/', "split", '/', "split2"]
55
55
  ]
56
56
  end
57
57
 
58
58
  it "should group nested-optional parts with brackets" do
59
59
  Usher::Splitter.for_delimiters(['/', '.'], '[0-9A-Za-z\$\-_\+!\*\',]+').split('/test/this(/split(.:format))') == [
60
- [:/, "test", :/, "this"],
61
- [:/, "test", :/, "this", :/, "split"],
62
- [:/, "test", :/, "this", :/, "split", :'.', Usher::Route::Variable.new(:':', :format)]
60
+ ['/', "test", '/', "this"],
61
+ ['/', "test", '/', "this", '/', "split"],
62
+ ['/', "test", '/', "this", '/', "split", '.', Usher::Route::Variable.new(:':', :format)]
63
63
  ]
64
64
  end
65
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joshbuddy-usher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-15 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,7 @@ files:
38
38
  - VERSION.yml
39
39
  - lib/usher
40
40
  - lib/usher/exceptions.rb
41
+ - lib/usher/generate.rb
41
42
  - lib/usher/grapher.rb
42
43
  - lib/usher/interface
43
44
  - lib/usher/interface/email_interface.rb
@@ -46,9 +47,10 @@ files:
46
47
  - lib/usher/interface/rack_interface/mapper.rb
47
48
  - lib/usher/interface/rack_interface/route.rb
48
49
  - lib/usher/interface/rack_interface.rb
49
- - lib/usher/interface/rails2_interface
50
- - lib/usher/interface/rails2_interface/mapper.rb
51
- - lib/usher/interface/rails2_interface.rb
50
+ - lib/usher/interface/rails2_2_interface
51
+ - lib/usher/interface/rails2_2_interface/mapper.rb
52
+ - lib/usher/interface/rails2_2_interface.rb
53
+ - lib/usher/interface/rails2_3_interface.rb
52
54
  - lib/usher/interface.rb
53
55
  - lib/usher/node.rb
54
56
  - lib/usher/route
@@ -66,11 +68,16 @@ files:
66
68
  - spec/private/path_spec.rb
67
69
  - spec/private/rack
68
70
  - spec/private/rack/dispatch_spec.rb
69
- - spec/private/rails
70
- - spec/private/rails/compat.rb
71
- - spec/private/rails/generate_spec.rb
72
- - spec/private/rails/path_spec.rb
73
- - spec/private/rails/recognize_spec.rb
71
+ - spec/private/rails2_2
72
+ - spec/private/rails2_2/compat.rb
73
+ - spec/private/rails2_2/generate_spec.rb
74
+ - spec/private/rails2_2/path_spec.rb
75
+ - spec/private/rails2_2/recognize_spec.rb
76
+ - spec/private/rails2_3
77
+ - spec/private/rails2_3/compat.rb
78
+ - spec/private/rails2_3/generate_spec.rb
79
+ - spec/private/rails2_3/path_spec.rb
80
+ - spec/private/rails2_3/recognize_spec.rb
74
81
  - spec/private/recognize_spec.rb
75
82
  - spec/private/request_method_spec.rb
76
83
  - spec/private/split_spec.rb