path-to 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  == Description
4
4
 
5
- path-to allows web applications to be modelled via URI templates and then accessed through an application-specific Ruby API. It is
6
- designed to be extended easily to support discovery mechanisms; support for XRD may be added at some future date.
5
+ path-to allows web applications to be modelled via URI templates and then accessed through an application-specific Ruby API. It is designed to be extended easily to support discovery mechanisms; support for XRD may be added at some future date.
7
6
 
8
7
  == Synopsis
9
8
 
data/lib/path-to/path.rb CHANGED
@@ -29,6 +29,13 @@ module PathTo
29
29
  application.uri_for(service, params)
30
30
  end
31
31
 
32
+ #
33
+ # Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
34
+ #
35
+ def uri_template
36
+ application.uri_template_for(self, service, params)
37
+ end
38
+
32
39
  #
33
40
  # Returns the http_client of the application; override if necessary. See also HTTPClient.
34
41
  #
@@ -34,11 +34,11 @@ module PathTo
34
34
  # [service] Value for the new instance's service attribute, inherited from self (the parent) if none supplied
35
35
  # [params] The new instance's params, will be merged with self's (the parent's) params
36
36
  #
37
- def child(child_class = nil, service = nil, params = {})
37
+ def child(child_class = nil, service = nil, params = {}, *other_args)
38
38
  child_class ||= child_class_for(instance, service, params)
39
39
  service ||= self.service
40
40
  params = self.params.merge(params)
41
- child_class.new(self, service, params)
41
+ child_class.new(self, service, params, *other_args)
42
42
  end
43
43
 
44
44
  #
data/lib/path-to.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module PathTo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
4
4
 
5
5
  $:.push File.dirname(__FILE__)
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'path-to/described_routes'
4
+
5
+ class TestDescribedRoutes < Test::Unit::TestCase
6
+ attr_reader :app
7
+
8
+ BASE = "http://localhost"
9
+
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"]
15
+
16
+ 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)
20
+ end
21
+
22
+ def test_resource_templates_by_name
23
+ assert_equal(RESOURCE_TEMPLATE_NAMES, app.resource_templates_by_name.keys.sort)
24
+ assert_kind_of(DescribedRoutes::ResourceTemplate, app.resource_templates_by_name["user"])
25
+ end
26
+
27
+ def test_child_class_for
28
+ assert_equal(PathTo::DescribedRoutes::TemplatedPath, app.child_class_for(nil, nil, nil, nil))
29
+ assert_equal(PathTo::DescribedRoutes::TemplatedPath, app.child_class_for(nil, :user, nil, nil))
30
+ end
31
+
32
+ def test_child_with_missing_params
33
+ assert_raises(ArgumentError) do
34
+ app.edit_user
35
+ end
36
+ end
37
+
38
+ def test_child_with_insufficient_params
39
+ assert_raises(ArgumentError) do
40
+ app.user_article("user_id" => "dojo")
41
+ end
42
+ end
43
+
44
+ def test_child_with_no_params
45
+ assert_kind_of(PathTo::DescribedRoutes::TemplatedPath, app.users)
46
+ end
47
+
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"))
51
+ end
52
+ 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.3
4
+ version: 0.0.4
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-18 00:00:00 +01:00
12
+ date: 2009-04-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,9 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.8.0
54
54
  version:
55
- description: |-
56
- path-to allows web applications to be modelled via URI templates and then accessed through an application-specific Ruby API. It is
57
- designed to be extended easily to support discovery mechanisms; support for XRD may be added at some future date.
55
+ description: path-to allows web applications to be modelled via URI templates and then accessed through an application-specific Ruby API. It is designed to be extended easily to support discovery mechanisms; support for XRD may be added at some future date.
58
56
  email:
59
57
  - mjb@asplake.co.uk
60
58
  executables: []
@@ -116,6 +114,7 @@ specification_version: 3
116
114
  summary: path-to allows web applications to be modelled via URI templates and then accessed through an application-specific Ruby API
117
115
  test_files:
118
116
  - test/path-to/test_application.rb
117
+ - test/path-to/test_described_routes.rb
119
118
  - test/path-to/test_path.rb
120
119
  - test/path-to/test_with_params.rb
121
120
  - test/test_helper.rb