Sha256: 1c00ae27eaa2ca63e3d79c349362a653e98b63552b153205140204794ab54f46

Contents?: true

Size: 681 Bytes

Versions: 4

Compression:

Stored size: 681 Bytes

Contents

# frozen_string_literal: true

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

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

  it "adds randomness to existing order" do
    expect(Thing.order(:word).to_sql).to end_with('ORDER BY "things"."word" ASC, RANDOM()')
  end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unreliable-0.1.3 spec/model_select_spec.rb
unreliable-0.1.2 spec/model_select_spec.rb
unreliable-0.1.1 spec/model_select_spec.rb
unreliable-0.1.0 spec/model_select_spec.rb