spec/acfs/global_spec.rb in acfs-1.3.1 vs spec/acfs/global_spec.rb in acfs-1.3.2
- old
+ new
@@ -69,9 +69,53 @@
expect(u1).to be_loaded
expect(u2).to be_loaded
end
Acfs.run
end
+
+ context 'with an empty result for a find_by call' do
+ before do
+ stub_request(:get, %r{http://users.example.org/users})
+ .with(query: {id: '2'})
+ .to_return(
+ status: 200,
+ body: '{}',
+ headers: {'Content-Type' => 'application/json'}
+ )
+ end
+
+ it 'invokes once both requests are finished' do
+ user1 = MyUser.find 1
+ user2 = MyUser.find_by id: 2
+
+ expect do |cb|
+ Acfs.on(user1, user2, &cb)
+ Acfs.run
+ end.to yield_with_args(user1, be_nil)
+ end
+
+ it 'invokes once remaining requests are finished' do
+ user1 = MyUser.find 1
+ Acfs.run # Finish the first request
+
+ user2 = MyUser.find_by id: 2
+
+ expect do |cb|
+ Acfs.on(user1, user2, &cb)
+ Acfs.run
+ end.to yield_with_args(user1, be_nil)
+ end
+
+ it 'invokes immediately when all requests have already been finished' do
+ user1 = MyUser.find 1
+ user2 = MyUser.find_by id: 2
+ Acfs.run
+
+ expect do |cb|
+ Acfs.on(user1, user2, &cb)
+ end.to yield_with_args(user1, be_nil)
+ end
+ end
end
describe '#runner' do
it 'returns per-thread runner' do
runner1 = Thread.new { acfs.runner } .value