azeroth 0.6.4 → 0.6.5

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
  SHA256:
3
- metadata.gz: ac2c03e9a7b51ed50db9ecab43a4f7257d98839126f79a45cc6b3563efd7b296
4
- data.tar.gz: 95d18220fae24c2f049cf186fe25a0d5cdc94bada48ccd9ce02b867c5334f3ce
3
+ metadata.gz: 8e28a5c409533eebedc8579f02941b55a956b8296459243b8cf5572857f64d1c
4
+ data.tar.gz: ba50b329165868a7b2a65b4762a20c91898c45593bedc528e440d6d51b9fae01
5
5
  SHA512:
6
- metadata.gz: 8dd092347ebebde2ccdaad5b2c165a8a595a2f8f2a6fc463303566f1b3812d84b22a0295f75ce9dbf696c752ad045691953696166705e0294f94ae3450b0f3e7
7
- data.tar.gz: 4a406a9e2d4609034cab48bd8aff6ead1c644f3535d3cacd6e18523881572dde035afccbc4279ee96f9a110a0b078897641ebcfc5008a93cf47b7b4ce89bd746
6
+ metadata.gz: 38ca1d96bf67471f7eb0bdd1c626832e534c9418646d09d2381659096c1739a8d06b592a8c4063e1068f4e2fa8502bc9fcc25f2a9e6c998c659459eea837325c
7
+ data.tar.gz: 9cb5e259c5f9961d60d6ae8c50563ada7d45ab2a850f2cf79dfd8977d5b30b53ea9e029617466d19a237c2256db3c6491fe9a674cb463ad074e76b78693852ee
data/README.md CHANGED
@@ -11,7 +11,7 @@ Azeroth
11
11
 
12
12
  Yard Documentation
13
13
  -------------------
