diff --git a/app/jobs/check_battery_level_below_job.rb b/app/jobs/check_battery_level_below_job.rb index 09695be1..706725c7 100644 --- a/app/jobs/check_battery_level_below_job.rb +++ b/app/jobs/check_battery_level_below_job.rb @@ -18,7 +18,7 @@ def perform(*args) if device.data["10"].to_i < 15 && device.data["10"].to_i > 1 #p "Sending email to: #{device.owner.email} - device: #{device}" - device.update(notify_low_battery_timestamp: Time.now) + device.update_column(:notify_low_battery_timestamp, Time.now) UserMailer.device_battery_low(device.id).deliver_now end diff --git a/app/jobs/check_device_stopped_publishing_job.rb b/app/jobs/check_device_stopped_publishing_job.rb index bbeab457..8b97cf65 100644 --- a/app/jobs/check_device_stopped_publishing_job.rb +++ b/app/jobs/check_device_stopped_publishing_job.rb @@ -9,7 +9,7 @@ def perform(*args) devices.each do |device| if device.notify_stopped_publishing_timestamp < 24.hours.ago - device.update notify_stopped_publishing_timestamp: Time.now + device.update_column(:notify_stopped_publishing_timestamp, Time.now) UserMailer.device_stopped_publishing(device.id).deliver_now end end diff --git a/app/lib/mqtt_messages_handler.rb b/app/lib/mqtt_messages_handler.rb index 7276c1bd..86fd867c 100644 --- a/app/lib/mqtt_messages_handler.rb +++ b/app/lib/mqtt_messages_handler.rb @@ -38,7 +38,7 @@ def self.handle_topic(topic, message) } ) Sentry.add_breadcrumb(crumb) - device.update hardware_info: json_message + device.update_column(:hardware_info, json_message) end end diff --git a/spec/jobs/check_battery_level_below_job_spec.rb b/spec/jobs/check_battery_level_below_job_spec.rb index 0f5220b1..93427864 100644 --- a/spec/jobs/check_battery_level_below_job_spec.rb +++ b/spec/jobs/check_battery_level_below_job_spec.rb @@ -3,10 +3,10 @@ RSpec.describe CheckBatteryLevelBelowJob, type: :job do it 'should update notify_low_battery_timestamp and send email' do - device = create(:device, notify_low_battery: true) - + device = create(:device, notify_low_battery: true, updated_at: "2023-01-01 00:00:00") + updated_at_before = device.updated_at time_before = device.notify_low_battery_timestamp - device.update(data: { "10": '11'}) + device.update_columns(data: { "10": '11'}) expect(device.data["10"].to_i).to eq(11) @@ -14,5 +14,6 @@ device.reload expect(time_before).not_to eq(device.notify_low_battery_timestamp) + expect(device.updated_at).to eq(updated_at_before) end end