Testing ActiveRecord Finders

Learn about testing ActiveRecord finders, duplication finders, performance finders, readability finders, error finders, and compound matchers.

ActiveRecord finders

ActiveRecord provides a rich set of methods that are wrappers around SQL statements sent to our database. These methods are collectively referred to as finders. One great feature of ActiveRecord finders is that they can be composed, allowing us to express a compound statement like “bring me the most recently completed five large tasks” as Task.where(status: completed).order("completed_at DESC").where("size > 3").limit(5).

We can even compose the finders if we extract them to their own methods in pieces:

Get hands-on with 1200+ tech skills courses.