path-to 0.0.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.2.0 2009-04-18
2
+
3
+ * Major enhancement
4
+ * Support for nested described_routes, friendlier initialisation
5
+
6
+ == 0.1.0 2009-04-18
7
+
8
+ * Major enhancement
9
+ * Support for described_routes
10
+
1
11
  == 0.0.3 2009-04-18
2
12
 
3
13
  * Minor enhancement:
data/README.rdoc CHANGED
@@ -6,7 +6,18 @@ path-to allows web applications to be modelled via URI templates and then access
6
6
 
7
7
  == Synopsis
8
8
 
9
- Here's a simple example that illustrates access to a CMS:
9
+ === Automatic configuration with described_routes
10
+
11
+ Create a client application configured from a server that supports described_routes:
12
+
13
+ require 'path-to/described_routes'
14
+
15
+ app = PathTo::DescribedRoutes::Application.new(:json => Net::HTTP.get(URI.parse("http://example.com/described_routes.json")))
16
+
17
+ app.users["user_id" => "dojo"].articles.recent #=> http://example.com/users/dojo/articles/recent
18
+ app.users["user_id" => "dojo"].articles.recent.get #=> "<html>...</html>"
19
+
20
+ === Local configuration
10
21
 
11
22
  require "path-to"
12
23
 
@@ -1,13 +1,13 @@
1
1
  require "path-to"
2
- require "described_routes"
2
+ require "described_routes/resource_template"
3
3
 
4
4
  module PathTo
5
5
  module DescribedRoutes
6
- class TemplatedPath < WithParams
6
+ class TemplatedPath < PathTo::Path
7
7
  attr_reader :resource_template
8
8
 
9
9
  def initialize(parent, service, params, resource_template)
10
- super(parent, service, params)
10
+ super(parent, resource_template.name, params)
11
11
  @resource_template = resource_template
12
12
 
13
13
  missing_params = resource_template.params - params.keys
@@ -21,7 +21,7 @@ module PathTo
21
21
  end
22
22
 
23
23
  def uri_template
24
- @uri_template ||= application.base + resource_template.path_template
24
+ @uri_template ||= resource_template.uri_template || (application.base + resource_template.path_template)
25
25
  end
26
26
 
27
27
  def uri
@@ -37,11 +37,47 @@ module PathTo
37
37
  def application
38
38
  @application ||= parent.application if parent
39
39
  end
40
+
41
+ # Delegated to the application
42
+ def child_class_for(instance, method, params, template)
43
+ application.child_class_for(instance, method, params, template)
44
+ end
45
+
46
+ #
47
+ # Creates a child instance with new params, potentially finding a nested resource template that takes the additional params
48
+ #
49
+ def [](params = {})
50
+ keys = self.params.merge(params).keys
51
+ child_resource_template = resource_template.resource_templates.detect{ |t|
52
+ t.rel.nil? && (t.params - keys).empty?
53
+ } || resource_template
54
+ child_class = child_class_for(self, nil, params, child_resource_template)
55
+ child(child_class, nil, params, child_resource_template)
56
+ end
57
+
58
+ #
59
+ # Tries to respond to a missing method. We can do so if
60
+ #
61
+ # 1. we can find a resource template with rel matching the method name (direct children only)
62
+ # 2. #child_class_for returns a class or other factory object capable of creating a new child instance
63
+ #
64
+ # Otherwise we invoke super in the hope of avoiding any hard-to-debug behaviour!
65
+ #
66
+ def method_missing(method, *args)
67
+ child_resource_template = resource_template.resource_templates.detect{|t| t.rel == method.to_s}
68
+ if resource_template && (child_class = child_class_for(self, method, params, child_resource_template))
69
+ params = args.inject(Hash.new){|h, arg| h.merge(arg)}
70
+ child(child_class, method, params, child_resource_template)
71
+ else
72
+ super
73
+ end
74
+ end
75
+
40
76
  end
41
77
 
42
78
  class Application < WithParams
43
79
  # An Array of DescribedRoutes::Resource objects
44
- attr_reader :resources
80
+ attr_reader :resource_templates
45
81
 
46
82
  # A Class (or at least something with a #new method) from which child objects will be created
47
83
  attr_reader :default_type
@@ -49,10 +85,27 @@ module PathTo
49
85
  # An HTTParty or similar
50
86
  attr_reader :http_client
51
87
 
88
+ # Base URI of the application
52
89
  attr_reader :base
53
90
 
