Skip to content

fix: preserve decimal hours in activity create and update#352

Open
bmortimer wants to merge 3 commits intonavapbc:mainfrom
bmortimer:fix/hours-decimal-truncation
Open

fix: preserve decimal hours in activity create and update#352
bmortimer wants to merge 3 commits intonavapbc:mainfrom
bmortimer:fix/hours-decimal-truncation

Conversation

@bmortimer
Copy link

Change .to_i to .to_f in activity_attributes_from_params to prevent silent truncation of decimal hour values (e.g., 5.25 → 5, 3.5 → 3).

Adds test coverage for decimal hours on both create and update paths.

Ticket

Resolves #350

Changes

  • activities_controller.rb line 157: change .to_i to .to_f in activity_attributes_from_params
  • activities_spec.rb: add two tests — decimal hours preserved on create (5.25) and update (3.5)

Context for reviewers

Both create and update call the shared activity_attributes_from_params method which was converting hours with .to_i. The database column is decimal, the model declares strata_attribute :hours, :decimal, and the input field uses inputmode: "decimal" so decimal support appears to be intended at every other layer.

.to_f is consistent with how hours are handled elsewhere in the codebase.

No change to income handling — the existing .to_i * 100 for dollar-to-cents conversion appears correct.

Issue 350

Testing

Full test suite passes (1489 examples, 0 failures):

bundle exec rspec --exclude-pattern '**/image_to_pdf*'
1489 examples, 0 failures, 1 pending

New test cases:

  • POST /create with hours "5.25" → persisted as 5.25 ✓
  • PATCH /update with hours "3.5" → persisted as 3.5 ✓
  • Existing empty-hours and invalid-input tests continue to pass (.to_f returns 0.0 for invalid input, letting model validation
    handle the error)

Change .to_i to .to_f in activity_attributes_from_params to prevent
silent truncation of decimal hour values (e.g., 5.25 → 5, 3.5 → 3).

Adds test coverage for decimal hours on both create and update paths.

Co-Authored-By: Claude <noreply@anthropic.com>
@bmortimer bmortimer requested a review from a team as a code owner March 16, 2026 18:10
@bmortimer bmortimer requested a review from nkutub March 16, 2026 18:10
@bmortimer
Copy link
Author

@nkutub Anything I need to be doing to adjust my PR or is this just a pure CI/CD pipeline thing that I let y'all work out?
Mostly looks like the latter but I figured I should ask.

@nkutub
Copy link
Contributor

nkutub commented Mar 22, 2026

@nkutub Anything I need to be doing to adjust my PR or is this just a pure CI/CD pipeline thing that I let y'all work out? Mostly looks like the latter but I figured I should ask.

Your PR is good, we are investigating the pipeline issues.. once they clear we can merge

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.

[Bug]: Hours input silently truncates decimal values without feedback

2 participants