acfs 1.3.1 → 1.3.2

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: '099f37ed68e218d04f91c2f9f636e7b177b84feb8b8e0be4c4403da004937760'
4
- data.tar.gz: bfbf0d3dc7f77eb38f16043051350a468baab870b3b002c35bc9f96df492eb07
3
+ metadata.gz: 9e970f81dff63a351279207100701f7a9be822272a77e5dfc3bd39d9e418a0db
4
+ data.tar.gz: 81b752674659595a097b951334bb41fa36f9a96de2f3b7ff0a1a82d3e03f0009
5
5
  SHA512:
6
- metadata.gz: 29c45b69c95afd11cb58af0e02a383a2c1adcfeefb2521a917e1b7f6606a694c66fa0e2d56796e59127d453f4a1f95ab36c6a2e9a384657992b6a821c946c357
7
- data.tar.gz: cba2e6df7a7988d2d06fc8ca303aa63875736c6d0fc6c0013ecbb36038b559bcfc085058c086468389905947aba375d6add11f3e8010ab2cff1b70628edd8770
6
+ metadata.gz: 4d8363f66d917672285318eaf1f68f03c3ef28c560373b4e74054f5d5d4da7dd0a443f6b54c9835fafbd290921e2d8316195a3c015970e539baa37fb8bead339
7
+ data.tar.gz: 73d009dc5601ba4e4cc06efb41a0990a58779726b86ebf4905c2967dba55de406085b83e9a7c3de71b860e748bae1ff39b2a59de91a2699c488ced2d689d9234
@@ -14,9 +14,17 @@
14
14
  ### Breaks
15
15
 
16
16
 
17
- ## 1.3.1 - (2019-07-02)
17
+ ## 1.3.2 - (2019-09-24)
18
+
19
+
20
+ ### Fixes
21
+ * Fix Acfs.on callbacks for empty find_by results (#42)
22
+
23
+
18
24
  ---
19
25
 
26
+ ## 1.3.1 - (2019-07-02)
27
+
20
28
  ### Fixes
21
29
  * Improve URL argument encoding when building resource requests
22
30
 
data/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/acfs.svg)](http://badge.fury.io/rb/acfs)
4
4
  [![Build Status](http://img.shields.io/travis/jgraichen/acfs/master.svg)](https://travis-ci.org/jgraichen/acfs)
5
5
  [![Coverage Status](http://img.shields.io/coveralls/jgraichen/acfs/master.svg)](https://coveralls.io/r/jgraichen/acfs)
6
- [![Code Climate](http://img.shields.io/codeclimate/github/jgraichen/acfs.svg)](https://codeclimate.com/github/jgraichen/acfs)
7
- [![Dependency Status](http://img.shields.io/gemnasium/jgraichen/acfs.svg)](https://gemnasium.com/jgraichen/acfs)
8
6
  [![RubyDoc Documentation](http://img.shields.io/badge/rubydoc-here-blue.svg)](http://rubydoc.info/github/jgraichen/acfs/master/frames)
9
7
 
10
8
  Acfs is a library to develop API client libraries for single services within a larger service oriented application.
@@ -73,7 +73,7 @@ module Acfs
73
73
  end
74
74
  return false if block.nil?
75
75
 
76
- if resource.loaded?
76
+ if resource.nil? || resource.loaded?
77
77
  block.call resource
78
78
  else
79
79
  resource.__callbacks__ << block
@@ -81,9 +81,17 @@ module Acfs
81
81
  end
82
82
 
83
83
  def on(*resources)
84
+ # If all resources have already been loaded, we run the callback immediately.
85
+ if resources.all? {|res| res.nil? || res.loaded? }
86
+ yield(*resources)
87
+ return
88
+ end
89
+
90
+ # Otherwise, we add a callback to *each* resource with a guard that ensures
91
+ # that only the very last resource being loaded executes the callback.
84
92
  resources.each do |resource|
85
93
  add_callback resource do |_|
86
- yield(*resources) unless resources.any? {|res| !res.loaded? }
94
+ yield(*resources) if resources.all? {|res| res.nil? || res.loaded? }
87
95
  end
88
96
  end
89
97
  end
@@ -2,7 +2,7 @@ module Acfs
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STAGE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
@@ -71,6 +71,50 @@ describe ::Acfs::Global do
71
71
  end
72
72
  Acfs.run
73
73
  end
74
+
75
+ context 'with an empty result for a find_by call' do
76
+ before do
77
+ stub_request(:get, %r{http://users.example.org/users})
78
+ .with(query: {id: '2'})
79
+ .to_return(
80
+ status: 200,
81
+ body: '{}',
82
+ headers: {'Content-Type' => 'application/json'}
83
+ )
84
+ end
85
+
86
+ it 'invokes once both requests are finished' do
87
+ user1 = MyUser.find 1
88
+ user2 = MyUser.find_by id: 2
89
+
90
+ expect do |cb|
91
+ Acfs.on(user1, user2, &cb)
92
+ Acfs.run
93
+ end.to yield_with_args(user1, be_nil)
94
+ end
95
+
96
+ it 'invokes once remaining requests are finished' do
97
+ user1 = MyUser.find 1
98
+ Acfs.run # Finish the first request
99
+
100
+ user2 = MyUser.find_by id: 2
101
+
102
+ expect do |cb|
103
+ Acfs.on(user1, user2, &cb)
104
+ Acfs.run
105
+ end.to yield_with_args(user1, be_nil)
106
+ end
107
+
108
+ it 'invokes immediately when all requests have already been finished' do
109
+ user1 = MyUser.find 1
110
+ user2 = MyUser.find_by id: 2
111
+ Acfs.run
112
+
113
+ expect do |cb|
114
+ Acfs.on(user1, user2, &cb)
115
+ end.to yield_with_args(user1, be_nil)
116
+ end
117
+ end
74
118
  end
75
119
 
76
120
  describe '#runner' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-02 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -228,8 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubyforge_project:
232
- rubygems_version: 2.7.7
231
+ rubygems_version: 3.0.6
233
232
  signing_key:
234
233
  specification_version: 4
235
234
  summary: An abstract API base client for service oriented application.