Bug fix for `updated_at` staleness noted by @connorrigby

pull/1043/head
Rick Carlino 2018-11-14 14:48:27 -06:00
parent 868f898eba
commit eb6ba750b8
2 changed files with 11 additions and 6 deletions

View File

@ -55,7 +55,10 @@ class Sequence < ApplicationRecord
end
def manually_sync!
device.auto_sync_transaction { broadcast! } if device
device.auto_sync_transaction do
update_attributes!(updated_at: Time.now)
broadcast!
end if device
end
# THIS IS AN OVERRIDE - See Sequence#body_as_json

View File

@ -107,15 +107,17 @@ describe Api::SequencesController do
it 'updates existing sequences' do
sign_in user
sequence = FakeSequence.create( device: user.device)
sequence = FakeSequence.create(device: user.device)
sequence.update_attributes!(updated_at: 2.days.ago)
updated_at_before = sequence.updated_at.to_i
input = { sequence: { name: "Scare Birds", args: {}, body: [] } }
params = { id: sequence.id }
patch :update,
params: params,
body: input.to_json,
format: :json
run_jobs_now do
patch :update, params: params, body: input.to_json, format: :json
end
expect(response.status).to eq(200)
sequence.reload
expect(sequence.updated_at.to_i).to be > updated_at_before
expect(sequence.name).to eq(input[:sequence][:name])
end
end