Skip to content

Commit

Permalink
dont update component updated_at on new reading
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jan 8, 2024
1 parent d1e34ce commit 986c111
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def remove_mac_address_for_newly_registered_device!

def update_component_timestamps(timestamp, sensor_ids)
components.select {|c| sensor_ids.include?(c.sensor_id) }.each do |component|
component.update(last_reading_at: timestamp)
component.update_column(:last_reading_at, timestamp)
end
end

Expand Down
8 changes: 7 additions & 1 deletion spec/models/device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@

before do
@device = create(:device)
@component_1 = create(:component, device: @device, sensor: create(:sensor, id: 1))
@component_1 = create(:component, device: @device, sensor: create(:sensor, id: 1), updated_at: "2023-01-01 12:00:00")
@component_2 = create(:component, device: @device, sensor: create(:sensor, id: 2))
@device.reload
@timestamp = Time.parse("2023-10-06 06:00:00")
Expand All @@ -300,6 +300,12 @@
expect(@component_2).not_to receive(:update).with(last_reading_at: @timestamp)
@device.update_component_timestamps(@timestamp, [1])
end

it "does not update the component updated_at" do
updated_at = @component_1.updated_at
@device.update_component_timestamps(@timestamp, [1])
expect(@component_1.reload.updated_at).to eq(updated_at)
end
end

context "notifications for low battery" do
Expand Down

0 comments on commit 986c111

Please sign in to comment.