Sha256: 8813a83a193937edf3532c8276beb99d6039f01f714a47ac378f170c15e99dd1

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

RSpec.describe ROM::SQL::Relation, '#instrument', :sqlite do
  include_context 'users and tasks'

  subject(:relation) do
    relations[:users]
  end

  let(:notifications) do
    spy(:notifications)
  end

  before do
    conf.plugin(:sql, relations: :instrumentation) do |p|
      p.notifications = notifications
    end
  end

  it 'instruments relation materialization' do
    users.to_a

    expect(notifications).
      to have_received(:instrument).with(:sql, name: :users, query: users.dataset.sql)
  end

  it 'instruments methods that return a single tuple' do
    users.first

    expect(notifications).
      to have_received(:instrument).with(:sql, name: :users, query: users.limit(1).dataset.sql)

    users.last

    expect(notifications).
      to have_received(:instrument).with(:sql, name: :users, query: users.reverse.limit(1).dataset.sql)
  end

  it 'instruments aggregation methods' do
    pending "no idea how to make this work with sequel"

    users.count

    expect(notifications).
      to have_received(:instrument).with(:sql, name: :users, query: 'SELECT COUNT(*) FROM users')
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rom-sql-1.3.5 spec/unit/relation/instrument_spec.rb
rom-sql-1.3.4 spec/unit/relation/instrument_spec.rb
rom-sql-2.0.0.beta2 spec/unit/relation/instrument_spec.rb
rom-sql-2.0.0.beta1 spec/unit/relation/instrument_spec.rb
rom-sql-1.3.3 spec/unit/relation/instrument_spec.rb
rom-sql-1.3.2 spec/unit/relation/instrument_spec.rb
rom-sql-1.3.1 spec/unit/relation/instrument_spec.rb
rom-sql-1.3.0 spec/unit/relation/instrument_spec.rb
rom-sql-1.2.2 spec/unit/relation/instrument_spec.rb
rom-sql-1.2.1 spec/unit/relation/instrument_spec.rb
rom-sql-1.2.0 spec/unit/relation/instrument_spec.rb
rom-sql-1.1.2 spec/unit/relation/instrument_spec.rb
rom-sql-1.1.1 spec/unit/relation/instrument_spec.rb
rom-sql-1.1.0 spec/unit/relation/instrument_spec.rb