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.
- data/lib/rack-test-rest.rb +8 -6
- data/lib/rack-test-rest/version.rb +1 -1
- data/test/fixtures/sample_app.rb +1 -0
- data/test/rack_test_rest_test.rb +16 -0
- metadata +2 -2
data/lib/rack-test-rest.rb
CHANGED
@@ -16,7 +16,7 @@ module Rack
|
|
16
16
|
# unless the :code option is specified.
|
17
17
|
#
|
18
18
|
def create_resource(params={})
|
19
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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)
|
data/test/fixtures/sample_app.rb
CHANGED
data/test/rack_test_rest_test.rb
CHANGED
@@ -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.
|
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:
|
62
|
+
hash: -4347160503149450218
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|