Skip to content

Switch test framework from Minitest to RSpec + FactoryBot#13

Merged
HamptonMakes merged 2 commits into
mainfrom
hampton/switch-to-rspec-and-factorybot
Feb 24, 2026
Merged

Switch test framework from Minitest to RSpec + FactoryBot#13
HamptonMakes merged 2 commits into
mainfrom
hampton/switch-to-rspec-and-factorybot

Conversation

@HamptonMakes

Copy link
Copy Markdown
Collaborator

Summary

Migrates the entire test suite from Minitest + fixtures to RSpec + FactoryBot.

Changes

  • Gemfile: Removed minitest ~> 5.25, added rspec-rails and factory_bot_rails to test group
  • spec/: 175 specs covering all models, requests, services, and helpers — 1:1 parity with the old test suite
  • spec/factories/: 9 factory files with proper association chains (orgs derived from parent objects)
  • spec/rails_helper.rb: FactoryBot syntax methods, sign_in_as helper, TimeHelpers
  • AGENTS.md: Updated testing section to document RSpec + FactoryBot conventions
  • test/: Removed entirely

Key conventions

  • UUID primary keys auto-assigned by ApplicationRecord#assign_uuid — factories never set id
  • Factories derive associations from parents (e.g., organization { plan.organization })
  • sign_in_as(user) helper for request specs
  • Run suite: bundle exec rspec

Verification

All 175 examples pass:

175 examples, 0 failures

- Replace minitest gem with rspec-rails and factory_bot_rails
- Convert all 175 tests from test/ to spec/ (models, requests, services, helpers)
- Convert YAML fixtures to FactoryBot factories with proper association chains
- Factories derive org from parent objects to keep data consistent
- Add sign_in_as helper and ActiveSupport::Testing::TimeHelpers to rails_helper
- Update AGENTS.md to document new testing conventions
- Remove old test/ directory

Amp-Thread-ID: https://ampcode.com/threads/T-019c8c51-0ef2-723d-bab8-a95e7ecbf4e0
Co-authored-by: Amp <amp@ampcode.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8acc8fe625

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread spec/factories/edit_leases.rb Outdated
FactoryBot.define do
factory :edit_lease do
plan
organization

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Derive edit lease organization from associated plan

This factory currently builds plan and organization independently, so create(:edit_lease) can generate cross-tenant records where edit_lease.organization_id does not match plan.organization_id; that state cannot be produced by EditLease.acquire! and can cause specs to pass or fail against impossible data. AGENTS.md explicitly requires factories to derive associations from parent objects, so this should be tied to the plan (organization { plan.organization }).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 75fbce0organization now derives from plan.organization.

Comment thread spec/factories/comment_threads.rb Outdated

trait :resolved do
status { "resolved" }
association :resolved_by_user, factory: :user

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep resolved_by_user in the thread's organization

In the :resolved trait, resolved_by_user is created with a standalone :user factory, so it can belong to a different organization than the comment_thread; this again violates the AGENTS.md factory rule about deriving associations from parent objects and introduces invalid multi-tenant test fixtures that can hide authorization/scoping issues when this trait is used. The trait should scope resolved_by_user to plan.organization (or organization).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 75fbce0resolved_by_user now scoped to plan.organization.

- edit_leases: derive organization from plan.organization
- comment_threads: scope resolved_by_user to plan.organization in :resolved trait

Amp-Thread-ID: https://ampcode.com/threads/T-019c9060-1543-77b2-af4d-2757ba2a6ee1
Co-authored-by: Amp <amp@ampcode.com>
@HamptonMakes
HamptonMakes merged commit b690948 into main Feb 24, 2026
4 checks passed
@HamptonMakes
HamptonMakes deleted the hampton/switch-to-rspec-and-factorybot branch February 24, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant