spyke 6.0.0 → 6.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +78 -0
- data/README.md +6 -16
- data/bin/console +13 -0
- data/lib/spyke/associations/builder.rb +1 -1
- data/lib/spyke/attribute_assignment.rb +3 -3
- data/lib/spyke/http.rb +12 -4
- data/lib/spyke/scope_registry.rb +15 -4
- data/lib/spyke/version.rb +1 -1
- data/spyke.gemspec +5 -4
- data/spyke.svg +22 -0
- data/test/activemodel_dirty_test.rb +1 -1
- data/test/associations_test.rb +9 -0
- data/test/attributes_test.rb +7 -3
- data/test/custom_request_test.rb +1 -1
- data/test/fallbacks_test.rb +6 -0
- data/test/path_test.rb +2 -2
- data/test/scope_registry_test.rb +11 -0
- data/test/support/fixtures.rb +3 -0
- data/test/test_helper.rb +7 -5
- metadata +36 -17
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba8000e29f83abe34550b8453ff430358759237765158641544c2deabe24014
|
4
|
+
data.tar.gz: 81d4521b0f2a0c22647c5ee4e8fb2d191eab09bf3eda9c114e8aef52ecfdbf80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 834dbdbcf76ae84d9e7b037ac798385a9d911ad2089c7b4b34a40eea82fcdabcf0e8c8aa0fa751a27d38ad8f13f1dbbf833a1b40b0fb741ff9ce631e7ed0982e
|
7
|
+
data.tar.gz: 70fe2847b7971c9479490d26adfdf05ea9f9f065be171281fce3a0b536b440d506feede266bb05943796aa81568ae32045d4bd9a202609633233564a78eeefa1
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Use the latest 2.1 version of CircleCI pipeline process engine.
|
2
|
+
# See: https://circleci.com/docs/2.0/configuration-reference
|
3
|
+
version: 2.1
|
4
|
+
|
5
|
+
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
|
6
|
+
# See: https://circleci.com/docs/2.0/orb-intro/
|
7
|
+
orbs:
|
8
|
+
ruby: circleci/ruby@0.1.2
|
9
|
+
coveralls: coveralls/coveralls@1.0.6
|
10
|
+
node: circleci/node@5.0.0
|
11
|
+
|
12
|
+
# Define a job to be invoked later in a workflow.
|
13
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
|
14
|
+
jobs:
|
15
|
+
build:
|
16
|
+
parameters:
|
17
|
+
ruby_version:
|
18
|
+
type: string
|
19
|
+
rails_version:
|
20
|
+
type: string
|
21
|
+
docker:
|
22
|
+
- image: cimg/ruby:<< parameters.ruby_version >>
|
23
|
+
executor: ruby/default
|
24
|
+
environment:
|
25
|
+
RAILS_TEST_VERSION: << parameters.rails_version >>
|
26
|
+
EUID: 0 # not sure why this is needed, but sudo npm fails
|
27
|
+
steps:
|
28
|
+
- checkout
|
29
|
+
- run:
|
30
|
+
name: Which ruby?
|
31
|
+
command: ruby -v
|
32
|
+
- run:
|
33
|
+
name: Which bundler?
|
34
|
+
command: bundle -v
|
35
|
+
- ruby/bundle-install
|
36
|
+
- run:
|
37
|
+
name: Run tests
|
38
|
+
command: bundle exec rake
|
39
|
+
- node/install:
|
40
|
+
node-version: 10.0.0
|
41
|
+
- coveralls/upload:
|
42
|
+
parallel: true
|
43
|
+
coverage:
|
44
|
+
docker:
|
45
|
+
- image: circleci/node:10.0.0
|
46
|
+
steps:
|
47
|
+
- coveralls/upload:
|
48
|
+
parallel_finished: true
|
49
|
+
|
50
|
+
workflows:
|
51
|
+
tests:
|
52
|
+
jobs:
|
53
|
+
- build:
|
54
|
+
matrix:
|
55
|
+
alias: Rails 4
|
56
|
+
parameters:
|
57
|
+
rails_version: ["~> 4.0"]
|
58
|
+
ruby_version: ["2.6.6"]
|
59
|
+
- build:
|
60
|
+
matrix:
|
61
|
+
alias: Rails 5
|
62
|
+
parameters:
|
63
|
+
rails_version: ["~> 5.0"]
|
64
|
+
ruby_version: ["2.6.6", "2.7.2"]
|
65
|
+
- build:
|
66
|
+
matrix:
|
67
|
+
alias: Rails 6
|
68
|
+
parameters:
|
69
|
+
rails_version: ["~> 6.0"]
|
70
|
+
ruby_version: ["2.6.6", "2.7.2", "3.0.0"]
|
71
|
+
- build:
|
72
|
+
matrix:
|
73
|
+
alias: Rails 7
|
74
|
+
parameters:
|
75
|
+
rails_version: ["~> 7.0"]
|
76
|
+
ruby_version: ["2.7.2", "3.0.0"]
|
77
|
+
- coverage:
|
78
|
+
requires: ["Rails 4", "Rails 5", "Rails 6", "Rails 7"]
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<p align="center">
|
4
|
-
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/2/21/Spyke.jpg/392px-Spyke.jpg" width="15%" />
|
1
|
+
<div align="center">
|
2
|
+
<img src="spyke.svg" width="250" alt="Spyke" />
|
5
3
|
<br/>
|
6
4
|
Interact with remote <strong>REST services</strong> in an <strong>ActiveRecord-like</strong> manner.
|
7
5
|
<br /><br />
|
8
6
|
<a href="https://rubygems.org/gems/spyke"><img src="https://badge.fury.io/rb/spyke.svg?style=flat" alt="Gem Version"></a>
|
9
7
|
<a href="https://codeclimate.com/github/balvig/spyke"><img src="https://codeclimate.com/github/balvig/spyke/badges/gpa.svg" /></a>
|
10
|
-
<a href='https://coveralls.io/
|
11
|
-
<a href="https://
|
12
|
-
</
|
8
|
+
<a href='https://coveralls.io/github/balvig/spyke'><img src="https://coveralls.io/repos/github/balvig/spyke/badge.svg" /></a>
|
9
|
+
<a href="https://circleci.com/gh/balvig/spyke"><img src="https://circleci.com/gh/balvig/spyke.svg?style=shield" /></a>
|
10
|
+
</div>
|
13
11
|
|
14
12
|
---
|
15
13
|
|
@@ -131,8 +129,6 @@ Post.find(4) # => GET http://api.com/posts/4
|
|
131
129
|
Custom request methods and the `with` scope methods allow you to
|
132
130
|
perform requests for non-REST actions:
|
133
131
|
|
134
|
-
The `.with` scope:
|
135
|
-
|
136
132
|
```ruby
|
137
133
|
Post.with('posts/recent') # => GET http://api.com/posts/recent
|
138
134
|
Post.with(:recent) # => GET http://api.com/posts/recent
|
@@ -172,7 +168,7 @@ Spyke expects errors to be formatted in the same way as the
|
|
172
168
|
[ActiveModel::Errors details hash](https://cowbell-labs.com/2015-01-22-active-model-errors-details.html), ie:
|
173
169
|
|
174
170
|
```ruby
|
175
|
-
{ title: [{ error: 'blank'}, { error: 'too_short', count: 10 }]}
|
171
|
+
{ title: [{ error: 'blank'}, { error: 'too_short', count: 10 }] }
|
176
172
|
```
|
177
173
|
|
178
174
|
If the API you're using returns errors in a different format you can
|
@@ -246,9 +242,3 @@ Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
|
|
246
242
|
|
247
243
|
For more examples of how Spyke can be used, check out [fixtures.rb](https://github.com/balvig/spyke/blob/master/test/support/fixtures.rb) and the
|
248
244
|
[test suite](https://github.com/balvig/spyke/tree/master/test).
|
249
|
-
|
250
|
-
|
251
|
-
## Contributing
|
252
|
-
|
253
|
-
If possible please take a look at the [tests marked "wishlisted"](https://github.com/balvig/spyke/search?l=ruby&q=wishlisted&utf8=%E2%9C%93)!
|
254
|
-
These are features/fixes I'd like to implement but haven't gotten around to doing yet :)
|
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'spyke'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
# Require support files via `bin/console -t`
|
8
|
+
if ARGV.any? { |o| %w(-t --test).include? o }
|
9
|
+
require_relative '../test/support/fixtures.rb'
|
10
|
+
Spyke::Base.connection.response :logger
|
11
|
+
end
|
12
|
+
|
13
|
+
Pry.start
|
@@ -29,7 +29,7 @@ module Spyke
|
|
29
29
|
candidates << type_name
|
30
30
|
|
31
31
|
candidates.each do |candidate|
|
32
|
-
constant =
|
32
|
+
constant = candidate.safe_constantize
|
33
33
|
return constant if candidate == constant.to_s
|
34
34
|
end
|
35
35
|
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
@@ -94,9 +94,9 @@ module Spyke
|
|
94
94
|
|
95
95
|
def method_missing(name, *args, &block)
|
96
96
|
case
|
97
|
-
when association?(name) then association(name).load
|
98
|
-
when attribute?(name) then attribute(name)
|
99
|
-
when predicate?(name) then predicate(name)
|
97
|
+
when association?(name) then association(name, *args).load
|
98
|
+
when attribute?(name) then attribute(name, *args)
|
99
|
+
when predicate?(name) then predicate(name, *args)
|
100
100
|
when setter?(name) then set_attribute(name, args.first)
|
101
101
|
else super
|
102
102
|
end
|
data/lib/spyke/http.rb
CHANGED
@@ -46,7 +46,8 @@ module Spyke
|
|
46
46
|
def send_request(method, path, params)
|
47
47
|
connection.send(method) do |request|
|
48
48
|
if method == :get
|
49
|
-
|
49
|
+
path, params = merge_query_params(path, params)
|
50
|
+
request.url path, params
|
50
51
|
else
|
51
52
|
request.url path.to_s
|
52
53
|
request.body = params
|
@@ -56,6 +57,13 @@ module Spyke
|
|
56
57
|
raise ConnectionError
|
57
58
|
end
|
58
59
|
|
60
|
+
def merge_query_params(path, params)
|
61
|
+
parsed_uri = Addressable::URI.parse(path.to_s)
|
62
|
+
path = parsed_uri.path
|
63
|
+
params = params.merge(parsed_uri.query_values || {})
|
64
|
+
[path, params]
|
65
|
+
end
|
66
|
+
|
59
67
|
def scoped_request(method)
|
60
68
|
uri = new.uri
|
61
69
|
params = current_scope.params.except(*uri.variables)
|
@@ -106,10 +114,10 @@ module Spyke
|
|
106
114
|
field_errors.each do |error_attributes|
|
107
115
|
error = NormalizedValidationError.new(error_attributes)
|
108
116
|
|
109
|
-
if
|
110
|
-
errors.add(field.to_sym, error.message, **error.options)
|
111
|
-
else
|
117
|
+
if ActiveSupport::VERSION::MAJOR < 5
|
112
118
|
errors.add(field.to_sym, error.message, error.options)
|
119
|
+
else
|
120
|
+
errors.add(field.to_sym, error.message, **error.options)
|
113
121
|
end
|
114
122
|
end
|
115
123
|
end
|
data/lib/spyke/scope_registry.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
module Spyke
|
2
2
|
class ScopeRegistry
|
3
|
-
|
3
|
+
# https://github.com/balvig/spyke/pull/128
|
4
|
+
if ActiveSupport::VERSION::MAJOR >= 7
|
5
|
+
class << self
|
6
|
+
delegate :value_for, :set_value_for, to: :new
|
7
|
+
end
|
8
|
+
|
9
|
+
thread_mattr_accessor :registry
|
10
|
+
else
|
11
|
+
extend ActiveSupport::PerThreadRegistry
|
12
|
+
|
13
|
+
attr_accessor :registry
|
14
|
+
end
|
4
15
|
|
5
16
|
def initialize
|
6
|
-
|
17
|
+
self.registry ||= Hash.new { |hash, key| hash[key] = {} }
|
7
18
|
end
|
8
19
|
|
9
20
|
def value_for(scope_type, variable_name)
|
10
|
-
|
21
|
+
registry[scope_type][variable_name]
|
11
22
|
end
|
12
23
|
|
13
24
|
def set_value_for(scope_type, variable_name, value)
|
14
|
-
|
25
|
+
registry[scope_type][variable_name] = value
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
data/lib/spyke/version.rb
CHANGED
data/spyke.gemspec
CHANGED
@@ -18,15 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency 'activesupport', '>= 4.0.0'
|
22
|
-
spec.add_dependency 'activemodel', '>= 4.0.0'
|
21
|
+
spec.add_dependency 'activesupport', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
22
|
+
spec.add_dependency 'activemodel', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
23
23
|
spec.add_dependency 'faraday', '>= 0.9.0', '< 2.0'
|
24
24
|
spec.add_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
|
25
25
|
spec.add_dependency 'addressable', '>= 2.5.2'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'actionpack', '>= 4.0.0'
|
27
|
+
spec.add_development_dependency 'actionpack', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
28
28
|
spec.add_development_dependency 'bundler', '>= 1.6'
|
29
|
-
spec.add_development_dependency 'coveralls', '~> 0.7'
|
30
29
|
spec.add_development_dependency 'minitest'
|
31
30
|
spec.add_development_dependency 'minitest-line'
|
32
31
|
spec.add_development_dependency 'minitest-reporters'
|
@@ -34,5 +33,7 @@ Gem::Specification.new do |spec|
|
|
34
33
|
spec.add_development_dependency 'multi_json'
|
35
34
|
spec.add_development_dependency 'pry'
|
36
35
|
spec.add_development_dependency 'rake'
|
36
|
+
spec.add_development_dependency 'simplecov'
|
37
|
+
spec.add_development_dependency 'simplecov-lcov'
|
37
38
|
spec.add_development_dependency 'webmock'
|
38
39
|
end
|
data/spyke.svg
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="180" height="70" viewBox="0 0 180 70" xml:space="preserve">
|
4
|
+
<desc>Created with Fabric.js 4.6.0</desc>
|
5
|
+
<defs>
|
6
|
+
</defs>
|
7
|
+
<g transform="matrix(0.83 0 0 0.8 31.5 36)" id="6X9shhn5tjKNE9PTybgYf" >
|
8
|
+
<path style="stroke: rgb(252,0,51); stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-opacity: 0; fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(0, 0)" d="M -19.8939 12.44496 L 19.8939 -12.44496 L 19.8939 12.44496" stroke-linecap="round" />
|
9
|
+
</g>
|
10
|
+
<g transform="matrix(1 0 0 1 48 26)" id="qfktuO63U17zxOoFBmSIk" >
|
11
|
+
<path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
|
12
|
+
</g>
|
13
|
+
<g transform="matrix(1 0 0 1 48 45)" id="CoP4qh0-57aRlWWd5gWpq" >
|
14
|
+
<path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
|
15
|
+
</g>
|
16
|
+
<g transform="matrix(1 0 0 1 16 45)" id="0AYtWnywiPmVyWgmd3Nax" >
|
17
|
+
<path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
|
18
|
+
</g>
|
19
|
+
<g transform="matrix(1.01 0 0 1.02 111 35.5)" id="0CUp8y4TleogKJWzIB5ti" >
|
20
|
+
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-115.71, -44.78)" d="M 72.39608287 59.952 L 72.39608287 59.952 Q 69.77208287 59.952 67.88608287 59.1525 Q 66.00008287 58.353 64.99558287 57.3075 Q 63.99108287 56.262 63.99108287 55.524 L 63.99108287 55.524 Q 63.99108287 55.196 64.17558287 54.827 Q 64.36008287 54.458 64.64708287 54.2325 Q 64.93408287 54.007 65.22108287 54.007 L 65.22108287 54.007 Q 65.63108287 54.007 66.06158287 54.5195 Q 66.49208287 55.032 67.20958287 55.7085 Q 67.92708287 56.385 69.11608287 56.8975 Q 70.30508287 57.41 72.23208287 57.41 L 72.23208287 57.41 Q 74.15908287 57.41 75.53258287 56.7745 Q 76.90608287 56.139 77.62358287 54.8885 Q 78.34108287 53.638 78.34108287 51.752 L 78.34108287 51.752 Q 78.34108287 49.784 77.60308287 48.5745 Q 76.86508287 47.365 75.65558287 46.6065 Q 74.44608287 45.848 73.01108287 45.2945 Q 71.57608287 44.741 70.12058287 44.1875 Q 68.66508287 43.634 67.45558287 42.7935 Q 66.24608287 41.953 65.48758287 40.5795 Q 64.72908287 39.206 64.72908287 37.074 L 64.72908287 37.074 Q 64.72908287 34.819 65.54908287 33.384 Q 66.36908287 31.949 67.66058287 31.129 Q 68.95208287 30.309 70.46908287 29.9605 Q 71.98608287 29.612 73.42108287 29.612 L 73.42108287 29.612 Q 74.56908287 29.612 75.77858287 29.7965 Q 76.98808287 29.981 78.01308287 30.309 Q 79.03808287 30.637 79.67358287 31.088 Q 80.30908287 31.539 80.30908287 32.113 L 80.30908287 32.113 Q 80.30908287 32.4 80.16558287 32.7485 Q 80.02208287 33.097 79.77608287 33.3635 Q 79.53008287 33.63 79.12008287 33.63 L 79.12008287 33.63 Q 78.75108287 33.63 78.09508287 33.2405 Q 77.43908287 32.851 76.31158287 32.4615 Q 75.18408287 32.072 73.38008287 32.072 L 73.38008287 32.072 Q 71.90408287 32.072 70.53058287 32.5025 Q 69.15708287 32.933 68.29608287 33.958 Q 67.43508287 34.983 67.43508287 36.828 L 67.43508287 36.828 Q 67.43508287 38.468 68.19358287 39.4725 Q 68.95208287 40.477 70.16158287 41.092 Q 71.37108287 41.707 72.80608287 42.2195 Q 74.24108287 42.732 75.69658287 43.3675 Q 77.15208287 44.003 78.36158287 44.9665 Q 79.57108287 45.93 80.30908287 47.488 Q 81.04708287 49.046 81.04708287 51.506 L 81.04708287 51.506 Q 81.04708287 54.417 79.94008287 56.2825 Q 78.83308287 58.148 76.88558287 59.05 Q 74.93808287 59.952 72.39608287 59.952 Z M 87.23808287 59.665 L 87.23808287 59.665 Q 86.70508287 59.665 86.29508287 59.3985 Q 85.88508287 59.132 85.88508287 58.599 L 85.88508287 58.599 L 85.88508287 30.678 Q 85.88508287 30.268 86.19258287 30.0015 Q 86.50008287 29.735 87.03308287 29.694 L 87.03308287 29.694 L 94.57708287 29.694 Q 96.95508287 29.694 98.88208287 30.555 Q 100.80908287 31.416 101.91608287 33.3225 Q 103.02308287 35.229 103.02308287 38.386 L 103.02308287 38.386 L 103.02308287 38.796 Q 103.02308287 41.994 101.89558287 43.9005 Q 100.76808287 45.807 98.82058287 46.668 Q 96.87308287 47.529 94.49508287 47.529 L 94.49508287 47.529 L 88.59108287 47.529 L 88.59108287 58.599 Q 88.59108287 59.132 88.16058287 59.3985 Q 87.73008287 59.665 87.23808287 59.665 Z M 88.59108287 32.195 L 88.59108287 45.192 L 94.49508287 45.192 Q 97.24208287 45.192 98.77958287 43.6545 Q 100.31708287 42.117 100.31708287 38.919 L 100.31708287 38.919 L 100.31708287 38.427 Q 100.31708287 35.229 98.77958287 33.712 Q 97.24208287 32.195 94.49508287 32.195 L 94.49508287 32.195 L 88.59108287 32.195 Z M 115.15908287 59.665 L 115.15908287 59.665 Q 114.66708287 59.665 114.23658287 59.3985 Q 113.80608287 59.132 113.80608287 58.599 L 113.80608287 58.599 L 113.80608287 48.185 Q 113.80608287 47.98 113.76508287 47.857 L 113.76508287 47.857 L 105.27808287 31.58 Q 105.15508287 31.334 105.11408287 31.1495 Q 105.07308287 30.965 105.07308287 30.842 L 105.07308287 30.842 Q 105.07308287 30.473 105.29858287 30.227 Q 105.52408287 29.981 105.87258287 29.8375 Q 106.22108287 29.694 106.54908287 29.694 L 106.54908287 29.694 Q 106.87708287 29.694 107.14358287 29.899 Q 107.41008287 30.104 107.61508287 30.514 L 107.61508287 30.514 L 115.15908287 45.479 L 122.74408287 30.514 Q 122.99008287 30.104 123.25658287 29.899 Q 123.52308287 29.694 123.81008287 29.694 L 123.81008287 29.694 Q 124.17908287 29.694 124.50708287 29.8375 Q 124.83508287 29.981 125.06058287 30.227 Q 125.28608287 30.473 125.28608287 30.842 L 125.28608287 30.842 Q 125.28608287 30.965 125.24508287 31.1495 Q 125.20408287 31.334 125.12208287 31.58 L 125.12208287 31.58 L 116.59408287 47.857 Q 116.51208287 47.98 116.51208287 48.185 L 116.51208287 48.185 L 116.51208287 58.599 Q 116.51208287 59.132 116.10208287 59.3985 Q 115.69208287 59.665 115.15908287 59.665 Z M 130.49308287 59.665 L 130.49308287 59.665 Q 129.96008287 59.665 129.55008287 59.3985 Q 129.14008287 59.132 129.14008287 58.599 L 129.14008287 58.599 L 129.14008287 30.678 Q 129.14008287 30.145 129.55008287 29.9195 Q 129.96008287 29.694 130.49308287 29.694 L 130.49308287 29.694 Q 130.98508287 29.694 131.41558287 29.9195 Q 131.84608287 30.145 131.84608287 30.678 L 131.84608287 30.678 L 131.84608287 45.192 L 143.69508287 30.104 Q 143.98208287 29.694 144.55608287 29.694 L 144.55608287 29.694 Q 144.88408287 29.694 145.23258287 29.899 Q 145.58108287 30.104 145.80658287 30.4115 Q 146.03208287 30.719 146.03208287 31.088 L 146.03208287 31.088 Q 146.03208287 31.211 145.99108287 31.3955 Q 145.95008287 31.58 145.82708287 31.703 L 145.82708287 31.703 L 137.01208287 42.65 L 147.09808287 57.82 Q 147.26208287 58.066 147.26208287 58.353 L 147.26208287 58.353 Q 147.26208287 58.722 147.03658287 59.0295 Q 146.81108287 59.337 146.46258287 59.5215 Q 146.11408287 59.706 145.70408287 59.706 L 145.70408287 59.706 Q 145.41708287 59.706 145.15058287 59.5625 Q 144.88408287 59.419 144.67908287 59.132 L 144.67908287 59.132 L 135.20808287 44.905 L 131.84608287 49.169 L 131.84608287 58.599 Q 131.84608287 59.132 131.41558287 59.3985 Q 130.98508287 59.665 130.49308287 59.665 Z M 166.40908287 59.665 L 151.81308287 59.665 Q 151.36208287 59.665 150.97258287 59.3985 Q 150.58308287 59.132 150.58308287 58.599 L 150.58308287 58.599 L 150.58308287 30.719 Q 150.58308287 30.227 150.97258287 29.9605 Q 151.36208287 29.694 151.81308287 29.694 L 151.81308287 29.694 L 166.40908287 29.694 Q 166.94208287 29.694 167.18808287 30.0835 Q 167.43408287 30.473 167.43408287 30.883 L 167.43408287 30.883 Q 167.43408287 31.416 167.16758287 31.8055 Q 166.90108287 32.195 166.40908287 32.195 L 166.40908287 32.195 L 153.28908287 32.195 L 153.28908287 43.47 L 159.72608287 43.47 Q 160.21808287 43.47 160.48458287 43.839 Q 160.75108287 44.208 160.75108287 44.7 L 160.75108287 44.7 Q 160.75108287 45.069 160.50508287 45.438 Q 160.25908287 45.807 159.72608287 45.807 L 159.72608287 45.807 L 153.28908287 45.807 L 153.28908287 57.164 L 166.40908287 57.164 Q 166.90108287 57.164 167.16758287 57.533 Q 167.43408287 57.902 167.43408287 58.435 L 167.43408287 58.435 Q 167.43408287 58.886 167.18808287 59.2755 Q 166.94208287 59.665 166.40908287 59.665 L 166.40908287 59.665 Z" stroke-linecap="round" />
|
21
|
+
</g>
|
22
|
+
</svg>
|
data/test/associations_test.rb
CHANGED
@@ -241,6 +241,15 @@ module Spyke
|
|
241
241
|
assert_requested endpoint
|
242
242
|
end
|
243
243
|
|
244
|
+
|
245
|
+
def test_using_where_with_custom_uri_including_query_params
|
246
|
+
endpoint = stub_request(:get, 'http://sushi.com/featured_ingredients?filter[group_id]=1&filter[status]=published')
|
247
|
+
|
248
|
+
Group.new(id: 1).featured_ingredients.where(filter: { status: 'published' }).to_a
|
249
|
+
|
250
|
+
assert_requested endpoint
|
251
|
+
end
|
252
|
+
|
244
253
|
def test_path_inferred_from_name
|
245
254
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/1/gallery_images')
|
246
255
|
Recipe.new(id: 1).gallery_images.to_a
|
data/test/attributes_test.rb
CHANGED
@@ -18,8 +18,13 @@ module Spyke
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_initializing_using_unpermitted_strong_params
|
21
|
-
|
22
|
-
Ingredient.new(strong_params(name: 'Flour'))
|
21
|
+
if ActiveSupport::VERSION::MAJOR < 5
|
22
|
+
ingredient = Ingredient.new(strong_params(name: 'Flour'))
|
23
|
+
assert_equal({}, ingredient.attributes)
|
24
|
+
else
|
25
|
+
assert_raises ActionController::UnfilteredParameters do
|
26
|
+
Ingredient.new(strong_params(name: 'Flour'))
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -157,7 +162,6 @@ module Spyke
|
|
157
162
|
end
|
158
163
|
|
159
164
|
def test_rejecting_wrong_number_of_args
|
160
|
-
skip 'wishlisted'
|
161
165
|
stub_request(:any, /.*/)
|
162
166
|
recipe = Recipe.new(description: 'Delicious')
|
163
167
|
assert_raises ArgumentError do
|
data/test/custom_request_test.rb
CHANGED
@@ -70,7 +70,7 @@ module Spyke
|
|
70
70
|
|
71
71
|
def test_multiple_apis_with_custom_fallback
|
72
72
|
fallback_endpoint = stub_request(:get, 'http://sushi.com/recipes')
|
73
|
-
|
73
|
+
_primary_endpoint = stub_request(:get, 'http://sashimi.com/recipes').to_timeout
|
74
74
|
OtherRecipe.all.to_a
|
75
75
|
assert_requested fallback_endpoint
|
76
76
|
end
|
data/test/fallbacks_test.rb
CHANGED
@@ -7,6 +7,12 @@ module Spyke
|
|
7
7
|
stub_request(:get, "http://sushi.com/recipes?published=true").to_timeout
|
8
8
|
end
|
9
9
|
|
10
|
+
def test_find_without_fallback
|
11
|
+
assert_raises ConnectionError do
|
12
|
+
Recipe.find(1)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
def test_find_with_default_fallback
|
11
17
|
assert_raises ResourceNotFound do
|
12
18
|
Recipe.with_fallback.find(1)
|
data/test/path_test.rb
CHANGED
@@ -21,13 +21,13 @@ module Spyke
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_required_variables
|
24
|
-
assert_raises
|
24
|
+
assert_raises InvalidPathError, 'Missing required variables: user_id in /users/:user_id/recipes/(:id)' do
|
25
25
|
Path.new('/users/:user_id/recipes/(:id)', id: 2).to_s
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_mix_of_required_and_unrequired_variables
|
30
|
-
assert_raises
|
30
|
+
assert_raises InvalidPathError, 'Missing required variables: part2, part4' do
|
31
31
|
Path.new('/1/profiles(/:part1)/:part2(/:part3)/:part4.xml').to_s
|
32
32
|
end
|
33
33
|
end
|
data/test/support/fixtures.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
# Dummy api
|
2
4
|
class JSONParser < Faraday::Response::Middleware
|
3
5
|
def parse(body)
|
@@ -79,6 +81,7 @@ end
|
|
79
81
|
|
80
82
|
class Group < Spyke::Base
|
81
83
|
has_many :ingredients, uri: nil
|
84
|
+
has_many :featured_ingredients, uri: 'featured_ingredients?filter[group_id]=:group_id', class_name: "Ingredient"
|
82
85
|
accepts_nested_attributes_for :ingredients
|
83
86
|
|
84
87
|
def self.build_default
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-lcov'
|
3
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
4
|
+
c.report_with_single_file = true
|
5
|
+
c.single_report_path = 'coverage/lcov.info'
|
6
|
+
end
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
5
8
|
SimpleCov.start do
|
6
9
|
add_filter 'test'
|
7
10
|
end
|
@@ -10,7 +13,6 @@ require 'spyke'
|
|
10
13
|
require 'minitest/autorun'
|
11
14
|
require 'minitest/reporters'
|
12
15
|
require 'mocha/minitest'
|
13
|
-
require 'multi_json'
|
14
16
|
require 'pry'
|
15
17
|
|
16
18
|
# Require support files
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spyke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -121,21 +121,21 @@ dependencies:
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '1.6'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
|
-
name:
|
124
|
+
name: minitest
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- - "
|
127
|
+
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: '0
|
129
|
+
version: '0'
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
|
-
- - "
|
134
|
+
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version: '0
|
136
|
+
version: '0'
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
|
-
name: minitest
|
138
|
+
name: minitest-line
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
141
|
- - ">="
|
@@ -149,7 +149,7 @@ dependencies:
|
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
|
-
name: minitest-
|
152
|
+
name: minitest-reporters
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
@@ -163,7 +163,7 @@ dependencies:
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
- !ruby/object:Gem::Dependency
|
166
|
-
name:
|
166
|
+
name: mocha
|
167
167
|
requirement: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
169
|
- - ">="
|
@@ -177,7 +177,7 @@ dependencies:
|
|
177
177
|
- !ruby/object:Gem::Version
|
178
178
|
version: '0'
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
|
-
name:
|
180
|
+
name: multi_json
|
181
181
|
requirement: !ruby/object:Gem::Requirement
|
182
182
|
requirements:
|
183
183
|
- - ">="
|
@@ -191,7 +191,7 @@ dependencies:
|
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: '0'
|
193
193
|
- !ruby/object:Gem::Dependency
|
194
|
-
name:
|
194
|
+
name: pry
|
195
195
|
requirement: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
197
|
- - ">="
|
@@ -205,7 +205,7 @@ dependencies:
|
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
207
|
- !ruby/object:Gem::Dependency
|
208
|
-
name:
|
208
|
+
name: rake
|
209
209
|
requirement: !ruby/object:Gem::Requirement
|
210
210
|
requirements:
|
211
211
|
- - ">="
|
@@ -219,7 +219,21 @@ dependencies:
|
|
219
219
|
- !ruby/object:Gem::Version
|
220
220
|
version: '0'
|
221
221
|
- !ruby/object:Gem::Dependency
|
222
|
-
name:
|
222
|
+
name: simplecov
|
223
|
+
requirement: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
type: :development
|
229
|
+
prerelease: false
|
230
|
+
version_requirements: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
- !ruby/object:Gem::Dependency
|
236
|
+
name: simplecov-lcov
|
223
237
|
requirement: !ruby/object:Gem::Requirement
|
224
238
|
requirements:
|
225
239
|
- - ">="
|
@@ -249,16 +263,18 @@ dependencies:
|
|
249
263
|
description: Interact with REST services in an ActiveRecord-like manner
|
250
264
|
email:
|
251
265
|
- jens@balvig.com
|
252
|
-
executables:
|
266
|
+
executables:
|
267
|
+
- console
|
253
268
|
extensions: []
|
254
269
|
extra_rdoc_files: []
|
255
270
|
files:
|
271
|
+
- ".circleci/config.yml"
|
256
272
|
- ".gitignore"
|
257
|
-
- ".travis.yml"
|
258
273
|
- Gemfile
|
259
274
|
- LICENSE.txt
|
260
275
|
- README.md
|
261
276
|
- Rakefile
|
277
|
+
- bin/console
|
262
278
|
- lib/spyke.rb
|
263
279
|
- lib/spyke/associations.rb
|
264
280
|
- lib/spyke/associations/association.rb
|
@@ -286,6 +302,7 @@ files:
|
|
286
302
|
- lib/spyke/scoping.rb
|
287
303
|
- lib/spyke/version.rb
|
288
304
|
- spyke.gemspec
|
305
|
+
- spyke.svg
|
289
306
|
- test/activemodel_dirty_test.rb
|
290
307
|
- test/associations_test.rb
|
291
308
|
- test/attributes_test.rb
|
@@ -295,6 +312,7 @@ files:
|
|
295
312
|
- test/fallbacks_test.rb
|
296
313
|
- test/orm_test.rb
|
297
314
|
- test/path_test.rb
|
315
|
+
- test/scope_registry_test.rb
|
298
316
|
- test/scopes_test.rb
|
299
317
|
- test/support/fixtures.rb
|
300
318
|
- test/support/webmock.rb
|
@@ -318,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
336
|
- !ruby/object:Gem::Version
|
319
337
|
version: '0'
|
320
338
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
339
|
+
rubygems_version: 3.2.3
|
322
340
|
signing_key:
|
323
341
|
specification_version: 4
|
324
342
|
summary: Interact with REST services in an ActiveRecord-like manner
|
@@ -332,6 +350,7 @@ test_files:
|
|
332
350
|
- test/fallbacks_test.rb
|
333
351
|
- test/orm_test.rb
|
334
352
|
- test/path_test.rb
|
353
|
+
- test/scope_registry_test.rb
|
335
354
|
- test/scopes_test.rb
|
336
355
|
- test/support/fixtures.rb
|
337
356
|
- test/support/webmock.rb
|