54
- def initialize(resources, base, params = {}, default_type = TemplatedPath, http_client = HTTPClient)
55
- @base, @resources, @default_type, @http_client = base, resources, default_type, http_client
91
+ def initialize(options)
92
+ @base = options[:base]
93
+ @base.sub(/\/$/, '') if base
94
+ @params = options[:params] || {}
95
+ @default_type = options[:default_type] || TemplatedPath
96
+ @http_client = options[:http_client] || HTTPClient
97
+
98
+ @resource_templates = options[:resource_templates]
99
+ unless @resource_templates
100
+ if (json = options[:json])
101
+ @resource_templates = ::DescribedRoutes::ResourceTemplate.parse_json(json)
102
+ elsif (yaml = options[:yaml])
103
+ @resource_templates = ::DescribedRoutes::ResourceTemplate.parse_yaml(yaml)
104
+ elsif (xml = options[:xml])
105
+ @resource_templates = ::DescribedRoutes::ResourceTemplate.parse_xml(xml)
106
+ end
107
+ end
108
+
56
109
  super(nil, nil, params)
57
110
  end
58
111
 
@@ -93,7 +146,7 @@ module PathTo
93
146
  # Returns a hash of all ResourceTemplates (the tree flattened) keyed by name
94
147
  #
95
148
  def resource_templates_by_name
96
- @resource_templates_by_name ||= ::DescribedRoutes.all_by_name(resources)
149
+ @resource_templates_by_name ||= ::DescribedRoutes::ResourceTemplate.all_by_name(resource_templates)
97
150
  end
98
151
 
99
152
  #
data/lib/path-to/path.rb CHANGED
@@ -7,9 +7,8 @@ module PathTo
7
7
  # discovery process).
8
8
  #
9
9
  class Path < WithParams
10
-
11
10
  #
12
- # Finds (once) the application in the parent hierarchy.
11
+ # Finds (and remembers) the application in the parent hierarchy.
13
12
  #
14
13
  def application
15
14
  @application ||= parent.application if parent
@@ -22,6 +21,13 @@ module PathTo
22
21
  application.child_class_for(instance, service, args)
23
22
  end
24
23
 
24
+ #
25
+ # Returns the http_client of the application; override if necessary. See also HTTPClient.
26
+ #
27
+ def http_client
28
+ @http_client ||= application.http_client
29
+ end
30
+
25
31
  #
26
32
  # Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
27
33
  #
@@ -35,14 +41,6 @@ module PathTo
35
41
  def uri_template
36
42
  application.uri_template_for(self, service, params)
37
43
  end
38
-
39
- #
40
- # Returns the http_client of the application; override if necessary. See also HTTPClient.
41
- #
42
- def http_client
43
- @http_client ||= application.http_client
44
- end
45
-
46
44
  #
47
45
  # GET request on this object's URI
48
46
  #
@@ -9,13 +9,13 @@ module PathTo
9
9
  class WithParams
10
10
  # Parent object, presumably of type WithParams or descendant
11
11
  attr_reader :parent
12
-
13
- # Service identifier, typically a method symbol intercepted in #method_missing
14
- attr_reader :service
15
-
12
+
16
13
  # Parameter hash
17
14
  attr_reader :params
18
15
 
16
+ # Service identifier, typically a method symbol intercepted in #method_missing by parent
17
+ attr_reader :service
18
+
19
19
  #
20
20
  # Initialize a new WithParams object. Parameters:
21
21
  #
data/lib/path-to.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module PathTo
2
- VERSION = "0.0.5"
2
+ VERSION = "0.2.0"
3
3
  end
4
4
 
5
5
  $:.push File.dirname(__FILE__)
@@ -1 +1 @@
1
- [{"name":"root","path_template":"\/"},{"name":"admin_products","resource_templates":[{"name":"admin_product","resource_templates":[{"name":"edit_admin_product","options":["GET"],"path_template":"\/admin\/products\/{product_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["product_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/admin\/products\/{product_id}{-prefix|.|format}","optional_params":["format"],"params":["product_id"]},{"name":"new_admin_product","options":["GET"],"path_template":"\/admin\/products\/new{-prefix|.|format}","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/admin\/products{-prefix|.|format}","optional_params":["format"]},{"name":"pages","resource_templates":[{"name":"page","resource_templates":[{"name":"edit_page","options":["GET"],"path_template":"\/pages\/{page_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["page_id"]},{"name":"summary_page","options":["GET"],"path_template":"\/pages\/{page_id}\/summary{-prefix|.|format}","rel":"summary","optional_params":["format"],"params":["page_id"]},{"name":"toggle_visibility_page","options":["POST"],"path_template":"\/pages\/{page_id}\/toggle_visibility{-prefix|.|format}","rel":"toggle_visibility","optional_params":["format"],"params":["page_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/pages\/{page_id}{-prefix|.|format}","optional_params":["format"],"params":["page_id"]},{"name":"new_page","options":["GET"],"path_template":"\/pages\/new{-prefix|.|format}","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/pages{-prefix|.|format}","optional_params":["format"]},{"name":"users","resource_templates":[{"name":"user","resource_templates":[{"name":"user_articles","resource_templates":[{"name":"user_article","resource_templates":[{"name":"edit_user_article","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/{article_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id","article_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/users\/{user_id}\/articles\/{article_id}{-prefix|.|format}","optional_params":["format"],"params":["user_id","article_id"]},{"name":"new_user_article","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/new{-prefix|.|format}","optional_params":["format"],"params":["user_id"]},{"name":"recent_user_articles","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/recent{-prefix|.|format}","rel":"recent","optional_params":["format"],"params":["user_id"]}],"options":["GET","POST"],"path_template":"\/users\/{user_id}\/articles{-prefix|.|format}","rel":"articles","optional_params":["format"],"params":["user_id"]},{"name":"edit_user","options":["GET"],"path_template":"\/users\/{user_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id"]},{"name":"user_profile","resource_templates":[{"name":"edit_user_profile","options":["GET"],"path_template":"\/users\/{user_id}\/profile\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id"]},{"name":"new_user_profile","options":["GET"],"path_template":"\/users\/{user_id}\/profile\/new{-prefix|.|format}","rel":"new","optional_params":["format"],"params":["user_id"]}],"options":["GET","PUT","DELETE","POST"],"path_template":"\/users\/{user_id}\/profile{-prefix|.|format}","rel":"profile","optional_params":["format"],"params":["user_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/users\/{user_id}{-prefix|.|format}","optional_params":["format"],"params":["user_id"]},{"name":"new_user","options":["GET"],"path_template":"\/users\/new{-prefix|.|format}","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/users{-prefix|.|format}","optional_params":["format"]}]
1
+ [{"name":"root","path_template":"\/","uri_template":"http:\/\/localhost:3000\/"},{"name":"admin_products","resource_templates":[{"name":"admin_product","resource_templates":[{"name":"edit_admin_product","options":["GET"],"path_template":"\/admin\/products\/{product_id}\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/admin\/products\/{product_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["product_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/admin\/products\/{product_id}{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/admin\/products\/{product_id}{-prefix|.|format}","optional_params":["format"],"params":["product_id"]},{"name":"new_admin_product","options":["GET"],"path_template":"\/admin\/products\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/admin\/products\/new{-prefix|.|format}","rel":"new_admin_product","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/admin\/products{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/admin\/products{-prefix|.|format}","optional_params":["format"]},{"name":"described_routes","resource_templates":[{"name":"new_described_route","options":["GET"],"path_template":"\/described_routes\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/described_routes\/new{-prefix|.|format}","rel":"new_described_route","optional_params":["format"]},{"name":"described_route","resource_templates":[{"name":"edit_described_route","options":["GET"],"path_template":"\/described_routes\/{route_name}\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/described_routes\/{route_name}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"]}],"options":["GET","PUT","DELETE"],"path_template":"\/described_routes\/{route_name}{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/described_routes\/{route_name}{-prefix|.|format}","rel":"described_route","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/described_routes{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/described_routes{-prefix|.|format}","optional_params":["format"]},{"name":"pages","resource_templates":[{"name":"page","resource_templates":[{"name":"edit_page","options":["GET"],"path_template":"\/pages\/{page_id}\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages\/{page_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["page_id"]},{"name":"summary_page","options":["GET"],"path_template":"\/pages\/{page_id}\/summary{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages\/{page_id}\/summary{-prefix|.|format}","rel":"summary","optional_params":["format"],"params":["page_id"]},{"name":"toggle_visibility_page","options":["POST"],"path_template":"\/pages\/{page_id}\/toggle_visibility{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages\/{page_id}\/toggle_visibility{-prefix|.|format}","rel":"toggle_visibility","optional_params":["format"],"params":["page_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/pages\/{page_id}{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages\/{page_id}{-prefix|.|format}","optional_params":["format"],"params":["page_id"]},{"name":"new_page","options":["GET"],"path_template":"\/pages\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages\/new{-prefix|.|format}","rel":"new_page","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/pages{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/pages{-prefix|.|format}","optional_params":["format"]},{"name":"users","resource_templates":[{"name":"user","resource_templates":[{"name":"user_articles","resource_templates":[{"name":"user_article","resource_templates":[{"name":"edit_user_article","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/{article_id}\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/articles\/{article_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id","article_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/users\/{user_id}\/articles\/{article_id}{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/articles\/{article_id}{-prefix|.|format}","optional_params":["format"],"params":["user_id","article_id"]},{"name":"new_user_article","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/articles\/new{-prefix|.|format}","rel":"new_user_article","optional_params":["format"],"params":["user_id"]},{"name":"recent_user_articles","options":["GET"],"path_template":"\/users\/{user_id}\/articles\/recent{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/articles\/recent{-prefix|.|format}","rel":"recent","optional_params":["format"],"params":["user_id"]}],"options":["GET","POST"],"path_template":"\/users\/{user_id}\/articles{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/articles{-prefix|.|format}","rel":"articles","optional_params":["format"],"params":["user_id"]},{"name":"edit_user","options":["GET"],"path_template":"\/users\/{user_id}\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id"]},{"name":"user_profile","resource_templates":[{"name":"edit_user_profile","options":["GET"],"path_template":"\/users\/{user_id}\/profile\/edit{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/profile\/edit{-prefix|.|format}","rel":"edit","optional_params":["format"],"params":["user_id"]},{"name":"new_user_profile","options":["GET"],"path_template":"\/users\/{user_id}\/profile\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/profile\/new{-prefix|.|format}","rel":"new","optional_params":["format"],"params":["user_id"]}],"options":["GET","PUT","DELETE","POST"],"path_template":"\/users\/{user_id}\/profile{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}\/profile{-prefix|.|format}","rel":"profile","optional_params":["format"],"params":["user_id"]}],"options":["GET","PUT","DELETE"],"path_template":"\/users\/{user_id}{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/{user_id}{-prefix|.|format}","optional_params":["format"],"params":["user_id"]},{"name":"new_user","options":["GET"],"path_template":"\/users\/new{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users\/new{-prefix|.|format}","rel":"new_user","optional_params":["format"]}],"options":["GET","POST"],"path_template":"\/users{-prefix|.|format}","uri_template":"http:\/\/localhost:3000\/users{-prefix|.|format}","optional_params":["format"]}]
@@ -8,15 +8,37 @@ class TestDescribedRoutes < Test::Unit::TestCase
8
8
  BASE = "http://localhost"
9
9
 
10
10
  RESOURCE_TEMPLATE_NAMES = [
11
- "admin_product", "admin_products", "edit_admin_product", "edit_page", "edit_user", "edit_user_article",
12
- "edit_user_profile", "new_admin_product", "new_page", "new_user", "new_user_article", "new_user_profile",
13
- "page", "pages", "recent_user_articles", "root", "summary_page", "toggle_visibility_page", "user",
14
- "user_article", "user_articles", "user_profile", "users"]
11
+ "admin_product",
12
+ "admin_products",
13
+ "described_route",
14
+ "described_routes",
15
+ "edit_admin_product",
16
+ "edit_described_route",
17
+ "edit_page",
18
+ "edit_user",
19
+ "edit_user_article",
20
+ "edit_user_profile",
21
+ "new_admin_product",
22
+ "new_described_route",
23
+ "new_page",
24
+ "new_user",
25
+ "new_user_article",
26
+ "new_user_profile",
27
+ "page",
28
+ "pages",
29
+ "recent_user_articles",
30
+ "root",
31
+ "summary_page",
32
+ "toggle_visibility_page",
33
+ "user",
34
+ "user_article",
35
+ "user_articles",
36
+ "user_profile",
37
+ "users"]
15
38
 
16
39
  def setup
17
- @json ||= File.read(File.dirname(__FILE__) + "/fixtures/described_routes_test.json")
18
- resource_templates = DescribedRoutes.parse_json(@json)
19
- @app = PathTo::DescribedRoutes::Application.new(resource_templates, BASE)
40
+ json ||= File.read(File.dirname(__FILE__) + "/fixtures/described_routes_test.json")
41
+ @app = PathTo::DescribedRoutes::Application.new(:base => BASE, :json => json)
20
42
  end
21
43
 
22
44
  def test_resource_templates_by_name
@@ -24,29 +46,49 @@ class TestDescribedRoutes < Test::Unit::TestCase
24
46
  assert_kind_of(DescribedRoutes::ResourceTemplate, app.resource_templates_by_name["user"])
25
47
  end
26
48
 
27
- def test_child_class_for
49
+ def test_app_child_class_for
28
50
  assert_equal(PathTo::DescribedRoutes::TemplatedPath, app.child_class_for(nil, nil, nil, nil))
29
51
  assert_equal(PathTo::DescribedRoutes::TemplatedPath, app.child_class_for(nil, :user, nil, nil))
30
52
  end
31
53
 
32
- def test_child_with_missing_params
54
+ def test_app_child_with_missing_params
33
55
  assert_raises(ArgumentError) do
34
56
  app.edit_user
35
57
  end
36
58
  end
37
59
 
38
- def test_child_with_insufficient_params
60
+ def test_app_child_with_insufficient_params
39
61
  assert_raises(ArgumentError) do
40
62
  app.user_article("user_id" => "dojo")
41
63
  end
42
64
  end
43
65
 
44
- def test_child_with_no_params
45
- assert_kind_of(PathTo::DescribedRoutes::TemplatedPath, app.users)
66
+ def test_app_child_with_no_params
67
+ assert_equal('users', app.users.resource_template.name)
46
68
  end
47
69
 
48
- def test_children_with_params
49
- assert_kind_of(PathTo::DescribedRoutes::TemplatedPath, app.user("user_id" => "dojo"))
50
- assert_kind_of(PathTo::DescribedRoutes::TemplatedPath, app.user_article("user_id" => "dojo", "article_id" => "first-post"))
70
+ def test_app_children_with_params
71
+ assert_equal('user', app.user("user_id" => "dojo").resource_template.name)
72
+ assert_equal('user_article', app.user_article("user_id" => "dojo", "article_id" => "first-post").resource_template.name)
73
+ end
74
+
75
+ def test_app_bad_child_name
76
+ assert_raises(NoMethodError) do
77
+ app.flooby
78
+ end
79
+ end
80
+
81
+ def test_path_collection_member
82
+ assert_equal('user', app.users["user_id" => "dojo"].resource_template.name)
83
+ end
84
+
85
+ def test_nested_resource
86
+ assert_equal('user_articles', app.users["user_id" => "dojo"].articles.resource_template.name)
87
+ end
88
+
89
+ def test_bad_nested_resource
90
+ assert_raises(NoMethodError) do
91
+ app.users.users
92
+ end
51
93
  end
52
94
  end
@@ -17,6 +17,12 @@ module PathTo
17
17
  @users = @app.users
18
18
  end
19
19
 
20
+ def test_service
21
+ assert_equal(:users, app.users.service)
22
+ assert_equal(:articles, app.articles.service)
23
+ assert_equal(:articles, app.users.articles.service)
24
+ end
25
+
20
26
  def test_application
21
27
  assert_equal(app, users.application)
22
28
  assert_equal(app, users.articles.application)
@@ -20,14 +20,6 @@ module PathTo
20
20
  @s1 = WithParamsSubclass1.new
21
21
  end
22
22
 
23
- def test_service
24
- assert_nil(WithParams.new.service)
25
- assert_equal(:root, root.service)
26
- assert_equal(:root, root.child.service)
27
- assert_equal(:child, root.child(nil, :child).service)
28
- assert_equal(:child, root.child(nil, :child).child.service)
29
- end
30
-
31
23
  def test_params
32
24
  assert_equal({}, WithParams.new.params)
33
25
  assert_equal({:x => 1}, root.params)
@@ -43,8 +35,7 @@ module PathTo
43
35
  assert_kind_of(WithParamsSubclass2, s1.child.child)
44
36
  end
45
37
 
46
- def test_ary_params
47
- assert_equal(:root, root[].service)
38
+ def test_indexed_params
48
39
  assert_equal({:x => 1}, root[].params)
49
40
  assert_equal({:x => 2}, root[:x => 2].params)
50
41
  assert_equal({:x => 1, :y => 2}, root[:y => 2].params)
@@ -52,7 +43,6 @@ module PathTo
52
43
 
53
44
  def test_method_missing
54
45
  assert_kind_of(WithParams, root.flooby)
55
- assert_equal(:flooby, root.flooby.service)
56
46
  assert_equal({:x => 1}, root.flooby.params)
57
47
  assert_equal({:x => 1, :y => 2}, root.flooby[:y => 2].params)
58
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path-to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Burrows (asplake)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-27 00:00:00 +01:00
12
+ date: 2009-04-29 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency