rails-query-object

Create Rails query objects with specs-first TDD and tenant isolation.

1|Updated Jan 8, 2026
One-click install
npx skills add https://github.com/LaunchPadLab/ai-bank --skill rails-query-object-launchpadlab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-query-object
Source: https://github.com/LaunchPadLab/ai-bank/tree/main/claude/skills/rails-query-object
Command: npx skills add https://github.com/LaunchPadLab/ai-bank --skill rails-query-object-launchpadlab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the problem of tangled, hard-to-test ActiveRecord query logic by turning complex database reads into focused, reusable query objects with tests first.

Core Features & Use Cases

  • TDD workflow for complex queries: write failing tests under test/queries first, then implement app/queries, and iterate until tests go GREEN.
  • Multi-tenant safe scoping: enforce account-scoped filtering so data from other tenants cannot appear in results.
  • Clear result contracts: design query objects to return chainable ActiveRecord::Relation for lists or Hash for aggregations, exposing a consistent call method.

Use case: You need a dashboard that aggregates stats and filtered records across many conditions, and you want the logic isolated from controllers while staying testable and tenant-safe.

Quick Start

Ask the skill to generate a TDD Rails query object that takes an account: parameter, writes a matching test under test/queries/, and implements the corresponding app/queries/ query with a call method that returns the expected result type.

Frequently Asked Questions about rails-query-object

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

FAQPage Schema
What are Rails query objects and when should I use them over scopes?

Rails query objects encapsulate complex database query logic into focused, reusable classes with a call method. Use them for multi-condition filtering, reporting aggregations, and dashboard statistics to prevent long ActiveRecord chains in controllers and models.

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

You can test complex ActiveRecord database queries using TDD by writing failing specs under test/queries first, then implementing the corresponding query object in app/queries, and iterating until tests pass. This isolates query logic and validates tenant isolation and result shapes.

How do I enforce multi-tenancy in Rails ActiveRecord queries?

Enforce multi-tenancy in Rails ActiveRecord queries by using query objects that require an account-scoped constructor accepting user or account parameters. This ensures tenant isolation so data from other accounts cannot appear in query results.

What is the best way to organize dashboard reporting and aggregation logic in Rails?

The best way to organize dashboard reporting and aggregation logic in Rails is using query objects. They isolate multi-condition filtering and aggregations from controllers, returning chainable ActiveRecord::Relation for lists or Hash for aggregations through a consistent call method.

Does this TDD query object approach work without adding new Rails dependencies?

Yes, this TDD query object approach works without adding new dependencies. It uses standard Rails ActiveRecord patterns and native Ruby testing frameworks to generate spec-driven query classes that encapsulate database reads.

Why are my Rails controller database queries getting too long and hard to test?

Rails controller database queries get hard to test when complex multi-condition filtering and aggregations are tangled in controllers. Extracting this logic into TDD-ready query objects with documented return types makes the code focused, reusable, and testable.