File: relation_match_array_spec.rb

package info (click to toggle)
ruby-rspec-rails 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,796 kB
  • sloc: ruby: 11,068; sh: 198; makefile: 6
file content (18 lines) | stat: -rw-r--r-- 686 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
RSpec.describe "ActiveSupport::Relation match_array matcher" do
  before { MockableModel.delete_all }

  let!(:models) { Array.new(3) { MockableModel.create } }

  it "verifies that the scope returns the records on the right hand side, regardless of order" do
    expect(MockableModel.all).to match_array(models.reverse)
  end

  it "fails if the scope encompasses more records than on the right hand side" do
    MockableModel.create
    expect(MockableModel.all).not_to match_array(models.reverse)
  end

  it "fails if the scope encompasses fewer records than on the right hand side" do
    expect(MockableModel.limit(models.length - 1)).not_to match_array(models.reverse)
  end
end