一键导入
rails-testing
Ruby on Rails testing conventions — Minitest strategy, fixtures, system tests. Use when writing tests, setting up test data, or running test suites.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Ruby on Rails testing conventions — Minitest strategy, fixtures, system tests. Use when writing tests, setting up test data, or running test suites.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Ruby on Rails backend conventions — models, controllers, jobs, API design. Use when implementing Rails backend code, creating models, writing controllers, or designing APIs.
Ruby on Rails performance conventions — N+1 prevention, caching, database tuning, benchmarking. Use when optimizing queries, adding caching, or profiling performance.
Ruby on Rails frontend conventions — Hotwire, Turbo, Stimulus, views, components, assets. Use when implementing frontend features, building views, or working with JavaScript/CSS.
Ruby on Rails security conventions — authentication, authorization, OWASP protections, CSRF, input validation. Use when implementing auth, handling sensitive data, or reviewing security.
| name | rails-testing |
| description | Ruby on Rails testing conventions — Minitest strategy, fixtures, system tests. Use when writing tests, setting up test data, or running test suites. |
Testing strategy for Rails applications using Minitest and fixtures. Not RSpec, not FactoryBot.
Sub-files:
Current.session — Lambda defaults and multi-tenancy depend on it; forgetting it is the #1 test failureassert_difference for state changes — Catches false positives that boolean checks alone misstest/
models/
card/
archivable_test.rb # Concern tests get their own file
card_test.rb
controllers/
cards/
closures_controller_test.rb
jobs/
notify_recipients_job_test.rb
fixtures/
cards.yml
sessions.yml
require "test_helper"
class Card::CloseableTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david) # Always — sets user + account context
end
test "close creates closure record and marks card closed" do
card = cards(:logo)
assert_difference -> { Closure.count }, +1 do
card.close
end
assert card.closed?
end
end
Nest assert_difference blocks when multiple record types change together:
assert_difference -> { Closure.count }, +1 do
assert_difference -> { Event.count }, +1 do
card.close
end
end
assert card.closed?
assert_equal "card_closed", Event.last.action
Count alone is insufficient — always verify attributes:
event = Event.last
assert_equal "card_archived", event.action
assert_equal card, event.eventable
assert_equal Current.user, event.creator
# For events with particulars:
assert_equal old_board.name, event.particulars["old_board"]
card.archive
assert_includes Card.archived, card
assert_not_includes Card.unarchived, card
Inherit from ActionDispatch::IntegrationTest. Assert on model state after the request:
class Cards::ClosuresControllerTest < ActionDispatch::IntegrationTest
setup do
Current.session = sessions(:david)
@card = cards(:logo)
end
test "create closes the card" do
post card_closure_path(@card.number)
assert @card.reload.closed?
end
end
Test synchronous logic and async enqueuing separately:
# Business logic — fast, no job infrastructure
test "process_data updates records" do
record.process_data
assert record.processed?
end
# Async wrapper — verify enqueuing
test "process_data_later enqueues job" do
assert_enqueued_with(job: ProcessDataJob, args: [record]) do
record.process_data_later
end
end
Multi-tenancy is automatic — Current.account is captured and restored by the job extension. Setting Current.session in setup is sufficient.
1. Missing Current.session — Lambda defaults (default: -> { Current.user }) raise nil errors. Put it in setup, not inline.
2. Only checking event count — After assert_difference, verify Event.last.action, eventable, and creator.
3. Skipping assert_difference — assert card.archived? can pass if the flag is set wrong. Wrap the action in assert_difference -> { Card::Archive.count }, +1 to confirm the record was created.