Last active
May 20, 2025 02:13
-
-
Save bensheldon/b4fd84f9880b05ae57521beb1297e3a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
description: Rules for creating Controllers | |
globs: | |
alwaysApply: false | |
--- | |
# Modifying Rails controllers | |
## Routes | |
When adding new controllers or actions, don't forget to update the [routes.rb](mdc:config/routes.rb) | |
## Strong Params | |
Use `expect` syntax instead of `require`/`allow` | |
``` | |
# Bad | |
params.require(:user).permit(:name, :favorite_pie) | |
# Good | |
params.expect(user: [:name, :favorite_pie]) | |
``` | |
## Wizard flows | |
Controllers in the `Apply` namespace are part of a form wizard. Each controller represents a stage in the from wizard flow. The flow is implemented in [flowable.rb](mdc:app/controllers/concerns/flowable.rb) and the stages are declared in [base_controller.rb](mdc:app/controllers/apply/base_controller.rb). To redirect to the next stage of the flow, use `flow_next_path`. | |
## Same-controller paths and redirects | |
When linking or redirecting to an action in the same controller, always use `url_for(action: "the_action")` with implicit controller instead of a path helper: | |
``` | |
# Bad | |
my_controller_the_action_path | |
# Good | |
url_for(action: "the_action") | |
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
description: Rules for migrations | |
globs: db/* | |
alwaysApply: false | |
--- | |
# Database migration rules | |
- Always create a migration using `bin/rails g migration <NAME>` instead of just creating a file | |
- The database is Postgres | |
- Use `text` for all string fields; never use `string` or `varchar` | |
- Use `datetime` instead of `timestamp` | |
- Assume that Boolean values should be nullable unless specified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# # .cursor/rules/tests.mdc | |
description: RSpec testing rules | |
globs: spec/* | |
alwaysApply: false | |
--- | |
# Rules for writing RSpec tests | |
- Write comprehensive tests using RSpec. It's ok to put multiple assertions in the same example. | |
- Use factories (FactoryBot) for test data generation. | |
- When writing System Tests. Use `css_id(*)` and `css_class(*)` instead of `"#{dom_id(*)}"` `"#{dom_class(*)}"` | |
- `shoulda-matchers` is not installed. Don't test declarative configuration. For validations, only test that it's not valid when the validation is violated. | |
- `rails-controller-testing` is not installed. Test controllers behaviorally: correct status code and/or model changes. Don't use `assigns` to inspect ivars. | |
- Timecop is used for time traveling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment