oat 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fc6d823ab477ce6ea91958585093f23afb9d0d2
4
- data.tar.gz: 84bf255fd575dd07ad62d6e942c8948ec44b20f0
3
+ metadata.gz: 7d444b3c170713aa0e2ff5c54fec3d55303560de
4
+ data.tar.gz: 2b0619de2dc37f28043a0d641f96fbc428145cc1
5
5
  SHA512:
6
- metadata.gz: 4ac3ea124a6cc06fcd3e21130e0ad99af95a59e92c113f8596298a093cc3bc34c879efb36a815ac0b388a77e231beecc8de8306bb2f12722d64c5bd7d17e7286
7
- data.tar.gz: cf27b4fd9ca4dcb4d6b7e6d335d5d1055ee643b4f1a6e94d808724cbfa15d50d0120cba18b34e23cc1332df1bd259957920bdda06290ac1dcb70e3e5fb383c58
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
@@ -1,3 +1,3 @@
1
1
  module Oat
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -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).fetch(:managers).should be_empty
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
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-02-24 00:00:00.000000000 Z
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport