committee 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,8 @@ module Committee
4
4
  @routes = build_routes(schema)
5
5
  end
6
6
 
7
- def routes?(method, path)
7
+ def routes?(method, path, options = {})
8
+ path = path.gsub(/^#{options[:prefix]}/, "") if options[:prefix]
8
9
  if method_routes = @routes[method]
9
10
  method_routes.each do |pattern, link, schema|
10
11
  if path =~ pattern
@@ -15,8 +16,8 @@ module Committee
15
16
  [nil, nil]
16
17
  end
17
18
 
18
- def routes_request?(request)
19
- routes?(request.request_method, request.path_info)
19
+ def routes_request?(request, options = {})
20
+ routes?(request.request_method, request.path_info, options)
20
21
  end
21
22
 
22
23
  private
@@ -6,7 +6,8 @@ module Committee::Test
6
6
  @schema ||= Committee::Schema.new(File.read(schema_path))
7
7
  @router ||= Committee::Router.new(@schema)
8
8
 
9
- link_schema, type_schema = @router.routes_request?(last_request)
9
+ link_schema, type_schema =
10
+ @router.routes_request?(last_request, prefix: schema_url_prefix)
10
11
 
11
12
  unless link_schema
12
13
  response = "`#{last_request.request_method} #{last_request.path_info}` undefined in schema."
@@ -32,5 +33,9 @@ module Committee::Test
32
33
  def schema_path
33
34
  raise "Please override #schema_path."
34
35
  end
36
+
37
+ def schema_url_prefix
38
+ nil
39
+ end
35
40
  end
36
41
  end
data/test/router_test.rb CHANGED
@@ -14,4 +14,9 @@ describe Committee::Router do
14
14
  it "builds routes with parameters" do
15
15
  assert @router.routes?("GET", "/apps/123")
16
16
  end
17
+
18
+ it "takes a prefix" do
19
+ # this is a sociopathic example
20
+ assert @router.routes?("GET", "/kpi/apps/123", prefix: "/kpi")
21
+ end
17
22
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "minitest"
2
2
  require "minitest/spec"
3
- require 'minitest/pride'
4
3
  require "minitest/autorun"
5
4
 
6
5
  require "bundler/setup"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: committee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-20 00:00:00.000000000 Z
13
+ date: 2014-04-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json