spyke 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9124e2e536f848aee4a144556f24e0ccad5515e5
4
- data.tar.gz: c1f33a42164811126c79b044b54265de252ddade
3
+ metadata.gz: 00c19525c5f1a175a8bb69815c18493d61a0ae9c
4
+ data.tar.gz: f3b903bd7a4ae21e974fe3a1a77e75adff7c104a
5
5
  SHA512:
6
- metadata.gz: 7f34c8c2f7b875e742ea9ed51b28d2518af3f62561978683374ea7956082403bd980b54aa176adb6dbb43b97c11c3e23599120d49b540ea9096395ad70c545b9
7
- data.tar.gz: b087f095780cbd94b6d7a620eb8ef87a589978837130dd9d3471292ea65285f8609996ff199885a67d44ceda15fc9c2070b3679efcb6505921bcca580fdf4942
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 embedded
48
- Result.new(data: embedded)
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 embedded
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] = parent.try(foreign_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
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '5.2.0'
2
+ VERSION = '5.3.0'
3
3
  end
@@ -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.2.0
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: 2017-12-26 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport