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
This commit is contained in:
Brooke Kuhlmann
2025-06-25 17:03:09 -06:00
parent 91fcf68cc6
commit 8acbfca8ff
13 changed files with 44 additions and 40 deletions
+5 -5
View File
@@ -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"
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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
+5 -5
View File
@@ -109,15 +109,15 @@
class: :value %>
<% end %>
<%= scope(:form_field, key: :sleep_end_at, errors:).render do %>
<label class="key" for="device[sleep_end_at]">
Sleep End
<%= scope(:form_field, key: :sleep_stop_at, errors:).render do %>
<label class="key" for="device[sleep_stop_at]">
Sleep Stop
<%= render "shared/popovers/trigger", name: :sleep_end %>
</label>
<%= tag.input name: "device[sleep_end_at]",
<%= tag.input name: "device[sleep_stop_at]",
type: :time,
value: time_at(field_for(:sleep_end_at, fields, device)),
value: time_at(field_for(:sleep_stop_at, fields, device)),
class: :value %>
<% end %>
</fieldset>
+1 -1
View File
@@ -6,5 +6,5 @@
<%= render "popovers/mac_address_content" %>
<%= render "popovers/proxy_content" %>
<%= render "popovers/refresh_rate_content" %>
<%= render "popovers/sleep_end_content" %>
<%= render "popovers/sleep_start_content" %>
<%= render "popovers/sleep_stop_content" %>
@@ -1,5 +1,5 @@
<%= scope(:popover_content, name: :sleep_start, label: "Sleep Start").render do %>
<p>Allows you to set when your device should go to sleep. Requires corresponding end time.</p>
<p>Allows you to set when your device should go to sleep. Requires corresponding stop time.</p>
<p>💡 When editing this field, use <kbd>TAB</kbd> + <kbd>DELETE</kbd> to tab through and delete all values to clear this out.</p>
<% end %>
@@ -1,4 +1,4 @@
<%= scope(:popover_content, name: :sleep_end, label: "Sleep End").render do %>
<%= scope(:popover_content, name: :sleep_stop, label: "Sleep Stop").render do %>
<p>Allows you to set when your device should wake up. Requires corresponding start time.</p>
<p>💡 When editing this field, use <kbd>TAB</kbd> + <kbd>DELETE</kbd> to tab through and delete all values to clear this out.</p>
+3 -3
View File
@@ -86,10 +86,10 @@
<dd class="value"><%= human_time device.sleep_start_at %></dd>
<dt class="key">
Sleep End
<%= render "shared/popovers/trigger", name: :sleep_end %>
Sleep Stop
<%= render "shared/popovers/trigger", name: :sleep_stop %>
</dt>
<dd class="value"><%= human_time device.sleep_end_at %></dd>
<dd class="value"><%= human_time device.sleep_stop_at %></dd>
<dt class="key">Created</dt>
<dd class="value"><%= human_at device.created_at %></dd>
@@ -0,0 +1,3 @@
# frozen_string_literal: true
ROM::SQL.migration { change { rename_column :devices, :sleep_end_at, :sleep_stop_at } }
+3 -2
View File
@@ -147,7 +147,7 @@ CREATE TABLE public.devices (
proxy boolean DEFAULT false NOT NULL,
firmware_update boolean DEFAULT false NOT NULL,
sleep_start_at time without time zone,
sleep_end_at time without time zone,
sleep_stop_at time without time zone,
model_id integer,
playlist_id integer
);
@@ -440,4 +440,5 @@ INSERT INTO schema_migrations (filename) VALUES
('20250624130848_add_model.rb'),
('20250625103300_remove_model_timestamps.rb'),
('20250625123433_add_playlist.rb'),
('20250625123558_add_device_and_model_playlist_columns.rb');
('20250625123558_add_device_and_model_playlist_columns.rb'),
('20250625123645_change_device_sleep_end_column.rb');
+10 -10
View File
@@ -18,7 +18,7 @@ RSpec.describe Terminus::Contracts::Devices::Create do
proxy: "on",
firmware_update: "on",
sleep_start_at: Time.new(2025, 1, 1, 1, 1, 1),
sleep_end_at: Time.new(2025, 2, 1, 1, 1, 1)
sleep_stop_at: Time.new(2025, 2, 1, 1, 1, 1)
}
}
end
@@ -29,7 +29,7 @@ RSpec.describe Terminus::Contracts::Devices::Create do
it "answers success when start and end time are nil" do
attributes[:device].delete :sleep_start_at
attributes[:device].delete :sleep_end_at
attributes[:device].delete :sleep_stop_at
expect(contract.call(attributes)).to be_success
end
@@ -39,30 +39,30 @@ RSpec.describe Terminus::Contracts::Devices::Create do
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must be before end time"],
sleep_end_at: ["must be after start time"]
sleep_start_at: ["must be before stop time"],
sleep_stop_at: ["must be after start time"]
}
)
end
it "answers failures when start is missing but end is present" do
it "answers failures when start is missing but stop is present" do
attributes[:device][:sleep_start_at] = nil
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must be filled"],
sleep_end_at: ["must have corresponding start time"]
sleep_stop_at: ["must have corresponding start time"]
}
)
end
it "answers failures when start is present but end is missing" do
attributes[:device][:sleep_end_at] = nil
it "answers failures when start is present but stop is missing" do
attributes[:device][:sleep_stop_at] = nil
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must have corresponding end time"],
sleep_end_at: ["must be filled"]
sleep_start_at: ["must have corresponding stop time"],
sleep_stop_at: ["must be filled"]
}
)
end
+8 -8
View File
@@ -19,7 +19,7 @@ RSpec.describe Terminus::Contracts::Devices::Update do
proxy: "on",
firmware_update: "on",
sleep_start_at: Time.new(2025, 1, 1, 1, 1, 1),
sleep_end_at: Time.new(2025, 2, 1, 1, 1, 1)
sleep_stop_at: Time.new(2025, 2, 1, 1, 1, 1)
}
}
end
@@ -30,7 +30,7 @@ RSpec.describe Terminus::Contracts::Devices::Update do
it "answers success when start and end date/time are nil" do
attributes[:device].delete :sleep_start_at
attributes[:device].delete :sleep_end_at
attributes[:device].delete :sleep_stop_at
expect(contract.call(attributes)).to be_success
end
@@ -40,8 +40,8 @@ RSpec.describe Terminus::Contracts::Devices::Update do
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must be before end time"],
sleep_end_at: ["must be after start time"]
sleep_start_at: ["must be before stop time"],
sleep_stop_at: ["must be after start time"]
}
)
end
@@ -52,18 +52,18 @@ RSpec.describe Terminus::Contracts::Devices::Update do
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must be filled"],
sleep_end_at: ["must have corresponding start time"]
sleep_stop_at: ["must have corresponding start time"]
}
)
end
it "answers failures when start is present but end is missing" do
attributes[:device][:sleep_end_at] = nil
attributes[:device][:sleep_stop_at] = nil
expect(contract.call(attributes).errors.to_h).to eq(
device: {
sleep_start_at: ["must have corresponding end time"],
sleep_end_at: ["must be filled"]
sleep_start_at: ["must have corresponding stop time"],
sleep_stop_at: ["must be filled"]
}
)
end
+1 -1
View File
@@ -33,7 +33,7 @@ RSpec.describe Terminus::Structs::Device, :db do
Factory[
:device,
sleep_start_at: Time.new(2025, 1, 1, 1, 1, 0),
sleep_end_at: Time.new(2025, 1, 1, 1, 10, 0)
sleep_stop_at: Time.new(2025, 1, 1, 1, 10, 0)
]
end