rest-in-peace 5.1.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/gem-push.yml +29 -0
- data/.github/workflows/rspec.yml +34 -0
- data/.gitignore +1 -0
- data/README.md +114 -27
- data/VERSION +1 -1
- data/gemfiles/{Gemfile.activemodel-5.0.x → Gemfile.activemodel-5.1.x} +1 -1
- data/gemfiles/Gemfile.activemodel-5.2.x +5 -0
- data/lib/rest_in_peace.rb +16 -2
- data/lib/rest_in_peace/active_model_api.rb +9 -2
- data/lib/rest_in_peace/faraday/raise_errors_middleware.rb +3 -3
- data/lib/rest_in_peace/template_sanitizer.rb +7 -2
- data/rest-in-peace.gemspec +1 -0
- data/spec/rest_in_peace/active_model_api_spec.rb +28 -1
- data/spec/rest_in_peace/template_sanitizer_spec.rb +38 -2
- data/spec/rest_in_peace_spec.rb +29 -6
- metadata +28 -27
- data/.ruby-version +0 -1
- data/.travis.yml +0 -22
- data/gemfiles/Gemfile.activemodel-3.2.x +0 -6
- data/gemfiles/Gemfile.activemodel-4.0.x +0 -6
- data/gemfiles/Gemfile.activemodel-4.1.x +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d122d9f9815d59a8e0f9c5cc3b5c558f920044ffee5e4ccfb926d9fac816dbfb
|
4
|
+
data.tar.gz: 5502ea4ad63d752fbabf4453523f9d3f8f8ebbdd04229a2793eaa1524e0e6d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2263f956630c22d8f13c44b974d609cbcc85a08285faab83d083c6d7f137f754a2a626e57d41d97b8bd90965c1bb8af45edc7fb132f97f73c1e7ff0f7b26ce7
|
7
|
+
data.tar.gz: 0b20c10350d7afb8ef9c31ad9679f27cc9be5fdef62990339e62d18cd3c8917bfb4a657809e1976864671a2de55058834d990942bd1a61374c82b475626d8418
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- "*"
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6.x
|
19
|
+
|
20
|
+
- name: Publish to RubyGems
|
21
|
+
run: |
|
22
|
+
mkdir -p $HOME/.gem
|
23
|
+
touch $HOME/.gem/credentials
|
24
|
+
chmod 0600 $HOME/.gem/credentials
|
25
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
26
|
+
gem build *.gemspec
|
27
|
+
gem push *.gem
|
28
|
+
env:
|
29
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby CI
|
9
|
+
|
10
|
+
on: [push, pull_request]
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
ruby-version: [2.4.10, 2.5.8, 2.6.6, 2.7.2]
|
20
|
+
activemodel: [4.2.x, 5.1.x, 5.2.x]
|
21
|
+
exclude:
|
22
|
+
- ruby-version: 2.7.2
|
23
|
+
activemodel: 4.2.x
|
24
|
+
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v2
|
27
|
+
- name: Set up Ruby
|
28
|
+
uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby-version }}
|
31
|
+
- name: Install dependencies
|
32
|
+
run: bundle install --gemfile gemfiles/Gemfile.activemodel-${{ matrix.activemodel }}
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rake spec
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -10,18 +10,51 @@ A ruby REST client that lets you feel like in heaven when consuming APIs.
|
|
10
10
|
|
11
11
|
gem 'rest-in-peace'
|
12
12
|
|
13
|
-
2. Choose which
|
13
|
+
2. Choose which HTTP client you want to use
|
14
14
|
|
15
15
|
gem 'faraday'
|
16
|
+
|
17
|
+
3. Choose which HTTP adapter you want to use
|
18
|
+
|
19
|
+
gem 'excon'
|
16
20
|
|
17
21
|
## Usage
|
18
22
|
|
19
23
|
### HTTP Client Library
|
20
24
|
|
21
|
-
|
25
|
+
This gem depends on the HTTP client library [Faraday](https://github.com/lostisland/faraday). REST-in-Peace has been tested in combination
|
26
|
+
with [Faraday](https://github.com/lostisland/faraday) and [Excon](https://github.com/excon/excon) only.
|
22
27
|
|
23
28
|
### Configuration
|
24
29
|
|
30
|
+
#### HTTP Client
|
31
|
+
|
32
|
+
You need to configure and specify the HTTP client library to use. You can either specify a block (for lazy loading) or a client instance directly.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class Resource
|
36
|
+
include RESTinPeace
|
37
|
+
|
38
|
+
rest_in_peace do
|
39
|
+
use_api ->() do
|
40
|
+
::Faraday.new(url: 'http://rip.dev', headers: { 'Accept' => 'application/json' }) do |faraday|
|
41
|
+
faraday.request :json
|
42
|
+
faraday.response :json
|
43
|
+
faraday.adapter :excon # make requests with Excon
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class ResourceTwo
|
50
|
+
include RESTinPeace
|
51
|
+
|
52
|
+
rest_in_peace do
|
53
|
+
use_api ->() { MyClient.api }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
25
58
|
#### Attributes
|
26
59
|
|
27
60
|
You need to specify all the attributes which should be read out of the parsed JSON. You have to specify whether an attribute
|
@@ -40,7 +73,7 @@ end
|
|
40
73
|
|
41
74
|
#### API Endpoints
|
42
75
|
|
43
|
-
You need to define all the API endpoints you want to consume with `
|
76
|
+
You need to define all the API endpoints you want to consume with `REST-in-Peace`. Currently the five verbs `GET`, `POST`, `PUT`, `PATCH` and `DELETE` are supported.
|
44
77
|
|
45
78
|
There are two sections where you can specify endpoints: `resource` and `collection`. `collection` supports the HTTP verb `GET` only.
|
46
79
|
|
@@ -55,28 +88,6 @@ rest_in_peace do
|
|
55
88
|
end
|
56
89
|
```
|
57
90
|
|
58
|
-
#### HTTP Client Configuration
|
59
|
-
|
60
|
-
You need to specify the HTTP client library to use. You can either specify a block (for lazy loading) or a client instance directly.
|
61
|
-
|
62
|
-
```ruby
|
63
|
-
class Resource
|
64
|
-
include RESTinPeace
|
65
|
-
|
66
|
-
rest_in_peace do
|
67
|
-
use_api ->() { Faraday.new(url: 'http://rip.dev') }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class ResourceTwo
|
72
|
-
include RESTinPeace
|
73
|
-
|
74
|
-
rest_in_peace do
|
75
|
-
use_api Faraday.new(url: 'http://rip.dev')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
```
|
79
|
-
|
80
91
|
#### Resource
|
81
92
|
|
82
93
|
If you define anything inside the `resource` block, it will define a method on the instances of the class:
|
@@ -160,6 +171,7 @@ For easy interoperability with Rails, there is the ability to include ActiveMode
|
|
160
171
|
|
161
172
|
```ruby
|
162
173
|
require 'rest_in_peace'
|
174
|
+
require 'faraday'
|
163
175
|
|
164
176
|
module MyClient
|
165
177
|
class Fabric
|
@@ -184,11 +196,14 @@ module MyClient
|
|
184
196
|
end
|
185
197
|
```
|
186
198
|
|
187
|
-
|
199
|
+
### Complete Configurations
|
188
200
|
|
189
|
-
|
201
|
+
#### Configured Fabric class with all dependencies
|
202
|
+
|
203
|
+
```ruby
|
190
204
|
require 'my_client/paginator'
|
191
205
|
require 'rest_in_peace'
|
206
|
+
require 'faraday'
|
192
207
|
|
193
208
|
module MyClient
|
194
209
|
class Fabric
|
@@ -220,6 +235,72 @@ module MyClient
|
|
220
235
|
end
|
221
236
|
```
|
222
237
|
|
238
|
+
#### Configured Fabric class using Faraday
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
require 'my_client/paginator'
|
242
|
+
require 'rest_in_peace'
|
243
|
+
require 'faraday'
|
244
|
+
|
245
|
+
module MyClient
|
246
|
+
class Fabric
|
247
|
+
include RESTinPeace
|
248
|
+
|
249
|
+
rest_in_peace do
|
250
|
+
use_api ->() do
|
251
|
+
::Faraday.new(url: 'http://localhost:3001', headers: { 'Accept' => 'application/json' }) do |faraday|
|
252
|
+
faraday.request :json
|
253
|
+
faraday.response :json
|
254
|
+
faraday.adapter :excon
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
attributes do
|
259
|
+
read :id
|
260
|
+
write :name
|
261
|
+
end
|
262
|
+
|
263
|
+
resource do
|
264
|
+
patch :save, '/fabrics/:id'
|
265
|
+
post :create, '/fabrics'
|
266
|
+
delete :destroy, '/fabrics/:id'
|
267
|
+
get :reload, '/fabrics/:id'
|
268
|
+
end
|
269
|
+
|
270
|
+
collection do
|
271
|
+
get :all, '/fabrics', paginate_with: MyClient::Paginator
|
272
|
+
get :find, '/fabrics/:id'
|
273
|
+
end
|
274
|
+
|
275
|
+
acts_as_active_model
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
```
|
280
|
+
|
281
|
+
#### CRUD options example of use
|
282
|
+
```ruby
|
283
|
+
# CREATE
|
284
|
+
fabric = MyClient::Fabric.new(name: 'my new fabric')
|
285
|
+
fabric.create # calls "POST /fabrics"
|
286
|
+
fabric.reload # calls "GET /fabrics/1"
|
287
|
+
|
288
|
+
# READ
|
289
|
+
last_fabric = MyClient::Fabric.find(id: fabric.id) # calls "GET /fabrics/1"
|
290
|
+
|
291
|
+
# UPDATE - first way
|
292
|
+
updated_fabric = last_fabric.update_attributes(name: 'first way fabric')
|
293
|
+
updated_fabric.save # calls "PATCH /fabrics/1"
|
294
|
+
|
295
|
+
# UPDATE - second way
|
296
|
+
updated_fabric = last_fabric.update(name: 'second way fabric') # calls "PATCH /fabrics/1"
|
297
|
+
|
298
|
+
# DELETE
|
299
|
+
updated_fabric.destroy # calls "DELETE /fabrics/1"
|
300
|
+
```
|
301
|
+
Method `update_attributes` sets updated value, `save` method stores all changes. This change can be done with calling
|
302
|
+
single line method `update` which do the both things.
|
303
|
+
|
223
304
|
## Helpers
|
224
305
|
|
225
306
|
### SSL Configuration for Faraday
|
@@ -255,3 +336,9 @@ Faraday.new do |faraday|
|
|
255
336
|
# ...
|
256
337
|
end
|
257
338
|
```
|
339
|
+
|
340
|
+
## About
|
341
|
+
|
342
|
+
This gem is currently maintained and funded by [nine](https://nine.ch).
|
343
|
+
|
344
|
+
[![logo of the company 'nine'](https://logo.apps.at-nine.ch/Dmqied_eSaoBMQwk3vVgn4UIgDo=/trim/500x0/logo_claim.png)](https://www.nine.ch)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
6.1.0
|
data/lib/rest_in_peace.rb
CHANGED
@@ -3,7 +3,6 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
3
3
|
require 'rest_in_peace/definition_proxy'
|
4
4
|
|
5
5
|
module RESTinPeace
|
6
|
-
|
7
6
|
def self.included(base)
|
8
7
|
base.send :extend, ClassMethods
|
9
8
|
base.send :include, ActiveModel::Dirty
|
@@ -25,8 +24,9 @@ module RESTinPeace
|
|
25
24
|
hash_representation[key.to_sym] = hash_representation_of_object(value)
|
26
25
|
end
|
27
26
|
else
|
28
|
-
hash_representation
|
27
|
+
hash_representation.merge!(to_write_only_hash)
|
29
28
|
end
|
29
|
+
|
30
30
|
if self.class.rip_namespace
|
31
31
|
{ id: id, self.class.rip_namespace => hash_representation }
|
32
32
|
else
|
@@ -55,9 +55,11 @@ module RESTinPeace
|
|
55
55
|
|
56
56
|
def to_h
|
57
57
|
hash_representation = {}
|
58
|
+
|
58
59
|
self.class.rip_attributes.values.flatten.each do |attr|
|
59
60
|
hash_representation[attr] = send(attr)
|
60
61
|
end
|
62
|
+
|
61
63
|
hash_representation
|
62
64
|
end
|
63
65
|
|
@@ -83,6 +85,10 @@ module RESTinPeace
|
|
83
85
|
object
|
84
86
|
end
|
85
87
|
|
88
|
+
def write_attribute?(attribute)
|
89
|
+
self.class.rip_attributes[:write].include?(attribute.to_sym)
|
90
|
+
end
|
91
|
+
|
86
92
|
module ClassMethods
|
87
93
|
attr_accessor :api
|
88
94
|
attr_accessor :rip_namespace
|
@@ -106,4 +112,12 @@ module RESTinPeace
|
|
106
112
|
}
|
107
113
|
end
|
108
114
|
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def to_write_only_hash
|
119
|
+
self.class.rip_attributes[:write].inject({}) do |h, attr|
|
120
|
+
h.merge(attr => send(attr))
|
121
|
+
end
|
122
|
+
end
|
109
123
|
end
|
@@ -46,6 +46,11 @@ module RESTinPeace
|
|
46
46
|
valid?
|
47
47
|
end
|
48
48
|
|
49
|
+
def update(attributes)
|
50
|
+
update_attributes(attributes)
|
51
|
+
save
|
52
|
+
end
|
53
|
+
|
49
54
|
def valid?
|
50
55
|
!errors.any?
|
51
56
|
end
|
@@ -63,8 +68,10 @@ module RESTinPeace
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def errors=(new_errors)
|
66
|
-
new_errors.each do |
|
67
|
-
errors.
|
71
|
+
new_errors.each do |field, errors|
|
72
|
+
errors.each do |error|
|
73
|
+
self.errors.add(field.to_sym, error)
|
74
|
+
end
|
68
75
|
end
|
69
76
|
end
|
70
77
|
end
|
@@ -8,15 +8,15 @@ module RESTinPeace
|
|
8
8
|
def on_complete(env)
|
9
9
|
case env[:status]
|
10
10
|
when 404
|
11
|
-
raise ::Faraday::
|
11
|
+
raise ::Faraday::ResourceNotFound, response_values(env)
|
12
12
|
when 407
|
13
13
|
# mimic the behavior that we get with proxy requests with HTTPS
|
14
|
-
raise ::Faraday::
|
14
|
+
raise ::Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
15
15
|
when 422
|
16
16
|
# do not raise an error as 422 from a rails app means validation errors
|
17
17
|
# and response body contains the validation errors
|
18
18
|
when CLIENT_ERROR_STATUSES
|
19
|
-
raise ::Faraday::
|
19
|
+
raise ::Faraday::ClientError, response_values(env)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest_in_peace/errors'
|
2
|
+
require 'addressable/uri'
|
2
3
|
|
3
4
|
module RESTinPeace
|
4
5
|
class TemplateSanitizer
|
@@ -16,10 +17,14 @@ module RESTinPeace
|
|
16
17
|
return @url if @url
|
17
18
|
@url = @url_template.dup
|
18
19
|
tokens.each do |token|
|
19
|
-
param = @params
|
20
|
+
param = @params[token.to_sym]
|
20
21
|
param ||= @klass.send(token) if @klass.respond_to?(token)
|
21
22
|
raise IncompleteParams, "No parameter for token :#{token} found" unless param
|
22
|
-
@
|
23
|
+
if @params.include?(token.to_sym)
|
24
|
+
@url.sub!(%r{:#{token}}, CGI.escape(param.to_s))
|
25
|
+
else
|
26
|
+
@url.sub!(%r{:#{token}}, Addressable::URI.parse(param.to_s).normalize.to_s)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
@url
|
25
30
|
end
|
data/rest-in-peace.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
|
20
20
|
s.add_runtime_dependency 'activemodel', '>= 3.2', '< 6'
|
21
|
+
s.add_runtime_dependency 'addressable', '~> 2.5'
|
21
22
|
|
22
23
|
s.add_development_dependency 'rake', '~> 10.0'
|
23
24
|
s.add_development_dependency 'rspec', '~> 3.0'
|
@@ -168,6 +168,27 @@ describe RESTinPeace do
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
describe '#update' do
|
172
|
+
let(:new_attributes) { { name: 'new_name', description: 'yoloswag' } }
|
173
|
+
|
174
|
+
subject { instance }
|
175
|
+
|
176
|
+
it 'saves record after update' do
|
177
|
+
expect(subject).to receive(:save)
|
178
|
+
|
179
|
+
subject.update(new_attributes)
|
180
|
+
end
|
181
|
+
|
182
|
+
specify do
|
183
|
+
expect { subject.update(new_attributes) }.
|
184
|
+
to change(instance, :description).from(attributes[:description]).to(new_attributes[:description])
|
185
|
+
end
|
186
|
+
|
187
|
+
specify do
|
188
|
+
expect { subject.update(new_attributes) }.to_not change(instance, :name).from(attributes[:name])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
171
192
|
describe 'validation handling' do
|
172
193
|
before do
|
173
194
|
def extended_class.model_name
|
@@ -176,7 +197,7 @@ describe RESTinPeace do
|
|
176
197
|
end
|
177
198
|
|
178
199
|
let(:description) { 'desc' }
|
179
|
-
let(:errors)
|
200
|
+
let(:errors) { { description: ['must not be empty'] } }
|
180
201
|
|
181
202
|
specify { expect(instance).to respond_to(:read_attribute_for_validation).with(1).argument }
|
182
203
|
specify { expect(instance.read_attribute_for_validation(:description)).to eq('desc') }
|
@@ -187,6 +208,12 @@ describe RESTinPeace do
|
|
187
208
|
|
188
209
|
describe '#errors=' do
|
189
210
|
specify { expect { instance.errors = errors }.to change { instance.errors.count } }
|
211
|
+
|
212
|
+
it 'correctly adds the error to the instance' do
|
213
|
+
instance.errors = errors
|
214
|
+
|
215
|
+
expect(instance.errors[:description]).to eq(['must not be empty'])
|
216
|
+
end
|
190
217
|
end
|
191
218
|
|
192
219
|
describe '#valid?' do
|
@@ -5,7 +5,6 @@ describe RESTinPeace::TemplateSanitizer do
|
|
5
5
|
let(:attributes) { {} }
|
6
6
|
let(:template_sanitizer) { RESTinPeace::TemplateSanitizer.new(url_template, params, klass) }
|
7
7
|
|
8
|
-
|
9
8
|
context 'with class' do
|
10
9
|
let(:klass) { OpenStruct }
|
11
10
|
|
@@ -18,6 +17,12 @@ describe RESTinPeace::TemplateSanitizer do
|
|
18
17
|
specify { expect(subject).to eq('/a/1') }
|
19
18
|
end
|
20
19
|
|
20
|
+
context 'single token with extra params' do
|
21
|
+
let(:params) { { id: 1, something: 'else' } }
|
22
|
+
let(:url_template) { '/a/:id' }
|
23
|
+
specify { expect(subject).to eq('/a/1') }
|
24
|
+
end
|
25
|
+
|
21
26
|
context 'multiple token' do
|
22
27
|
let(:params) { { id: 2, a_id: 1 } }
|
23
28
|
let(:url_template) { '/a/:a_id/b/:id' }
|
@@ -118,7 +123,7 @@ describe RESTinPeace::TemplateSanitizer do
|
|
118
123
|
specify { expect { subject }.to raise_error(RESTinPeace::TemplateSanitizer::IncompleteParams) }
|
119
124
|
end
|
120
125
|
|
121
|
-
context 'param which need to be encoded' do
|
126
|
+
context 'param which need to be encoded is white space separated string' do
|
122
127
|
let(:params) { { id: 'this param need to be encoded' } }
|
123
128
|
let(:encoded_param) { 'this+param+need+to+be+encoded' }
|
124
129
|
let(:attributes) { { a_id: 2 } }
|
@@ -126,6 +131,23 @@ describe RESTinPeace::TemplateSanitizer do
|
|
126
131
|
specify { expect(subject).to eq("/a/2/b/#{encoded_param}") }
|
127
132
|
end
|
128
133
|
|
134
|
+
context 'path which need to be encoded is white space separated string' do
|
135
|
+
let(:params) { { id: 1 } }
|
136
|
+
let(:attributes) { { a_name: 'with space' } }
|
137
|
+
let(:encoded_path) { 'with%20space' }
|
138
|
+
let(:url_template) { '/a/:a_name/b/:id' }
|
139
|
+
specify { expect(subject).to eq("/a/#{encoded_path}/b/1") }
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'path and param which need to be encoded are white space separated string' do
|
143
|
+
let(:params) { { place: 'dhaini kata' } }
|
144
|
+
let(:encoded_param) { 'dhaini+kata' }
|
145
|
+
let(:attributes) { { a_name: 'with space' } }
|
146
|
+
let(:encoded_path) { 'with%20space' }
|
147
|
+
let(:url_template) { '/a/:a_name/b/:place' }
|
148
|
+
specify { expect(subject).to eq("/a/#{encoded_path}/b/#{encoded_param}") }
|
149
|
+
end
|
150
|
+
|
129
151
|
context 'param which need to be encoded is null string' do
|
130
152
|
let(:params) { { id: '' } }
|
131
153
|
let(:encoded_param) { '' }
|
@@ -134,6 +156,13 @@ describe RESTinPeace::TemplateSanitizer do
|
|
134
156
|
specify { expect(subject).to eq("/a/2/b/#{encoded_param}") }
|
135
157
|
end
|
136
158
|
|
159
|
+
context 'path which need to be encoded is null string' do
|
160
|
+
let(:params) { { id: 1 } }
|
161
|
+
let(:attributes) { { a_name: '' } }
|
162
|
+
let(:url_template) { '/a/:a_name/b/:id' }
|
163
|
+
specify { expect(subject).to eq('/a//b/1') }
|
164
|
+
end
|
165
|
+
|
137
166
|
context 'param which need to be encoded is nil' do
|
138
167
|
let(:params) { { id: nil } }
|
139
168
|
let(:encoded_param) { '' }
|
@@ -141,6 +170,13 @@ describe RESTinPeace::TemplateSanitizer do
|
|
141
170
|
let(:url_template) { '/a/:a_id/b/:id' }
|
142
171
|
specify { expect { subject }.to raise_exception(RESTinPeace::TemplateSanitizer::IncompleteParams) }
|
143
172
|
end
|
173
|
+
|
174
|
+
context 'path which need to be encoded is nil' do
|
175
|
+
let(:params) { { id: 1 } }
|
176
|
+
let(:attributes) { { a_name: nil } }
|
177
|
+
let(:url_template) { '/a/:a_name/b/:id' }
|
178
|
+
specify { expect { subject }.to raise_exception(RESTinPeace::TemplateSanitizer::IncompleteParams) }
|
179
|
+
end
|
144
180
|
end
|
145
181
|
|
146
182
|
describe '#tokens' do
|
data/spec/rest_in_peace_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'rest_in_peace'
|
2
2
|
|
3
3
|
describe RESTinPeace do
|
4
|
-
|
5
4
|
let(:extended_class) do
|
6
5
|
Class.new do
|
7
6
|
include RESTinPeace
|
8
7
|
|
8
|
+
attr_writer :relation
|
9
|
+
|
9
10
|
rest_in_peace do
|
10
11
|
attributes do
|
11
12
|
read :id, :name, :relation
|
@@ -17,10 +18,6 @@ describe RESTinPeace do
|
|
17
18
|
'something else'
|
18
19
|
end
|
19
20
|
|
20
|
-
def relation=(v)
|
21
|
-
@relation = v
|
22
|
-
end
|
23
|
-
|
24
21
|
def self_defined_method
|
25
22
|
puts 'yolo'
|
26
23
|
end
|
@@ -143,6 +140,32 @@ describe RESTinPeace do
|
|
143
140
|
subject.payload
|
144
141
|
end
|
145
142
|
end
|
143
|
+
|
144
|
+
context 'all write attributes' do
|
145
|
+
specify do
|
146
|
+
expect(subject.payload(false)).to eq(
|
147
|
+
id: 1,
|
148
|
+
my_array: ['element'],
|
149
|
+
my_hash: { element1: 'yolo' },
|
150
|
+
array_with_hash: [{ element1: 'yolo' }],
|
151
|
+
overridden_attribute: 'something else',
|
152
|
+
description: 'old description'
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'changes only' do
|
158
|
+
specify do
|
159
|
+
expect(subject.payload(true)).to eq(
|
160
|
+
id: 1,
|
161
|
+
my_array: ['element'],
|
162
|
+
my_hash: { element1: 'yolo' },
|
163
|
+
array_with_hash: [{ element1: 'yolo' }],
|
164
|
+
overridden_attribute: 'something else',
|
165
|
+
description: 'old description'
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
146
169
|
end
|
147
170
|
|
148
171
|
context 'with a namespace defined' do
|
@@ -152,7 +175,7 @@ describe RESTinPeace do
|
|
152
175
|
|
153
176
|
rest_in_peace do
|
154
177
|
attributes do
|
155
|
-
read :id
|
178
|
+
read :id, :relation
|
156
179
|
write :name, :description
|
157
180
|
end
|
158
181
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-in-peace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raffael Schmid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: addressable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.5'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.5'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: rake
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,22 +96,22 @@ dependencies:
|
|
82
96
|
name: guard-rspec
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|
84
98
|
requirements:
|
85
|
-
- - "~>"
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '4.2'
|
88
99
|
- - ">="
|
89
100
|
- !ruby/object:Gem::Version
|
90
101
|
version: 4.2.0
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '4.2'
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '4.2'
|
98
109
|
- - ">="
|
99
110
|
- !ruby/object:Gem::Version
|
100
111
|
version: 4.2.0
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '4.2'
|
101
115
|
- !ruby/object:Gem::Dependency
|
102
116
|
name: simplecov
|
103
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,11 +139,11 @@ executables: []
|
|
125
139
|
extensions: []
|
126
140
|
extra_rdoc_files: []
|
127
141
|
files:
|
142
|
+
- ".github/workflows/gem-push.yml"
|
143
|
+
- ".github/workflows/rspec.yml"
|
128
144
|
- ".gitignore"
|
129
145
|
- ".rspec"
|
130
146
|
- ".ruby-gemset"
|
131
|
-
- ".ruby-version"
|
132
|
-
- ".travis.yml"
|
133
147
|
- Gemfile
|
134
148
|
- Guardfile
|
135
149
|
- LICENSE.txt
|
@@ -137,11 +151,9 @@ files:
|
|
137
151
|
- Rakefile
|
138
152
|
- VERSION
|
139
153
|
- examples/pagination_with_headers.rb
|
140
|
-
- gemfiles/Gemfile.activemodel-3.2.x
|
141
|
-
- gemfiles/Gemfile.activemodel-4.0.x
|
142
|
-
- gemfiles/Gemfile.activemodel-4.1.x
|
143
154
|
- gemfiles/Gemfile.activemodel-4.2.x
|
144
|
-
- gemfiles/Gemfile.activemodel-5.
|
155
|
+
- gemfiles/Gemfile.activemodel-5.1.x
|
156
|
+
- gemfiles/Gemfile.activemodel-5.2.x
|
145
157
|
- images/rest_in_peace.gif
|
146
158
|
- lib/rest-in-peace.rb
|
147
159
|
- lib/rest_in_peace.rb
|
@@ -186,19 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
198
|
- !ruby/object:Gem::Version
|
187
199
|
version: '0'
|
188
200
|
requirements: []
|
189
|
-
|
190
|
-
rubygems_version: 2.5.1
|
201
|
+
rubygems_version: 3.0.3
|
191
202
|
signing_key:
|
192
203
|
specification_version: 4
|
193
204
|
summary: REST in peace
|
194
|
-
test_files:
|
195
|
-
- spec/rest_in_peace/active_model_api_spec.rb
|
196
|
-
- spec/rest_in_peace/api_call_spec.rb
|
197
|
-
- spec/rest_in_peace/definition_proxy/attributes_definitions_spec.rb
|
198
|
-
- spec/rest_in_peace/definition_proxy/collection_method_definitions_spec.rb
|
199
|
-
- spec/rest_in_peace/definition_proxy/resource_method_definitions_spec.rb
|
200
|
-
- spec/rest_in_peace/definition_proxy_spec.rb
|
201
|
-
- spec/rest_in_peace/response_converter_spec.rb
|
202
|
-
- spec/rest_in_peace/template_sanitizer_spec.rb
|
203
|
-
- spec/rest_in_peace_spec.rb
|
204
|
-
- spec/spec_helper.rb
|
205
|
+
test_files: []
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.3.1
|
data/.travis.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
rvm:
|
4
|
-
- 2.0.0
|
5
|
-
- 2.1.2
|
6
|
-
- 2.2.5
|
7
|
-
- 2.3.1
|
8
|
-
gemfile:
|
9
|
-
- gemfiles/Gemfile.activemodel-3.2.x
|
10
|
-
- gemfiles/Gemfile.activemodel-4.0.x
|
11
|
-
- gemfiles/Gemfile.activemodel-4.1.x
|
12
|
-
- gemfiles/Gemfile.activemodel-4.2.x
|
13
|
-
- gemfiles/Gemfile.activemodel-5.0.x
|
14
|
-
script:
|
15
|
-
- bundle exec rake spec
|
16
|
-
before_install: gem install bundler
|
17
|
-
matrix:
|
18
|
-
exclude:
|
19
|
-
- rvm: 2.0.0
|
20
|
-
gemfile: gemfiles/Gemfile.activemodel-5.0.x
|
21
|
-
- rvm: 2.1.2
|
22
|
-
gemfile: gemfiles/Gemfile.activemodel-5.0.x
|