rack-test-rest 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ module Rack
16
16
  # unless the :code option is specified.
17
17
  #
18
18
  def create_resource(params={})
19
- id, expected_code, params = _rtr_prepare_params(params)
19
+ expected_code, params = _rtr_prepare_params(params, no_id: true)
20
20
 
21
21
  puts "Posting to: '#{resource_uri}#{@rack_test_rest[:extension]}'" if @rack_test_rest[:debug]
22
22
  post "#{resource_uri}#{@rack_test_rest[:extension]}", params
@@ -169,12 +169,14 @@ module Rack
169
169
 
170
170
  # split out common arguments & protect payload to ensure
171
171
  # we don't modify it by reference
172
- def _rtr_prepare_params(opts)
172
+ def _rtr_prepare_params(params, opts={})
173
173
  # symbolize all keys & ensure we don't affect original object
174
- params = opts.each_with_object({}) { |(k,v),memo| memo[k.to_sym] = v }
175
- id = params.delete(:id)
176
- code = params.delete(:code)
177
- [id, code, params]
174
+ prep = params.each_with_object({}) { |(k,v),memo| memo[k.to_sym] = v }
175
+ result = []
176
+ result << prep.delete(:id) unless opts[:no_id]
177
+ result << prep.delete(:code)
178
+ result << prep
179
+ result
178
180
  end
179
181
 
180
182
  def assert_content_type_is_json(response=last_response)
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  module Test
3
3
  module Rest
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
6
6
  end
7
7
  end
@@ -10,6 +10,7 @@ module Rack::Test::Rest
10
10
  end
11
11
 
12
12
  post '/v1/users' do
13
+ status 201
13
14
  headers 'Content-Type' => 'application/json'
14
15
  body '{}'
15
16
  end
@@ -16,6 +16,22 @@ class TestRackTestRest < Minitest::Test
16
16
  }
17
17
  end
18
18
 
19
+ def test_create_resource
20
+ create_resource(email: 'fred@sinatra.com', password: 'groovy')
21
+
22
+ # request
23
+ assert last_request.post?
24
+ assert_equal '/v1/users', last_request.path
25
+
26
+ # response
27
+ assert_equal 201, last_response.status
28
+ end
29
+
30
+ def test_create_resource_should_pass_id
31
+ create_resource(id: 101, email: 'fred@sinatra.com', password: 'groovy')
32
+ assert_equal "101", last_request.params['id']
33
+ end
34
+
19
35
  def test_read_resource
20
36
  read_resource(id: 15)
21
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-test-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  segments:
61
61
  - 0
62
- hash: 2737779017982661905
62
+ hash: -4347160503149450218
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements: