AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
100/100
Scores the file, not the repository.Length
847 words
22 headings · 11 code blocksRepository
59k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Ruby on Rails Codebase Guide for AI Coding Agents23This is the code base of the Ruby on Rails web framework.45## Architecture Overview67Rails is a **monorepo containing 10+ independent components** that can work standalone or together.89Each component lives in its own directory at the root level:1011- **Active Record** (`activerecord/`) - ORM and database abstraction12- **Action Pack** (`actionpack/`) - Controllers and routing (contains Action Controller and Action Dispatch)13- **Action View** (`actionview/`) - View templates and helpers (extracted from Action Pack in Rails 3)14- **Active Model** (`activemodel/`) - Model interfaces without database dependency15- **Active Support** (`activesupport/`) - Core extensions and utilities used across all Rails components16- **Action Mailer** (`actionmailer/`), **Action Mailbox** (`actionmailbox/`) - Email sending/receiving17- **Active Job** (`activejob/`) - Background job abstraction18- **Action Cable** (`actioncable/`) - WebSocket integration19- **Active Storage** (`activestorage/`) - File uploads and cloud storage20- **Action Text** (`actiontext/`) - Rich text content21- **Railties** (`railties/`) - Rails CLI, generators, and framework glue2223**Key architectural principle**: Rails components are loosely coupled. Changes to one of them should not break others unless there's an explicit dependency.2425## Testing Commands2627### Running Tests in a Component2829From within the component directory (preferred method):3031```bash32cd actionview && bin/test # Run all tests33cd actionview && bin/test test/template/form_helper_test.rb34cd actionview && bin/test -i "/test_name/" # Filter by test name pattern35```3637How to run a specific test method:3839```bash40cd actionview && bin/test test/template/form_helper_test.rb -i test_hidden_field41```4243How to run the test at a specific line:4445```bash46cd actionview && bin/test test/template/form_helper_test.rb:12347```4849### Running Tests from Root5051Run all tests for a given component:5253```bash54rake actionview:test55```5657Run tests across all components:5859```bash60rake test # Run all tests61rake smoke # Quick smoke test62```6364### Active Record Testing (Multiple Database Adapters)6566How to test individual database adapters in Active Record:6768```bash69cd activerecord70bundle exec rake test:sqlite3 # Default71bundle exec rake test:postgresql72bundle exec rake test:mysql273bundle exec rake test:trilogy74```7576**Important**: Tests run in parallel using multiple processes. The `bin/test` script wraps Rails' custom test runner (`tools/test.rb`) which uses `Rails::TestUnit::Runner`.7778## Configuration Testing Patterns7980When testing configuration options, use `Object#with` (from Active Support) to temporarily modify class attributes:8182```ruby83# Correct: Use Object#with for temporary config changes84ActionView::Base.with(remove_hidden_field_autocomplete: true) do85 # Test code here86end8788# Avoid: Manual set/restore patterns89old = ActionView::Base.remove_hidden_field_autocomplete90ActionView::Base.remove_hidden_field_autocomplete = true91# ... test code92ActionView::Base.remove_hidden_field_autocomplete = old93```9495This pattern is used throughout the test suite, especially for:9697- `ActionView::Base.with(config_option: value)`98- `ActionController::Base.with(config_option: value)`99- Other framework configuration testing100101**Requires**: `require "active_support/core_ext/object/with"` at the top of test files.102103## Code Conventions104105### Configuration Flags106107Configuration options follow a consistent pattern across components:1081091. **Define the attribute** in the base class (e.g., `ActionView::Base`):110```ruby111 cattr_accessor :remove_hidden_field_autocomplete, default: false112```1131142. **Check the flag** before applying behavior:115```ruby116 @options.reverse_merge!(autocomplete: "off") unless ActionView::Base.remove_hidden_field_autocomplete117```1181193. **Enable by default** in new Rails versions via `load_defaults`:120```ruby121 # In railties/lib/rails/application/configuration.rb122 case target_version.to_s123 when "8.1"124 action_view.remove_hidden_field_autocomplete = true125 end126```127128### Changelog Updates129130When fixing bugs or adding features:131132- Add an entry to the top of `<component>/CHANGELOG.md`133- Format: Brief description, then `*Your Name*` on new line134- See existing entries for style135136### Test Naming137138- Use descriptive names: `test_hidden_field_omits_autocomplete_when_remove_hidden_field_autocomplete_is_true`139- Group related tests together in the file140- Test both default behavior AND explicit overrides141142### Code Style143144- Run RuboCop: `bundle exec rubocop` (there's a project-wide `.rubocop.yml`)145- Prefer `assert_not` over `assert !` (`Rails/AssertNot` cop)146- Prefer `assert_dom_equal` for HTML comparisons in view tests147- Use `# frozen_string_literal: true` at top of all files148149## Common Development Workflows150151### Making a Fix Across Multiple Components152153Example: Issue #55984 required changes to:1541551. Helper class: `actionview/lib/action_view/helpers/tags/hidden_field.rb`1562. Tests: `actionview/test/template/form_helper_test.rb`1573. Reference: Similar fixes were in `tags/check_box.rb`, `tags/file_field.rb`, `form_tag_helper.rb`, `url_helper.rb`158159**Pattern**: When fixing a configuration flag, grep for similar patterns in other helpers:160161```bash162grep -r "unless ActionView::Base.remove_hidden_field_autocomplete" actionview/lib/163```164165### Finding Related Code166167- **Similar functionality**: Look in the same `lib/*/helpers/` or `lib/*/tags/` directory168- **Tests for a helper**: Check `test/template/<helper_name>_test.rb`169- **Configuration setup**: Check `railties/lib/rails/application/configuration.rb`170- **Default values**: Look for `load_defaults` version blocks171172### Working with Forms and Helpers173174Action View helpers follow this structure:175176- **Tag helpers** (`lib/action_view/helpers/tags/`) - Individual form elements177- **Form helpers** (`lib/action_view/helpers/form_helper.rb`) - Form builders178- **Form tag helpers** (`lib/action_view/helpers/form_tag_helper.rb`) - Standalone tags179180When modifying form behavior, check ALL three locations for consistency.181182## Issue References and Pull Requests183184- Always reference issue numbers in commits: `Fix #12345: Description`185- Check for previous related PRs/issues when fixing bugs186- Bug report templates live in `guides/bug_report_templates/`187188## File Organization Principles189190- `lib/` - Production code191- `test/` - Test files (NOT `spec/` - Rails uses Minitest, not RSpec)192- `bin/` - Executable scripts (e.g., `bin/test`)193- Each framework is self-contained with its own Gemfile and dependencies194- Shared tools live in `tools/` (e.g., `tools/test.rb`, `tools/release.rb`)195196## Documentation197198- API docs use YARD/RDoc format199- Guides source in `guides/source/` (Markdown)200- Generate docs: `rake rdoc` (from framework directory)201- Configuration options documented in `guides/source/configuring.md`202
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-frontend/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago |
