rack-api 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source :rubygems
2
+ gem "rack-test", :git => "https://github.com/brynary/rack-test.git"
3
+
2
4
  gemspec
@@ -1,53 +1,58 @@
1
+ GIT
2
+ remote: https://github.com/brynary/rack-test.git
3
+ revision: cab8eb929b45d9e32474fad1b6806c2ab8f6bea8
4
+ specs:
5
+ rack-test (0.6.1)
6
+ rack (>= 1.0)
7
+
1
8
  PATH
2
9
  remote: .
3
10
  specs:
4
- rack-api (1.0.2)
5
- activesupport (>= 3.0.0)
11
+ rack-api (1.1.0)
12
+ activesupport (>= 3.0)
13
+ i18n
6
14
  rack (>= 1.0.0)
7
15
  rack-mount (>= 0.6.0)
8
16
 
9
17
  GEM
10
18
  remote: http://rubygems.org/
11
19
  specs:
12
- activesupport (3.0.9)
13
- archive-tar-minitar (0.5.2)
14
- columnize (0.3.4)
15
- diff-lcs (1.1.2)
16
- linecache19 (0.5.12)
17
- ruby_core_source (>= 0.1.4)
18
- rack (1.3.2)
19
- rack-mount (0.6.14)
20
+ activesupport (3.2.2)
21
+ i18n (~> 0.6)
22
+ multi_json (~> 1.0)
23
+ awesome_print (1.0.2)
24
+ coderay (1.0.5)
25
+ diff-lcs (1.1.3)
26
+ i18n (0.6.0)
27
+ method_source (0.7.1)
28
+ multi_json (1.2.0)
29
+ pry (0.9.8.4)
30
+ coderay (~> 1.0.5)
31
+ method_source (~> 0.7.1)
32
+ slop (>= 2.4.4, < 3)
33
+ rack (1.4.1)
34
+ rack-mount (0.8.3)
20
35
  rack (>= 1.0.0)
21
- rack-test (0.5.7)
22
- rack (>= 1.0)
23
- rake (0.9.2)
24
- redis (2.2.1)
25
- rspec (2.6.0)
26
- rspec-core (~> 2.6.0)
27
- rspec-expectations (~> 2.6.0)
28
- rspec-mocks (~> 2.6.0)
29
- rspec-core (2.6.4)
30
- rspec-expectations (2.6.0)
31
- diff-lcs (~> 1.1.2)
32
- rspec-mocks (2.6.0)
33
- ruby-debug-base19 (0.11.25)
34
- columnize (>= 0.3.1)
35
- linecache19 (>= 0.5.11)
36
- ruby_core_source (>= 0.1.4)
37
- ruby-debug19 (0.11.6)
38
- columnize (>= 0.3.1)
39
- linecache19 (>= 0.5.11)
40
- ruby-debug-base19 (>= 0.11.19)
41
- ruby_core_source (0.1.5)
42
- archive-tar-minitar (>= 0.5.2)
36
+ rake (0.9.2.2)
37
+ redis (2.2.2)
38
+ rspec (2.9.0)
39
+ rspec-core (~> 2.9.0)
40
+ rspec-expectations (~> 2.9.0)
41
+ rspec-mocks (~> 2.9.0)
42
+ rspec-core (2.9.0)
43
+ rspec-expectations (2.9.0)
44
+ diff-lcs (~> 1.1.3)
45
+ rspec-mocks (2.9.0)
46
+ slop (2.4.4)
43
47
 
44
48
  PLATFORMS
45
49
  ruby
46
50
 
47
51
  DEPENDENCIES
52
+ awesome_print
53
+ pry
48
54
  rack-api!
49
- rack-test (~> 0.5.7)
55
+ rack-test!
50
56
  rake (~> 0.9)
51
57
  redis (~> 2.2.0)
52
58
  rspec (~> 2.6)
53
- ruby-debug19
@@ -53,7 +53,7 @@ module Rack
53
53
  #
54
54
  attr_accessor :rescuers
55
55
 
56
- def initialize(options)
56
+ def initialize(options = {})
57
57
  options.each do |name, value|
58
58
  instance_variable_set("@#{name}", value)
59
59
  end
@@ -1,12 +1,12 @@
1
1
  module Rack
2
2
  class API
3
3
  class Runner
4
- HTTP_METHODS = %w[get post put delete head]
4
+ HTTP_METHODS = %w[get post put delete head patch options]
5
5
 
6
6
  DELEGATE_METHODS = %w[
7
7
  version use prefix basic_auth rescue_from
8
8
  helper respond_to default_url_options
9
- get post put delete head
9
+ get post put delete head patch options
10
10
  ]
11
11
 
12
12
  attr_accessor :settings
@@ -214,7 +214,7 @@ module Rack
214
214
  # path are recognized.
215
215
  #
216
216
  # You're better off using all verb shortcut methods. Implemented verbs are
217
- # +get+, +post+, +put+, +delete+ and +head+.
217
+ # +get+, +post+, +put+, +delete+, +head+ and +patch+.
218
218
  #
219
219
  # class MyAPI < Rack::API
220
220
  # version "v1" do
@@ -250,7 +250,9 @@ module Rack
250
250
  # your world will explode.
251
251
  #
252
252
  def route(method, path, requirements = {}, &block)
253
- path = Rack::Mount::Strexp.compile mount_path(path), requirements, %w[ / . ? ]
253
+ separator = requirements.delete(:separator) { %w[ / . ? ] }
254
+
255
+ path = Rack::Mount::Strexp.compile mount_path(path), requirements, separator
254
256
  controller_class = Controller
255
257
 
256
258
  if requirements[:to]
@@ -274,7 +276,7 @@ module Rack
274
276
  #
275
277
  # rescue_from ActiveRecord::RecordNotFound, :status => 404
276
278
  # rescue_from Exception, :status => 500
277
- # rescue_from Exception do
279
+ # rescue_from Exception do |error|
278
280
  # $logger.error error.inspect
279
281
  # [500, {"Content-Type" => "text/plain"}, []]
280
282
  # end
@@ -2,8 +2,8 @@ module Rack
2
2
  class API
3
3
  module Version
4
4
  MAJOR = 1
5
- MINOR = 0
6
- PATCH = 2
5
+ MINOR = 1
6
+ PATCH = 0
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
9
9
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "rack/api"
3
+ require "rack/api/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rack-api"
@@ -19,10 +19,12 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency "rack", ">= 1.0.0"
21
21
  s.add_dependency "rack-mount", ">= 0.6.0"
22
- s.add_dependency "activesupport", ">= 3.0.0"
22
+ s.add_dependency "activesupport", ">= 3.0"
23
+ s.add_dependency "i18n"
23
24
  s.add_development_dependency "rspec", "~> 2.6"
24
25
  s.add_development_dependency "rack-test", "~> 0.5.7"
25
26
  s.add_development_dependency "redis", "~> 2.2.0"
26
27
  s.add_development_dependency "rake", "~> 0.9"
27
- s.add_development_dependency "ruby-debug19" if RUBY_VERSION >= "1.9"
28
+ s.add_development_dependency "pry"
29
+ s.add_development_dependency "awesome_print"
28
30
  end
@@ -9,6 +9,8 @@ describe Rack::API, "HTTP Methods" do
9
9
  put("put") { {:put => true} }
10
10
  delete("delete") { {:delete => true} }
11
11
  head("head") { {:head => true} }
12
+ patch("patch") { {:patch => true} }
13
+ options("options") { {:options => true} }
12
14
  end
13
15
  end
14
16
  end
@@ -3,6 +3,10 @@ require "spec_helper"
3
3
  describe Rack::API, "delegators" do
4
4
  subject { Rack::API }
5
5
 
6
+ specify "sanity check for delegate methods" do
7
+ Rack::API::Runner::DELEGATE_METHODS.size.should == 15
8
+ end
9
+
6
10
  it { should respond_to(:version) }
7
11
  it { should respond_to(:use) }
8
12
  it { should respond_to(:prefix) }
@@ -15,4 +19,6 @@ describe Rack::API, "delegators" do
15
19
  it { should respond_to(:put) }
16
20
  it { should respond_to(:delete) }
17
21
  it { should respond_to(:head) }
22
+ it { should respond_to(:patch) }
23
+ it { should respond_to(:options) }
18
24
  end
@@ -1,17 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rack::API::Runner do
4
- specify "sanity check for delegate methods" do
5
- # remember to update spec/method_delegation_spec.rb
6
- Rack::API::Runner::DELEGATE_METHODS.size.should == 13
7
- end
8
-
9
4
  it "responds to http methods" do
10
5
  subject.should respond_to(:get)
11
6
  subject.should respond_to(:post)
12
7
  subject.should respond_to(:put)
13
8
  subject.should respond_to(:delete)
14
9
  subject.should respond_to(:head)
10
+ subject.should respond_to(:options)
11
+ subject.should respond_to(:patch)
15
12
  end
16
13
 
17
14
  it "sets available formats" do
@@ -50,7 +47,11 @@ describe Rack::API::Runner do
50
47
  :handler => proc {}
51
48
  }
52
49
 
53
- Rack::API::Controller.should_receive(:new).with(hash_including(expected)).once
50
+ Rack::API::Controller
51
+ .should_receive(:new)
52
+ .with(hash_including(expected))
53
+ .and_return(mock.as_null_object)
54
+
54
55
  subject.version("v1") do
55
56
  respond_to :fffuuu
56
57
  prefix "api"
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe Rack::API, "separators" do
4
+ before do
5
+ Rack::API.app do
6
+ get("/no-dots/:name(.:format)") { params }
7
+ get("/dots/:name", :separator => %w[/?]) { params }
8
+ end
9
+ end
10
+
11
+ context "/no-dots/:name" do
12
+ it "stops on /" do
13
+ get "/no-dots/foo/"
14
+ last_response.body.should == {:name => "foo"}.to_json
15
+ end
16
+
17
+ it "stops on ?" do
18
+ get "/no-dots/foo?a=1"
19
+ last_response.body.should == {:a => "1", :name => "foo"}.to_json
20
+ end
21
+
22
+ it "stops on ." do
23
+ get "/no-dots/foo.json"
24
+ last_response.body.should == {:name => "foo", :format => "json"}.to_json
25
+ end
26
+ end
27
+
28
+ context "/dots/:name" do
29
+ it "stops on /" do
30
+ get "/dots/foo/"
31
+ last_response.body.should == {:name => "foo"}.to_json
32
+ end
33
+
34
+ it "stops on ?" do
35
+ get "/dots/foo?a=1"
36
+ last_response.body.should == {:a => "1", :name => "foo"}.to_json
37
+ end
38
+
39
+ it "stops on ." do
40
+ get "/dots/foo.json"
41
+ last_response.body.should == {:name => "foo.json"}.to_json
42
+ end
43
+ end
44
+ end
@@ -54,7 +54,7 @@ describe Rack::API::Controller, "#url_for" do
54
54
 
55
55
  it "adds query string" do
56
56
  actual = subject.url_for(:format => :json, :filters => [:name, :age])
57
- actual.should == "http://example.org/v1?filters[]=name&filters[]=age&format=json"
57
+ actual.should == "http://example.org/v1?filters%5B%5D=name&filters%5B%5D=age&format=json"
58
58
  end
59
59
 
60
60
  it "uses host from request" do
@@ -1,3 +1,7 @@
1
+ require "bundler"
2
+ Bundler.setup(:default, :development)
3
+ Bundler.require
4
+
1
5
  require "rack/test"
2
6
  require "rspec"
3
7
  require "rack/api"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000 Z
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &2269556480 !ruby/object:Gem::Requirement
16
+ requirement: &70274063249420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2269556480
24
+ version_requirements: *70274063249420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-mount
27
- requirement: &2269555880 !ruby/object:Gem::Requirement
27
+ requirement: &70274063248740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,32 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2269555880
35
+ version_requirements: *70274063248740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2269554780 !ruby/object:Gem::Requirement
38
+ requirement: &70274063248280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: 3.0.0
43
+ version: '3.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2269554780
46
+ version_requirements: *70274063248280
47
+ - !ruby/object:Gem::Dependency
48
+ name: i18n
49
+ requirement: &70274063247900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70274063247900
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec
49
- requirement: &2269553440 !ruby/object:Gem::Requirement
60
+ requirement: &70274063247320 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '2.6'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *2269553440
68
+ version_requirements: *70274063247320
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rack-test
60
- requirement: &2269483040 !ruby/object:Gem::Requirement
71
+ requirement: &70274063246820 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 0.5.7
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *2269483040
79
+ version_requirements: *70274063246820
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: redis
71
- requirement: &2269482580 !ruby/object:Gem::Requirement
82
+ requirement: &70274063246340 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: 2.2.0
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *2269482580
90
+ version_requirements: *70274063246340
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: rake
82
- requirement: &2269481900 !ruby/object:Gem::Requirement
93
+ requirement: &70274063245860 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ~>
@@ -87,10 +98,21 @@ dependencies:
87
98
  version: '0.9'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *2269481900
101
+ version_requirements: *70274063245860
102
+ - !ruby/object:Gem::Dependency
103
+ name: pry
104
+ requirement: &70274063245480 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70274063245480
91
113
  - !ruby/object:Gem::Dependency
92
- name: ruby-debug19
93
- requirement: &2269481220 !ruby/object:Gem::Requirement
114
+ name: awesome_print
115
+ requirement: &70274063245020 !ruby/object:Gem::Requirement
94
116
  none: false
95
117
  requirements:
96
118
  - - ! '>='
@@ -98,7 +120,7 @@ dependencies:
98
120
  version: '0'
99
121
  type: :development
100
122
  prerelease: false
101
- version_requirements: *2269481220
123
+ version_requirements: *70274063245020
102
124
  description: Create web app APIs that respond to one or more formats using an elegant
103
125
  DSL.
104
126
  email:
@@ -154,6 +176,7 @@ files:
154
176
  - spec/rack-api/paths_spec.rb
155
177
  - spec/rack-api/rescue_from_spec.rb
156
178
  - spec/rack-api/runner_spec.rb
179
+ - spec/rack-api/separators_spec.rb
157
180
  - spec/rack-api/settings_spec.rb
158
181
  - spec/rack-api/short_circuit_spec.rb
159
182
  - spec/rack-api/ssl_spec.rb
@@ -179,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
202
  version: '0'
180
203
  segments:
181
204
  - 0
182
- hash: -629518363732307002
205
+ hash: -2011021662254464063
183
206
  required_rubygems_version: !ruby/object:Gem::Requirement
184
207
  none: false
185
208
  requirements:
@@ -188,10 +211,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
211
  version: '0'
189
212
  segments:
190
213
  - 0
191
- hash: -629518363732307002
214
+ hash: -2011021662254464063
192
215
  requirements: []
193
216
  rubyforge_project:
194
- rubygems_version: 1.8.6
217
+ rubygems_version: 1.8.11
195
218
  signing_key:
196
219
  specification_version: 3
197
220
  summary: Create web app APIs that respond to one or more formats using an elegant
@@ -211,6 +234,7 @@ test_files:
211
234
  - spec/rack-api/paths_spec.rb
212
235
  - spec/rack-api/rescue_from_spec.rb
213
236
  - spec/rack-api/runner_spec.rb
237
+ - spec/rack-api/separators_spec.rb
214
238
  - spec/rack-api/settings_spec.rb
215
239
  - spec/rack-api/short_circuit_spec.rb
216
240
  - spec/rack-api/ssl_spec.rb