rails-query-object

Generate Ruby on Rails query objects with Test-Driven Development specs.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines the creation of complex database queries in Rails applications by enforcing a Test-Driven Development (TDD) approach, ensuring robust and maintainable query logic.

Core Features & Use Cases

  • TDD Workflow: Guides users through writing failing specs before implementing query objects.
  • Encapsulation: Promotes organizing complex queries into reusable, single-purpose classes.
  • Use Case: When building a reporting feature that requires aggregating sales data across multiple criteria, use this Skill to generate a SalesSummaryQuery object, starting with its RSpec tests.

Quick Start

Use the rails-query-object skill to generate a new query object for fetching active users.

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 using a query object?

To encapsulate complex Rails database queries using a query object, you create single-purpose classes that isolate intricate data retrieval logic. This approach keeps fat models or controllers thin and promotes reusable, maintainable query logic across your application.

What is the best way to test complex Rails database queries with RSpec?

The best way to test complex Rails database queries with RSpec is using a Test-Driven Development workflow. You write failing specs before implementing the query object, ensuring robust and maintainable logic for statistical aggregation and report generation.

When should I use a query object instead of a Rails model scope?

You should use a query object instead of a Rails model scope when dealing with intricate data retrieval, multi-criteria statistical aggregation, or report generation. Query objects encapsulate complex logic into reusable classes better than chained scopes.

How do I generate a query object for a Rails reporting feature using TDD?

To generate a query object for a Rails reporting feature using TDD, you start by writing failing RSpec tests for the desired data aggregation. You then implement the query object class to pass the tests, adhering to project conventions for context injection and return types.

Can I use query objects for multi-tenancy in Ruby on Rails applications?

Yes, you can use query objects for multi-tenancy in Ruby on Rails applications. The generated query objects are designed to adhere to project conventions, including multi-tenancy requirements, ensuring isolated and accurate data retrieval across tenant boundaries.

Does this TDD workflow support context injection for Rails query objects?

Yes, this TDD workflow supports context injection for Rails query objects. The generated classes adhere to project conventions for context injection, return types, and multi-tenancy, allowing flexible and maintainable complex database queries.