Sha256: ee2fac25d31b11a611bc20d43c4d040b0456ffca6f870d3b4d48e8c0d07bf1c7

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

shared_examples 'a query method with multi-callback support' do
  let(:cb) { Proc.new }

  it 'should invoke callback' do
    expect do |cb|
      action.call cb
      Acfs.run
    end.to yield_with_args
  end

  it 'should invoke multiple callbacks' do
    expect do |cb|
      object = action.call cb
      Acfs.add_callback object, &cb
      Acfs.run
    end.to yield_control.exactly(2).times
  end

  describe 'callback' do
    it 'should be invoked with resource' do
      proc = proc {}
      expect(proc).to receive(:call) do |res|
        expect(res).to equal @object
        expect(res).to be_loaded
      end

      @object = action.call proc
      Acfs.run
    end

    it 'should invoke multiple callback with loaded resource' do
      proc1 = proc {}
      proc2 = proc {}
      expect(proc1).to receive(:call) do |user|
        expect(user).to equal @object
        expect(user).to be_loaded
      end
      expect(proc2).to receive(:call) do |user|
        expect(user).to equal @object
        expect(user).to be_loaded
      end

      @object = action.call proc1
      Acfs.add_callback(@object, &proc2)
      Acfs.run
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acfs-1.6.0 spec/support/shared/find_callbacks.rb
acfs-1.5.1 spec/support/shared/find_callbacks.rb
acfs-1.5.0 spec/support/shared/find_callbacks.rb
acfs-1.4.0 spec/support/shared/find_callbacks.rb
acfs-1.3.4 spec/support/shared/find_callbacks.rb