Retrieving specific fixtures in Rails
-
20-09-2019 - |
Question
I have a YML file containing fixtures for a Rails model (Comment) which looks like this (pardon the formatting):
comment_a: id: 1 text: 'foo' visible: false
comment_b: id: 2 text: 'bar' visible: true
comment_c: id: 3 text: 'baz' visible: true
I know that I can select an individual Comment fixture like so:
comments(:comment_a)
In one of my acceptance tests, I want to find all the Comments which have visible = true. How do I select a set of Comments that meet certain criteria so I can iterate over them afterwards?
Solution
You need made the request by your ActiveRecord Object. Comments.all(:conditions => {:visible => true})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow