oat 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oat/adapters/json_api.rb +2 -1
- data/lib/oat/version.rb +1 -1
- data/spec/adapters/json_api_spec.rb +28 -3
- 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: 7d444b3c170713aa0e2ff5c54fec3d55303560de
|
4
|
+
data.tar.gz: 2b0619de2dc37f28043a0d641f96fbc428145cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5622ecddbad73ddbf6c390fcca1ac44cdd282ab1efc69bac16ea6962b7eea76008461a47eefc549962fb99f1346b928f7622f6e9e9f3d269e420bc23e5bdb6e7
|
7
|
+
data.tar.gz: 8f63e0662b6526536d79c4a07d2aadcb0c91b7ca90b25aa183a92c9b5b566d79b6a18c98807e5b816173ccd431f9cb1c9aae6dac7a99b0952e2396e7d412bb94
|
@@ -34,14 +34,15 @@ module Oat
|
|
34
34
|
|
35
35
|
def entity(name, obj, serializer_class = nil, context_options = {}, &block)
|
36
36
|
ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
|
37
|
-
entity_hash[name.to_s.pluralize.to_sym] ||= []
|
38
37
|
if ent
|
38
|
+
entity_hash[name.to_s.pluralize.to_sym] ||= []
|
39
39
|
link name, :href => ent[:id]
|
40
40
|
entity_hash[name.to_s.pluralize.to_sym] << ent
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def entities(name, collection, serializer_class = nil, context_options = {}, &block)
|
45
|
+
return if collection.nil? || collection.empty?
|
45
46
|
link_name = name.to_s.pluralize.to_sym
|
46
47
|
data[:links][link_name] = []
|
47
48
|
|
data/lib/oat/version.rb
CHANGED
@@ -52,8 +52,7 @@ describe Oat::Adapters::JsonAPI do
|
|
52
52
|
it 'contains the correct links' do
|
53
53
|
expect(linked_friends.first.fetch(:links)).to include(
|
54
54
|
:self => "http://foo.bar.com/#{friend.id}",
|
55
|
-
:empty => nil
|
56
|
-
:friends => []
|
55
|
+
:empty => nil
|
57
56
|
)
|
58
57
|
end
|
59
58
|
end
|
@@ -94,7 +93,33 @@ describe Oat::Adapters::JsonAPI do
|
|
94
93
|
end
|
95
94
|
|
96
95
|
it 'excludes the entity from the linked hash' do
|
97
|
-
hash.fetch(:linked).
|
96
|
+
expect(hash.fetch(:linked)).not_to include(:managers)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with a nil entities relationship' do
|
101
|
+
let(:user) { user_class.new('Ismael', 35, 1, nil, manager) }
|
102
|
+
let(:users) { hash.fetch(:users) }
|
103
|
+
|
104
|
+
it 'excludes the entity from user links' do
|
105
|
+
expect(users.first.fetch(:links)).not_to include(:friends)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'excludes the entity from the linked hash' do
|
109
|
+
expect(hash.fetch(:linked)).not_to include(:friends)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when an empty entities relationship' do
|
114
|
+
let(:user) { user_class.new('Ismael', 35, 1, [], manager) }
|
115
|
+
let(:users) { hash.fetch(:users) }
|
116
|
+
|
117
|
+
it 'excludes the entity from user links' do
|
118
|
+
expect(users.first.fetch(:links)).not_to include(:friends)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'excludes the entity from the linked hash' do
|
122
|
+
expect(hash.fetch(:linked)).not_to include(:friends)
|
98
123
|
end
|
99
124
|
end
|
100
125
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|