Merge pull request #1284 from RickCarlino/wednesday

Fix #1283
pull/1285/head
Rick Carlino 2019-07-17 11:28:23 -05:00 committed by GitHub
commit 992b6f9e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 68 deletions

View File

@ -37,6 +37,7 @@ class ApplicationRecord < ActiveRecord::Base
def self.auto_sync_debounce
@auto_sync_paused = true
result = yield
result.update_attributes!(updated_at: Time.now)
@auto_sync_paused = false
result.broadcast!
result

View File

@ -58,10 +58,11 @@ describe Api::FarmEventsController do
kind: "parameter_application",
args: {
label: "foo",
data_value: { kind: "coordinate", args: { x: 0, y: 0, z: 0 } }
}
}
])
data_value: { kind: "coordinate", args: { x: 0, y: 0, z: 0 } },
},
},
],
)
return fe
end
@ -95,9 +96,11 @@ describe Api::FarmEventsController do
it "replaces old fragment when given a new one" do
fe = create_fe_with_fragment
expect(fe.fragment).not_to be(nil)
old_timestamp = fe.updated_at
update_body(fe, nil)
expect(response.status).to eq(200)
expect(fe.reload.fragment).not_to be(nil)
expect(fe.updated_at).to be > old_timestamp
end
it "inserts new fragment when there originally was none" do
@ -113,11 +116,11 @@ describe Api::FarmEventsController do
args: {
x: 1,
y: 2,
z: 3
}
}
}
}
z: 3,
},
},
},
},
]
update_body(fe, body)
expect(response.status).to eq(200)

View File

@ -1,7 +1,6 @@
require "spec_helper"
describe Api::RegimensController do
include Devise::Test::ControllerHelpers
describe "#update" do
@ -19,17 +18,17 @@ describe Api::RegimensController do
"regimen_items" => [
{
"time_offset" => 1555500000,
"sequence_id" => sequence.id
"sequence_id" => sequence.id,
},
{
"time_offset" => 864300000,
"sequence_id" => sequence.id
"sequence_id" => sequence.id,
},
{
"time_offset" => 950700000,
"sequence_id" => sequence.id
}
]
"sequence_id" => sequence.id,
},
],
}
put :update, body: payload.to_json, params: { id: existing.id }
expect(response.status).to eq(200)
@ -50,10 +49,10 @@ describe Api::RegimensController do
label: "parent",
data_value: {
kind: "coordinate",
args: { x: 0, y: 0, z: 0 }
}
}
}
args: { x: 0, y: 0, z: 0 },
},
},
},
]
existing = Regimens::Create.run!(device: user.device,
name: "x",
@ -72,19 +71,20 @@ describe Api::RegimensController do
data_value: {
kind: "tool",
args: {
tool_id: FactoryBot.create(:tool, device: sequence.device).id
}
}
}
}
tool_id: FactoryBot.create(:tool, device: sequence.device).id,
},
},
},
},
],
regimen_items: [
{
time_offset: 950700000,
sequence_id: sequence.id
}
]
sequence_id: sequence.id,
},
],
}
old_timestamp = existing.created_at.as_json
put :update,
body: payload.to_json,
format: :json,
@ -92,6 +92,7 @@ describe Api::RegimensController do
expect(response.status).to eq(200)
path = [:body, 0, :args, :data_value, :kind]
expect(json.dig(*path)).to eq(payload.dig(*path))
expect(json.fetch(:updated_at)).to_not eq(old_timestamp)
end
it "catches bad regimen_items" do
@ -101,13 +102,12 @@ describe Api::RegimensController do
"id" => existing.id,
"name" => "something new",
"color" => "blue",
"regimen_items" => [ { "time_offset" => 950700000, "sequence_id" => 0 } ]
"regimen_items" => [{ "time_offset" => 950700000, "sequence_id" => 0 }],
}
put :update, body: payload.to_json, params: { id: existing.id }, format: :json
expect(response.status).to eq(422)
expect(json[:regimen_items]).to be
expect(json[:regimen_items])
.to include("Failed to instantiate nested RegimenItem.")
expect(json[:regimen_items]).to include("Failed to instantiate nested RegimenItem.")
end
end
end