14
- [https://www.rubydoc.info/gems/azeroth/0.6.4](https://www.rubydoc.info/gems/azeroth/0.6.4)
14
+ [https://www.rubydoc.info/gems/azeroth/0.6.5](https://www.rubydoc.info/gems/azeroth/0.6.5)
15
15
 
16
16
  Azeroth has been designed making the coding of controllers easier
17
17
  as routes in controllers are usually copy, paste and replace of same
@@ -36,9 +36,9 @@ which adds a resource and action methods for `create`, `show`, `index`,
36
36
  `update`, `delete`, `edit`
37
37
 
38
38
  It accepts options
39
- -only List of actions to be built
40
- -except List of actions to not to be built
41
- -decorator Decorator class or flag allowing/disallowing decorators
39
+ - only List of actions to be built
40
+ - except List of actions to not to be built
41
+ - decorator Decorator class or flag allowing/disallowing decorators
42
42
 
43
43
  ```ruby
44
44
  # publishers_controller.rb
@@ -121,6 +121,6 @@ Exposing is done through the class method
121
121
  [expose](https://www.rubydoc.info/gems/azeroth/Azeroth/Decorator#expose-class_method)
122
122
  which accepts several options:
123
123
 
124
- -as: custom key to expose
125
- -if: method/block to be called checking if an attribute should or should not be exposed
126
- -decorator: flag to use or not a decorator or decorator class to be used
124
+ - as: custom key to expose
125
+ - if: method/block to be called checking if an attribute should or should not be exposed
126
+ - decorator: flag to use or not a decorator or decorator class to be used
@@ -257,6 +257,8 @@ module Azeroth
257
257
  #
258
258
  # @return [Hash]
259
259
  def as_json(*args)
260
+ return nil if object.nil?
261
+
260
262
  return array_as_json(*args) if enum?
261
263
 
262
264
  HashBuilder.new(self).as_json
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Azeroth
4
- VERSION = '0.6.4'
4
+ VERSION = '0.6.5'
5
5
  end
@@ -227,5 +227,37 @@ describe Azeroth::Decorator::KeyValueExtractor do
227
227
  end
228
228
  end
229
229
  end
230
+
231
+ context 'when value is nil' do
232
+ context 'without decorator options' do
233
+ let(:object) { build(:document, name: nil) }
234
+
235
+ it 'returns nil for value' do
236
+ expect(extractor.as_json)
237
+ .to eq({ 'name' => nil })
238
+ end
239
+ end
240
+
241
+ context 'with decorator false' do
242
+ let(:object) { build(:document, name: nil) }
243
+ let(:options_hash) { { decorator: false } }
244
+
245
+ it 'returns nil for value' do
246
+ expect(extractor.as_json)
247
+ .to eq({ 'name' => nil })
248
+ end
249
+ end
250
+
251
+ context 'with decorator option' do
252
+ let(:object) { create(:pokemon_master) }
253
+ let(:options_hash) { { decorator: Pokemon::Decorator } }
254
+ let(:attribute) { :favorite_pokemon }
255
+
256
+ it 'returns nil for value' do
257
+ expect(extractor.as_json)
258
+ .to eq({ 'favorite_pokemon' => nil })
259
+ end
260
+ end
261
+ end
230
262
  end
231
263
  end
@@ -62,6 +62,12 @@ describe Azeroth::Decorator do
62
62
  end
63
63
 
64
64
  describe '#as_json' do
65
+ context 'when object is nil' do
66
+ let(:object) { nil }
67
+
68
+ it { expect(decorator.as_json).to be_nil }
69
+ end
70
+
65
71
  context 'when object is just a model' do
66
72
  let(:expected_json) do
67
73
  {
@@ -166,7 +172,7 @@ describe Azeroth::Decorator do
166
172
  end
167
173
  end
168
174
 
169
- context 'with decotator for model with validation' do
175
+ context 'with decorator for model with validation' do
170
176
  subject(:decorator) do
171
177
  Document::DecoratorWithError.new(object)
172
178
  end
@@ -255,6 +261,26 @@ describe Azeroth::Decorator do
255
261
  expect(decorator.as_json).to eq(expected_json)
256
262
  end
257
263
  end
264
+
265
+ context 'with nil value and defined decorator' do
266
+ subject(:decorator) do
267
+ Factory::DecoratorWithProduct.new(factory)
268
+ end
269
+
270
+ let(:factory) { create(:factory) }
271
+
272
+ let(:expected_json) do
273
+ {
274
+ name: factory.name,
275
+ main_product: nil,
276
+ products: []
277
+ }.deep_stringify_keys
278
+ end
279
+
280
+ it 'exposes relation' do
281
+ expect(decorator.as_json).to eq(expected_json)
282
+ end
283
+ end
258
284
  end
259
285
  end
260
286
 
@@ -262,7 +288,7 @@ describe Azeroth::Decorator do
262
288
  subject(:decorator) { decorator_class.new(object) }
263
289
 
264
290
  let(:decorator_class) { Class.new(described_class) }
265
- let(:model) { build(:dummy_model) }
291
+ let(:model) { build(:dummy_model) }
266
292
 
267
293
  it 'delegates methods to object' do
268
294
  expect(decorator.first_name).not_to be_nil
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :pokemon_master, class: '::PokemonMaster' do
5
+ sequence(:first_name) { |n| "Ash-#{n}" }
6
+ sequence(:last_name) { |n| "Ketchum-#{n}" }
7
+ age { 10 }
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azeroth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -560,6 +560,7 @@ files:
560
560
  - spec/support/factories/dummy_model.rb
561
561
  - spec/support/factories/factory.rb
562
562
  - spec/support/factories/game.rb
563
+ - spec/support/factories/pokemon_master.rb
563
564
  - spec/support/factories/product.rb
564
565
  - spec/support/factories/publisher.rb
565
566
  - spec/support/factories/user.rb
@@ -715,6 +716,7 @@ test_files:
715
716
  - spec/support/factories/dummy_model.rb
716
717
  - spec/support/factories/factory.rb
717
718
  - spec/support/factories/game.rb
719
+ - spec/support/factories/pokemon_master.rb
718
720
  - spec/support/factories/product.rb
719
721
  - spec/support/factories/publisher.rb
720
722
  - spec/support/factories/user.rb