Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Rails 5 rspec - convert object to ActiveRecord Relation

I have method that use .ids for ActiveRecord array. Something like that:

def exmpale(array)
  method2(array.ids)
end

Now I want to create tests for this method, but when I create objects by FactoryBot I dont get ActiveRecord array. For example:

let(:array) { FactoryBot.create(:class_example) }

I can use ClassExample.where to get have ActiveRecord Relation, but Im not sure it's good idea. Is there any other soultion without changing method?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The simple way to do it is to use create_list and return an ActiveRecord relation, but if I were you I'd rethink it to use stubs.

let(:array) do
  list = create_list(:class_example, 4)
  ClassExample.where(id: list.map(&:id))
end
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!