spyke 6.1.1 → 7.0.0
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 +85 -0
- data/Gemfile +4 -0
- data/README.md +12 -19
- data/bin/console +13 -0
- data/lib/spyke/attribute_assignment.rb +3 -3
- data/lib/spyke/attributes.rb +1 -1
- data/lib/spyke/http.rb +3 -5
- data/lib/spyke/scope_registry.rb +15 -4
- data/lib/spyke/version.rb +1 -1
- data/lib/spyke.rb +16 -0
- data/spyke.gemspec +7 -6
- data/spyke.svg +22 -0
- data/test/activemodel_dirty_test.rb +1 -1
- data/test/attributes_test.rb +8 -4
- data/test/custom_request_test.rb +1 -1
- data/test/fallbacks_test.rb +6 -0
- data/test/scope_registry_test.rb +11 -0
- data/test/support/fixtures.rb +8 -5
- data/test/test_helper.rb +7 -5
- metadata +44 -31
- 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: 6d4ddb1fd345f49012040e7f462f63003f1a1ff57ddc7173bb14cb5ca03c5bed
|
4
|
+
data.tar.gz: bd1674887dc87a21ca4bad570d7375299add2312a3af7183d466078b6510367f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c83ab8e4a46d6afff3624e7a1b2baccef8b5fe97c875271268c0dd7c51b65a76e85e019cf4ed749b06ef5414566203f6e618e22aaafe12c6494ac39f113abc75
|
7
|
+
data.tar.gz: c2f0f2bb8bbce8cb8047be70f0f946305efdff464f6c0e4ad4a46b13cfc2fba19f87ff98c8139102a107e9c64e45035246f5f66d055ed7402772685ca16d348e
|
@@ -0,0 +1,85 @@
|
|
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
|
+
faraday_version:
|
22
|
+
type: string
|
23
|
+
docker:
|
24
|
+
- image: cimg/ruby:<< parameters.ruby_version >>
|
25
|
+
executor: ruby/default
|
26
|
+
environment:
|
27
|
+
RAILS_TEST_VERSION: << parameters.rails_version >>
|
28
|
+
FARADAY_TEST_VERSION: << parameters.faraday_version >>
|
29
|
+
EUID: 0 # not sure why this is needed, but sudo npm fails
|
30
|
+
steps:
|
31
|
+
- checkout
|
32
|
+
- run:
|
33
|
+
name: Which ruby?
|
34
|
+
command: ruby -v
|
35
|
+
- run:
|
36
|
+
name: Which bundler?
|
37
|
+
command: bundle -v
|
38
|
+
- ruby/bundle-install
|
39
|
+
- run:
|
40
|
+
name: Run tests
|
41
|
+
command: bundle exec rake
|
42
|
+
- node/install:
|
43
|
+
node-version: 10.0.0
|
44
|
+
- coveralls/upload:
|
45
|
+
parallel: true
|
46
|
+
coverage:
|
47
|
+
docker:
|
48
|
+
- image: circleci/node:10.0.0
|
49
|
+
steps:
|
50
|
+
- coveralls/upload:
|
51
|
+
parallel_finished: true
|
52
|
+
|
53
|
+
workflows:
|
54
|
+
tests:
|
55
|
+
jobs:
|
56
|
+
- build:
|
57
|
+
matrix:
|
58
|
+
alias: Rails 4
|
59
|
+
parameters:
|
60
|
+
rails_version: ["~> 4.0"]
|
61
|
+
ruby_version: ["2.6.9"]
|
62
|
+
faraday_version: ["< 2.0"]
|
63
|
+
- build:
|
64
|
+
matrix:
|
65
|
+
alias: Rails 5
|
66
|
+
parameters:
|
67
|
+
rails_version: ["~> 5.0"]
|
68
|
+
ruby_version: ["2.6.9", "2.7.5"]
|
69
|
+
faraday_version: ["< 2.0", ">= 2.0"]
|
70
|
+
- build:
|
71
|
+
matrix:
|
72
|
+
alias: Rails 6
|
73
|
+
parameters:
|
74
|
+
rails_version: ["~> 6.0"]
|
75
|
+
ruby_version: ["2.6.9", "2.7.5", "3.0.3"]
|
76
|
+
faraday_version: ["< 2.0", ">= 2.0"]
|
77
|
+
- build:
|
78
|
+
matrix:
|
79
|
+
alias: Rails 7
|
80
|
+
parameters:
|
81
|
+
rails_version: ["~> 7.0"]
|
82
|
+
ruby_version: ["2.7.5", "3.0.3", "3.1.1"]
|
83
|
+
faraday_version: ["< 2.0", ">= 2.0"]
|
84
|
+
- coverage:
|
85
|
+
requires: ["Rails 4", "Rails 5", "Rails 6", "Rails 7"]
|
data/Gemfile
CHANGED
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
|
|
@@ -50,10 +48,10 @@ So, for example for an API that returns JSON like this:
|
|
50
48
|
```ruby
|
51
49
|
# config/initializers/spyke.rb
|
52
50
|
|
53
|
-
class JSONParser < Faraday::
|
54
|
-
def
|
55
|
-
json = MultiJson.load(body, symbolize_keys: true)
|
56
|
-
{
|
51
|
+
class JSONParser < Faraday::Middleware
|
52
|
+
def on_complete(env)
|
53
|
+
json = MultiJson.load(env.body, symbolize_keys: true)
|
54
|
+
env.body = {
|
57
55
|
data: json[:result],
|
58
56
|
metadata: json[:extra],
|
59
57
|
errors: json[:errors]
|
@@ -62,7 +60,8 @@ class JSONParser < Faraday::Response::Middleware
|
|
62
60
|
end
|
63
61
|
|
64
62
|
Spyke::Base.connection = Faraday.new(url: 'http://api.com') do |c|
|
65
|
-
c.request :
|
63
|
+
c.request :multipart
|
64
|
+
c.request :json # if using Faraday 1.x, please add `faraday_middleware` to your dependencies first
|
66
65
|
c.use JSONParser
|
67
66
|
c.adapter Faraday.default_adapter
|
68
67
|
end
|
@@ -204,7 +203,7 @@ but this can be disabled or customized:
|
|
204
203
|
```ruby
|
205
204
|
class Article < Spyke::Base
|
206
205
|
# Default
|
207
|
-
include_root_in_json
|
206
|
+
include_root_in_json true # { article: { title: ...} }
|
208
207
|
|
209
208
|
# Custom
|
210
209
|
include_root_in_json :post # { post: { title: ...} }
|
@@ -244,9 +243,3 @@ Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
|
|
244
243
|
|
245
244
|
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
|
246
245
|
[test suite](https://github.com/balvig/spyke/tree/master/test).
|
247
|
-
|
248
|
-
|
249
|
-
## Contributing
|
250
|
-
|
251
|
-
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)!
|
252
|
-
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
|
@@ -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/attributes.rb
CHANGED
@@ -12,7 +12,7 @@ module Spyke
|
|
12
12
|
case
|
13
13
|
when value.is_a?(Spyke::Base) then value.attributes.to_params
|
14
14
|
when value.is_a?(Array) then value.map { |v| parse_value(v) }
|
15
|
-
when value.respond_to?(:content_type) then Faraday::
|
15
|
+
when value.respond_to?(:content_type) then Faraday::Multipart::FilePart.new(value.path, value.content_type)
|
16
16
|
else value
|
17
17
|
end
|
18
18
|
end
|
data/lib/spyke/http.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday_middleware'
|
3
1
|
require 'spyke/config'
|
4
2
|
require 'spyke/path'
|
5
3
|
require 'spyke/result'
|
@@ -114,10 +112,10 @@ module Spyke
|
|
114
112
|
field_errors.each do |error_attributes|
|
115
113
|
error = NormalizedValidationError.new(error_attributes)
|
116
114
|
|
117
|
-
if
|
118
|
-
errors.add(field.to_sym, error.message, **error.options)
|
119
|
-
else
|
115
|
+
if ActiveSupport::VERSION::MAJOR < 5
|
120
116
|
errors.add(field.to_sym, error.message, error.options)
|
117
|
+
else
|
118
|
+
errors.add(field.to_sym, error.message, **error.options)
|
121
119
|
end
|
122
120
|
end
|
123
121
|
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/lib/spyke.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday/multipart'
|
6
|
+
|
7
|
+
if Gem.loaded_specs["faraday"].version < Gem::Version.new("2.0")
|
8
|
+
begin
|
9
|
+
require 'faraday_middleware'
|
10
|
+
rescue LoadError => e
|
11
|
+
puts <<~MSG
|
12
|
+
Please add `faraday_middleware` to your Gemfile when using Faraday 1.x. Alternatively,
|
13
|
+
upgrade to Faraday `~> 2` to avoid this dependency.
|
14
|
+
MSG
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
3
19
|
require 'spyke/base'
|
4
20
|
require 'spyke/instrumentation' if defined?(Rails)
|
5
21
|
require 'spyke/version'
|
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'
|
23
|
-
spec.add_dependency 'faraday', '>= 0.
|
24
|
-
spec.add_dependency '
|
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
|
+
spec.add_dependency 'faraday', ENV.fetch('FARADAY_TEST_VERSION', '>= 1.0.0'), '< 3.0'
|
24
|
+
spec.add_dependency 'faraday-multipart', '~> 1.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/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
|
|
@@ -129,7 +134,7 @@ module Spyke
|
|
129
134
|
end
|
130
135
|
|
131
136
|
def test_converting_files_to_faraday_io
|
132
|
-
Faraday::
|
137
|
+
Faraday::Multipart::FilePart.stubs(:new).with('/photo.jpg', 'image/jpeg').returns('UploadIO')
|
133
138
|
file = mock
|
134
139
|
file.stubs(:path).returns('/photo.jpg')
|
135
140
|
file.stubs(:content_type).returns('image/jpeg')
|
@@ -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/support/fixtures.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
# Dummy api
|
2
|
-
class JSONParser < Faraday::
|
3
|
-
def
|
4
|
-
json = MultiJson.load(body, symbolize_keys: true)
|
5
|
-
{
|
4
|
+
class JSONParser < Faraday::Middleware
|
5
|
+
def on_complete(env)
|
6
|
+
json = MultiJson.load(env.body, symbolize_keys: true)
|
7
|
+
env.body = {
|
6
8
|
data: json[:result],
|
7
9
|
metadata: json[:metadata],
|
8
10
|
errors: json[:errors]
|
9
11
|
}
|
10
12
|
rescue MultiJson::ParseError => exception
|
11
|
-
{ errors: { base: [ error: exception.message ] } }
|
13
|
+
env.body = { errors: { base: [ error: exception.message ] } }
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
Spyke::Base.connection = Faraday.new(url: 'http://sushi.com') do |faraday|
|
18
|
+
faraday.request :multipart
|
16
19
|
faraday.request :json
|
17
20
|
faraday.use JSONParser
|
18
21
|
faraday.adapter Faraday.default_adapter
|
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:
|
4
|
+
version: 7.0.0
|
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-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,40 +44,34 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 1.0.0
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
50
|
+
version: '3.0'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
57
|
+
version: 1.0.0
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '3.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: faraday-multipart
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 0.9.1
|
68
|
-
- - "<"
|
65
|
+
- - "~>"
|
69
66
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
67
|
+
version: '1.0'
|
71
68
|
type: :runtime
|
72
69
|
prerelease: false
|
73
70
|
version_requirements: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
|
-
- - "
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 0.9.1
|
78
|
-
- - "<"
|
72
|
+
- - "~>"
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
74
|
+
version: '1.0'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: addressable
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,21 +115,21 @@ dependencies:
|
|
121
115
|
- !ruby/object:Gem::Version
|
122
116
|
version: '1.6'
|
123
117
|
- !ruby/object:Gem::Dependency
|
124
|
-
name:
|
118
|
+
name: minitest
|
125
119
|
requirement: !ruby/object:Gem::Requirement
|
126
120
|
requirements:
|
127
|
-
- - "
|
121
|
+
- - ">="
|
128
122
|
- !ruby/object:Gem::Version
|
129
|
-
version: '0
|
123
|
+
version: '0'
|
130
124
|
type: :development
|
131
125
|
prerelease: false
|
132
126
|
version_requirements: !ruby/object:Gem::Requirement
|
133
127
|
requirements:
|
134
|
-
- - "
|
128
|
+
- - ">="
|
135
129
|
- !ruby/object:Gem::Version
|
136
|
-
version: '0
|
130
|
+
version: '0'
|
137
131
|
- !ruby/object:Gem::Dependency
|
138
|
-
name: minitest
|
132
|
+
name: minitest-line
|
139
133
|
requirement: !ruby/object:Gem::Requirement
|
140
134
|
requirements:
|
141
135
|
- - ">="
|
@@ -149,7 +143,7 @@ dependencies:
|
|
149
143
|
- !ruby/object:Gem::Version
|
150
144
|
version: '0'
|
151
145
|
- !ruby/object:Gem::Dependency
|
152
|
-
name: minitest-
|
146
|
+
name: minitest-reporters
|
153
147
|
requirement: !ruby/object:Gem::Requirement
|
154
148
|
requirements:
|
155
149
|
- - ">="
|
@@ -163,7 +157,7 @@ dependencies:
|
|
163
157
|
- !ruby/object:Gem::Version
|
164
158
|
version: '0'
|
165
159
|
- !ruby/object:Gem::Dependency
|
166
|
-
name:
|
160
|
+
name: mocha
|
167
161
|
requirement: !ruby/object:Gem::Requirement
|
168
162
|
requirements:
|
169
163
|
- - ">="
|
@@ -177,7 +171,7 @@ dependencies:
|
|
177
171
|
- !ruby/object:Gem::Version
|
178
172
|
version: '0'
|
179
173
|
- !ruby/object:Gem::Dependency
|
180
|
-
name:
|
174
|
+
name: multi_json
|
181
175
|
requirement: !ruby/object:Gem::Requirement
|
182
176
|
requirements:
|
183
177
|
- - ">="
|
@@ -191,7 +185,7 @@ dependencies:
|
|
191
185
|
- !ruby/object:Gem::Version
|
192
186
|
version: '0'
|
193
187
|
- !ruby/object:Gem::Dependency
|
194
|
-
name:
|
188
|
+
name: pry
|
195
189
|
requirement: !ruby/object:Gem::Requirement
|
196
190
|
requirements:
|
197
191
|
- - ">="
|
@@ -205,7 +199,7 @@ dependencies:
|
|
205
199
|
- !ruby/object:Gem::Version
|
206
200
|
version: '0'
|
207
201
|
- !ruby/object:Gem::Dependency
|
208
|
-
name:
|
202
|
+
name: rake
|
209
203
|
requirement: !ruby/object:Gem::Requirement
|
210
204
|
requirements:
|
211
205
|
- - ">="
|
@@ -219,7 +213,21 @@ dependencies:
|
|
219
213
|
- !ruby/object:Gem::Version
|
220
214
|
version: '0'
|
221
215
|
- !ruby/object:Gem::Dependency
|
222
|
-
name:
|
216
|
+
name: simplecov
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
type: :development
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
- !ruby/object:Gem::Dependency
|
230
|
+
name: simplecov-lcov
|
223
231
|
requirement: !ruby/object:Gem::Requirement
|
224
232
|
requirements:
|
225
233
|
- - ">="
|
@@ -249,16 +257,18 @@ dependencies:
|
|
249
257
|
description: Interact with REST services in an ActiveRecord-like manner
|
250
258
|
email:
|
251
259
|
- jens@balvig.com
|
252
|
-
executables:
|
260
|
+
executables:
|
261
|
+
- console
|
253
262
|
extensions: []
|
254
263
|
extra_rdoc_files: []
|
255
264
|
files:
|
265
|
+
- ".circleci/config.yml"
|
256
266
|
- ".gitignore"
|
257
|
-
- ".travis.yml"
|
258
267
|
- Gemfile
|
259
268
|
- LICENSE.txt
|
260
269
|
- README.md
|
261
270
|
- Rakefile
|
271
|
+
- bin/console
|
262
272
|
- lib/spyke.rb
|
263
273
|
- lib/spyke/associations.rb
|
264
274
|
- lib/spyke/associations/association.rb
|
@@ -286,6 +296,7 @@ files:
|
|
286
296
|
- lib/spyke/scoping.rb
|
287
297
|
- lib/spyke/version.rb
|
288
298
|
- spyke.gemspec
|
299
|
+
- spyke.svg
|
289
300
|
- test/activemodel_dirty_test.rb
|
290
301
|
- test/associations_test.rb
|
291
302
|
- test/attributes_test.rb
|
@@ -295,6 +306,7 @@ files:
|
|
295
306
|
- test/fallbacks_test.rb
|
296
307
|
- test/orm_test.rb
|
297
308
|
- test/path_test.rb
|
309
|
+
- test/scope_registry_test.rb
|
298
310
|
- test/scopes_test.rb
|
299
311
|
- test/support/fixtures.rb
|
300
312
|
- test/support/webmock.rb
|
@@ -332,6 +344,7 @@ test_files:
|
|
332
344
|
- test/fallbacks_test.rb
|
333
345
|
- test/orm_test.rb
|
334
346
|
- test/path_test.rb
|
347
|
+
- test/scope_registry_test.rb
|
335
348
|
- test/scopes_test.rb
|
336
349
|
- test/support/fixtures.rb
|
337
350
|
- test/support/webmock.rb
|