Sha256: 97efec24fe045470d89dd728698113cc3cb27f54991f29502e1a1df0eefb3b0b

Contents?: true

Size: 665 Bytes

Versions: 2

Compression:

Stored size: 665 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Cat do
  it "randomly selects from all" do
    expect(Cat.all.to_sql).to end_with("ORDER BY RANDOM()")
  end

  it "randomly selects from some" do
    expect(Cat.where(name: "foo").to_sql).to end_with("ORDER BY RANDOM()")
  end

  it "adds randomness to existing order" do
    expect(Cat.order(:name).to_sql).to end_with('ORDER BY "cats"."name" ASC, RANDOM()')
  end

  it "respects a disable block" do
    Unreliable::Config.disable do
      expect(Cat.where(name: "foo").to_sql).to_not end_with("ORDER BY RANDOM()")
      expect(Cat.where(name: "foo").to_sql).to end_with(%q("cats"."name" = 'foo'))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unreliable-0.9.1 spec/model_select_spec.rb
unreliable-0.9.0 spec/model_select_spec.rb