I'm writing a pretty straightforward test for a model scope:
describe "scope tests" do
let(:account1) { create(:account, last_seen: Date.today)}
let(:account2) { create(:account, last_seen: Date.today - 4.days)}
let(:account3) { create(:account, last_seen: Date.today - 10.days)}
let(:d) { Date.today}
let(:seen_between) { Account.seen_between(d - 14.days, d - 2.days) }
it "response to seen_between" do
expect(seen_between).to eq([account3, account2])
expect(seen_between).to_not include(account1)
end
end
But I'm getting some very verbose error:
Failure/Error: expect(Account.all).to eq([account3, account2])
expected: [#<Account id: 2, date_of_birth: nil, description: nil, active: true, created_at: "2018-05-10 12:05:4..._lead_id: nil, account_category_id: nil, psychiatrisch: nil, oggz: nil, problem: nil, actions: nil>]
got: #<ActiveRecord::Relation [#<Account id: 3, date_of_birth: nil, description: nil, active: true, create...lead_id: nil, account_category_id: nil, psychiatrisch: nil, oggz: nil, problem: nil, actions: nil>]>
Also, when I change the order of the assertion to [account2, account3] it still doesn't work. What is the correct way to make this test past (assuming that the scope does indeed returns the correct records, which it already does)
I also tried using inlcudes(), which of course works, but doesn't check for the correct order of records.
Thanks