Add request specs for properties CRUD and resolve endpoint #53
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "51-add-request-specs-for-properties-crud-an"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds 22 request specs covering the properties controller endpoints that had zero test coverage: show, edit, update, and the resolve endpoint. All existing specs preserved. Full suite passes at 79 examples, 0 failures.
Changes
spec/requests/properties_spec.rb-- Extended with specs for:GET /properties/:id(6 specs): status, address, client name, active status, special notes, servicesGET /properties/:id/edit(3 specs): status, form content, service checkboxesPATCH /properties/:id(5 specs): success redirect with:see_other, service assignment update, validation failure re-render, JSON success, JSON errorPOST /properties/resolve(8 specs): create new with address, find existing (no count change), client-name-only create, TBD default, service assignment, preserve existing client_name, special_notes, empty params defaultTest Plan
bundle exec rspec spec/requests/properties_spec.rb-- 28 examples, 0 failuresbundle exec rspec-- 79 examples, 0 failuresReview Checklist
Related Notes
None -- test-only change, no docs or SOPs affected.
Related
Closes #51
QA Review
Scope: 1 file changed, +239 lines (test-only)
Acceptance Criteria Check
GET /properties/:idreturns 200 with property contentGET /properties/:id/editreturns 200 with formPOST /propertiescreates a property and redirectscreateaction (route exists but action is missing)POST /propertieswith invalid params returns unprocessable_entityPATCH /properties/:idupdates and redirectsPATCH /properties/:idwith invalid params re-renders editPOST /properties/resolvewith street + number finds or createsPOST /properties/resolvewith existing address returns existingPOST /properties/resolvewithout street creates with client_name onlyPOST /properties/resolvewith service_ids assigns servicesFindings
No blocking issues.
work_queue_items_spec.rbanduploads_spec.rb(let!,Property.create!,Service.find_or_create_by!, describe blocks per action)find_or_create_by!(existing match) andcreate!(no street)see_otherredirect) and JSONrespond_tobranchesPOST /propertiescreate specs are correctly omitted -- the route is defined inroutes.rbbut the controller has nocreateaction. This is a pre-existing gap in the app code, not a test gap.VERDICT: APPROVE
PR #53 Review
DOMAIN REVIEW
Stack: Ruby on Rails 8.1, RSpec request specs, PostgreSQL. No app code changes -- test-only PR.
Controller fidelity: I read
app/controllers/properties_controller.rbline by line and traced every test assertion against the actual controller logic. The tests are accurate:find_or_create_by!uses(address_line, city, state, zip_code)as the composite lookup key. The "finds an existing property by address" test correctly constructs a matching address and asserts no count change + updated client_name. Verified against controller lines 22-37.params[:client_name].presence || property.client_name(controller line 34). Sending noclient_nameparam means.presencereturns nil, fallback to original. Correct.params[:client_name].presence || "TBD"). Correct.special_notestest exercises the create-path block (controller line 29). Correct.No
createaction --resolveIS the creation path: Confirmed. The controller has nocreatemethod. Theresolveendpoint handles both find-or-create (with address) and create-only (without address). The tests correctly cover both branches. The routes file (config/routes.rbline 6) declares:createin theresourcesblock but no controller action exists -- this is a pre-existing latent issue, not in scope for this PR.Turbo Drive 303 convention: The
PATCH /properties/:idsuccess path correctly assertshave_http_status(:see_other), matchingdocs/hotwire.mdrequirements and controller line 69. Theresolveendpoint returns JSON (not a redirect), so 303 is not applicable there. Correct.Validation behavior: The update failure tests (lines 123-128, 141-148) correctly rely on the
validates :client_name, presence: truemodel validation (app/models/property.rbline 8). Sendingclient_name: ""triggers unprocessable_entity. Both HTML and JSON error paths are covered.Test style: Matches existing patterns in
spec/requests/work_queue_items_spec.rbandspec/requests/uploads_spec.rb-- useslet!setup,Property.create!(no factories),describeblocks per endpoint,Service.find_or_create_by!for test data. Consistent.BLOCKERS
None.
NITS
Missing edge case: number present, street blank (controller line 18). When
numberis present butstreetis blank/nil,has_addressevaluates to false and falls through to theelsebranch, creating a new property withaddress_line: nil(line 42, sincehas_addressis false). This is a valid code path in production (user types a number before GPS resolves a street). A test likepost "/properties/resolve", params: { number: "123" }would confirm the behavior. Low risk since the fallback is safe, but worth adding for completeness.Missing edge case: same address, different city (controller line 22-26).
find_or_create_by!includescityin the lookup key, so"123 Oak Ave" in Austinand"123 Oak Ave" in Dallasare distinct properties. No test covers this. Again low risk, but it documents an important business rule.Double
property.reloadon lines 108-109. Could beproperty.reloadonce, then check both attributes. Extremely minor -- readability is fine as-is.PR body says 22 specs, later says 28 examples (6 pre-existing + 22 new = 28). The body text is slightly inconsistent -- the Summary says "22 request specs" while Test Plan says "28 examples, 0 failures". Both are correct but could be clearer that 28 is the total for the file. Trivial.
SOP COMPLIANCE
51-add-request-specs-for-properties-crud-anfollows{issue-number}-{kebab-case-purpose}conventionPROCESS OBSERVATIONS
This PR fills a real gap -- the properties controller had the most complex endpoint in the app (
resolvewith find-or-create, conditional updates, service assignment) and zero test coverage. Adding 22 specs for show/edit/update/resolve significantly reduces change failure risk for future work on these endpoints. The test patterns are consistent with the rest of the suite, which keeps maintenance cost low.The only gap worth noting for future work: the
resolveendpoint has no error handling forfind_or_create_by!orcreate!failures -- if a database constraint fails, it will raise a 500. That is a pre-existing controller issue, not a test gap in this PR.VERDICT: APPROVED