rails-query-object

Encapsulate complex Rails database queries with test-driven development.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/reckerswartz/resume_builder --skill rails-query-object-reckerswartz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-query-object
Source: https://github.com/reckerswartz/resume_builder/tree/main/.windsurf/skills/rails-query-object
Command: npx skills add https://github.com/reckerswartz/resume_builder --skill rails-query-object-reckerswartz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Creates query objects to encapsulate complex database queries using TDD. This approach promotes reusability, testability, and clearer data access patterns in Rails apps.

Core Features & Use Cases

  • Accepts context via constructor (user: or account:)
  • Returns ActiveRecord::Relation or Hash for aggregations
  • Exposes a call method for the primary operation
  • Supports multi-tenancy (scoped to account)

Quick Start

Write a failing spec in spec/queries/, implement the query object in app/queries/, and run the specs to green.

Frequently Asked Questions about rails-query-object

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encapsulate complex Rails database queries for better reusability?

Query objects encapsulate complex Rails database queries by exposing a call method that returns an ActiveRecord::Relation or Hash. This design pattern isolates query logic in app/queries to promote reusability, testability, and clearer data access patterns.

How do I test complex ActiveRecord queries using TDD in Rails?

You test complex ActiveRecord queries using TDD by writing a failing spec in spec/queries/ first, implementing the query object in app/queries/, and running the specs to green. This ensures your query logic is validated before integration.

Can I use query objects to enforce multi-tenancy in Rails apps?

Yes, you can use query objects to enforce multi-tenancy in Rails apps by accepting context like user or account via the constructor. This ensures the query automatically scopes records and returns only data relevant to the specified tenant.

What is the best way to structure aggregations in Rails query objects?

The best way to structure aggregations in Rails query objects is to have the call method return a Hash instead of an ActiveRecord::Relation. This approach neatly encapsulates aggregated data while following standard query composition conventions.

When should I not use a query object for ActiveRecord in Rails?

You should not use a query object for ActiveRecord when your queries are simple enough to reside directly in the model. Query objects are designed to encapsulate complex database queries and aggregations, so trivial scopes do not require this pattern.