Sha256: a6415b9ac538c05e340ce2ee245ba6c36aa476eddecb6d708fff1df796a0ce12

Contents?: true

Size: 1.71 KB

Versions: 14

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

class NotificationCollector
  def call(*args)
    events << ActiveSupport::Notifications::Event.new(*args)
  end

  def events
    @events ||= []
  end
end

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 } }

  describe 'instrumentation' do
    before do
      #allow(runner).to receive(:start)
      allow(acfs).to receive(:runner).and_return runner
    end

    describe '#run' do
      before do
        ::ActiveSupport::Notifications.subscribe 'acfs.run', collector
      end
      it 'should trigger event' do
        Acfs.run
        expect(collector.events).to have(1).items
      end
    end

    describe '#reset' do
      before do
        ::ActiveSupport::Notifications.subscribe 'acfs.reset', collector
      end
      it 'should trigger event' do
        Acfs.reset
        expect(collector.events).to have(1).items
      end
    end
  end

  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' })
    end

    it 'should invoke when both resources' do
      user1 = MyUser.find 1
      user2 = MyUser.find 2

      expect do |cb|
        Acfs.on(user1, user2, &cb)
        Acfs.run
      end.to yield_with_args(user1, user2)
    end

    it 'should invoke when both resources when loaded' do
      user1 = MyUser.find 1
      user2 = MyUser.find 2

      Acfs.on(user1, user2) do |u1, u2|
        expect(u1).to be_loaded
        expect(u2).to be_loaded
      end
      Acfs.run
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
acfs-0.42.0 spec/acfs/global_spec.rb
acfs-0.41.1 spec/acfs/global_spec.rb
acfs-0.41.1.beta1 spec/acfs/global_spec.rb
acfs-0.41.0 spec/acfs/global_spec.rb
acfs-0.40.1.rc1 spec/acfs/global_spec.rb
acfs-0.40.0 spec/acfs/global_spec.rb
acfs-0.39.1 spec/acfs/global_spec.rb
acfs-0.39.0 spec/acfs/global_spec.rb
acfs-1.0.0.dev.1.b305 spec/acfs/global_spec.rb
acfs-0.38.0 spec/acfs/global_spec.rb
acfs-1.0.0.dev.1.b298 spec/acfs/global_spec.rb
acfs-1.0.0.dev.1.b297 spec/acfs/global_spec.rb
acfs-0.37.0.1.b295 spec/acfs/global_spec.rb
acfs-0.37.0 spec/acfs/global_spec.rb