spec/acfs/global_spec.rb in acfs-1.0.0.dev.1.b305 vs spec/acfs/global_spec.rb in acfs-1.0.0

- old
+ new

@@ -12,15 +12,15 @@ describe ::Acfs::Global do let(:adapter) { ::NullAdapter.new } let(:runner) { double 'runner' } let(:collector) { NotificationCollector.new } - let(:acfs) { Object.new.tap { |o| o.extend ::Acfs::Global } } + let(:acfs) { Object.new.tap {|o| o.extend ::Acfs::Global } } describe 'instrumentation' do before do - #allow(runner).to receive(:start) + # allow(runner).to receive(:start) allow(acfs).to receive(:runner).and_return runner end describe '#run' do before do @@ -46,11 +46,11 @@ describe '#on' do before do stub_request(:get, %r{http://users.example.org/users/\d+}).to_return( status: 200, body: '{}', - headers: { 'Content-Type' => 'application/json' }) + headers: {'Content-Type' => 'application/json'}) end it 'should invoke when both resources' do user1 = MyUser.find 1 user2 = MyUser.find 2 @@ -68,8 +68,26 @@ Acfs.on(user1, user2) do |u1, u2| expect(u1).to be_loaded expect(u2).to be_loaded end Acfs.run + end + end + + describe '#runner' do + it 'returns per-thread runner' do + runner1 = Thread.new { acfs.runner } .value + runner2 = Thread.new { acfs.runner } .value + + expect(runner1).to_not equal runner2 + end + + it 'uses configurated adapter' do + adapter = double :adapter + expect(Acfs::Configuration.current).to receive(:adapter).and_return(-> { adapter }) + + runner = Thread.new { acfs.runner }.value + + expect(runner.adapter).to equal adapter end end end