Last Updated: March 14, 2018
·
3.4K
· mecampbellsoup

Testing Rails model`default_scope` with RSpec

class Trip < ActiveRecord::Base
  default_scope { order(departure: :asc) }
  ...
end
RSpec.describe Trip, type: :model do
  it "applies a default scope to collections by departure ascending" do
    expect(Trip.all.to_sql).to eq Trip.all.order(departure: :asc).to_sql
  end
end