spyke 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/spyke/associations/association.rb +3 -3
- data/lib/spyke/associations/belongs_to.rb +16 -1
- data/lib/spyke/version.rb +1 -1
- data/test/associations_test.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c19525c5f1a175a8bb69815c18493d61a0ae9c
|
4
|
+
data.tar.gz: f3b903bd7a4ae21e974fe3a1a77e75adff7c104a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23693dddb0c0b1f7f5afc44b7015de2eb4e1fbd28ae847685690ddf0f5c957a1f0cee01e63566827f987ee95d84aab6ea1b9019145f98ba3aaa397a53fbe899b
|
7
|
+
data.tar.gz: 10d722d8f55f915520a2c95a42e9545afe712599a6a8c8859674ded1f7548582f759eee2f285a18882aaa691aeda55b2eb7f0d9ee4cacbae4f9a4c667442a92f
|
@@ -44,14 +44,14 @@ module Spyke
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def fetch_embedded
|
47
|
-
if
|
48
|
-
Result.new(data:
|
47
|
+
if embedded_data
|
48
|
+
Result.new(data: embedded_data)
|
49
49
|
elsif !uri
|
50
50
|
Result.new(data: nil)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
54
|
+
def embedded_data
|
55
55
|
parent.attributes[name]
|
56
56
|
end
|
57
57
|
|
@@ -4,8 +4,23 @@ module Spyke
|
|
4
4
|
def initialize(*args)
|
5
5
|
super
|
6
6
|
@options.reverse_merge!(uri: "#{@name.to_s.pluralize}/:#{primary_key}", foreign_key: "#{klass.model_name.element}_id")
|
7
|
-
@params[primary_key] =
|
7
|
+
@params[primary_key] = primary_key_value
|
8
8
|
end
|
9
|
+
|
10
|
+
def find_one
|
11
|
+
return unless fetchable?
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def fetchable?
|
18
|
+
(primary_key_value || embedded_data).present?
|
19
|
+
end
|
20
|
+
|
21
|
+
def primary_key_value
|
22
|
+
parent.try(foreign_key)
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
data/lib/spyke/version.rb
CHANGED
data/test/associations_test.rb
CHANGED
@@ -438,6 +438,11 @@ module Spyke
|
|
438
438
|
assert_requested user_endpoint
|
439
439
|
end
|
440
440
|
|
441
|
+
def test_return_nil_for_missing_id_for_belongs_to
|
442
|
+
recipe = Recipe.new(id: 1, user_id: nil)
|
443
|
+
assert_nil recipe.user
|
444
|
+
end
|
445
|
+
|
441
446
|
def test_custom_primary_key_for_has_many
|
442
447
|
stub_request(:get, 'http://sushi.com/comments/1').to_return_json(result: { users: [{ id: 1 }] })
|
443
448
|
comment = Comment.find(1)
|
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: 5.
|
4
|
+
version: 5.3.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: 2018-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|