Skip to content

test: add MaterialCategory and BuyerCategory model tests + BuyerCategory factory#5

Open
cmbaldwin wants to merge 1 commit intomasterfrom
improve/material-buyer-category-tests
Open

test: add MaterialCategory and BuyerCategory model tests + BuyerCategory factory#5
cmbaldwin wants to merge 1 commit intomasterfrom
improve/material-buyer-category-tests

Conversation

@cmbaldwin
Copy link
Copy Markdown
Owner

What

Adds model tests for two untested classification models (Oroshi::MaterialCategory and Oroshi::BuyerCategory), plus a missing factory for BuyerCategory.

Why

These models are used throughout the order system for classifying buyers and packaging materials, but neither had dedicated unit tests. BuyerCategory also lacked a FactoryBot factory despite being referenced in system tests.

36 oroshi models exist; only 22 had model tests. This closes two gaps.

Changes

test/factories/oroshi/buyer_categories_factory.rb (new)

BuyerCategory factory with FFaker-generated name, symbol, and hex color — follows the same pattern as the existing oroshi_buyer factory.

test/models/oroshi/material_category_test.rb (11 tests)

  • Valid with valid attributes
  • Name presence validation
  • Activatable concern: nil active is invalid, false active is valid
  • active / inactive scope filtering
  • has_many :materials association
  • Dependent destroy: verifies materials are removed when category is destroyed

test/models/oroshi/buyer_category_test.rb (8 tests)

  • Valid with valid attributes
  • Name, symbol, color presence validations
  • Default scope orders by created_at ascending
  • has_many :buyers and has_many :buyer_buyer_categories associations
  • Persistence sanity check

Risks

Low — no model logic changes, no migrations. All tests use FactoryBot build/create with the dummy app's test database.

Both Oroshi::MaterialCategory and Oroshi::BuyerCategory had no model
tests despite being core classification models used throughout the
wholesale order system.

MaterialCategory (11 tests):
- Valid with valid attributes
- Name presence validation
- Activatable concern: nil active invalid, false active valid
- Activatable scopes: active/inactive filtering
- has_many :materials association
- dependent: :destroy behaviour verified with a created material

BuyerCategory (8 tests):
- Valid with valid attributes
- Name, symbol, color presence validations
- default_scope orders by created_at ascending
- has_many :buyers and :buyer_buyer_categories associations
- Persistence sanity check

Also adds test/factories/oroshi/buyer_categories_factory.rb (missing
factory referenced in system tests but never defined as a standalone
factory file).
@cmbaldwin cmbaldwin added the escalante-improvement Nightly automated improvement PR label Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

escalante-improvement Nightly automated improvement PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant