From 8acbfca8ff5678d40cbc31ebce97284cfade8965 Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Tue, 24 Jun 2025 12:04:24 -0600 Subject: [PATCH] Updated device sleep end at column as sleep stop at Necessary to use `stop` instead of `end` in order to be consistent with other date/time ranges used within the system. This updates all affected files related to using the older column name. Milestone: minor --- app/contracts/devices/abstract.rb | 10 +++++----- app/schemas/devices/upsert.rb | 2 +- app/structs/device.rb | 4 ++-- app/templates/devices/_fields.html.erb | 10 +++++----- app/templates/devices/popovers/_all.html.erb | 2 +- .../popovers/_sleep_start_content.html.erb | 2 +- ....html.erb => _sleep_stop_content.html.erb} | 2 +- app/templates/devices/show.html.erb | 6 +++--- ...25123645_change_device_sleep_end_column.rb | 3 +++ config/db/structure.sql | 5 +++-- spec/app/contracts/devices/create_spec.rb | 20 +++++++++---------- spec/app/contracts/devices/update_spec.rb | 16 +++++++-------- spec/app/structs/device_spec.rb | 2 +- 13 files changed, 44 insertions(+), 40 deletions(-) rename app/templates/devices/popovers/{_sleep_end_content.html.erb => _sleep_stop_content.html.erb} (74%) create mode 100644 config/db/migrate/20250625123645_change_device_sleep_end_column.rb diff --git a/app/contracts/devices/abstract.rb b/app/contracts/devices/abstract.rb index 88f33c82..31847336 100644 --- a/app/contracts/devices/abstract.rb +++ b/app/contracts/devices/abstract.rb @@ -6,16 +6,16 @@ module Terminus # The abstract contract for device create and update. class Abstract < Dry::Validation::Contract rule device: :sleep_start_at do - end_at = values.dig :device, :sleep_end_at + stop_at = values.dig :device, :sleep_stop_at - if value && end_at && value > end_at then key.failure "must be before end time" - elsif value && end_at.nil? then key.failure "must have corresponding end time" - elsif value.nil? && end_at then key.failure "must be filled" + if value && stop_at && value > stop_at then key.failure "must be before stop time" + elsif value && stop_at.nil? then key.failure "must have corresponding stop time" + elsif value.nil? && stop_at then key.failure "must be filled" else next end end - rule device: :sleep_end_at do + rule device: :sleep_stop_at do start_at = values.dig :device, :sleep_start_at if value && start_at && value < start_at then key.failure "must be after start time" diff --git a/app/schemas/devices/upsert.rb b/app/schemas/devices/upsert.rb index 86b03aa4..8dafe7d4 100644 --- a/app/schemas/devices/upsert.rb +++ b/app/schemas/devices/upsert.rb @@ -15,7 +15,7 @@ module Terminus optional(:proxy).filled :bool optional(:firmware_update).filled :bool optional(:sleep_start_at).maybe :time - optional(:sleep_end_at).maybe :time + optional(:sleep_stop_at).maybe :time after :value_coercer do |result| next unless result.output diff --git a/app/structs/device.rb b/app/structs/device.rb index d85fb044..6ee2bdfe 100644 --- a/app/structs/device.rb +++ b/app/structs/device.rb @@ -17,9 +17,9 @@ module Terminus end def asleep? now = Time.now - return false unless sleep_start_at && sleep_end_at + return false unless sleep_start_at && sleep_stop_at - (sleep_start_at.to_s..sleep_end_at.to_s).cover? now.strftime("%H:%M:%S") + (sleep_start_at.to_s..sleep_stop_at.to_s).cover? now.strftime("%H:%M:%S") end end end diff --git a/app/templates/devices/_fields.html.erb b/app/templates/devices/_fields.html.erb index 3117cc69..3fdbddc9 100644 --- a/app/templates/devices/_fields.html.erb +++ b/app/templates/devices/_fields.html.erb @@ -109,15 +109,15 @@ class: :value %> <% end %> - <%= scope(:form_field, key: :sleep_end_at, errors:).render do %> -