Update device create API

- Update the existing device if a device with existing unique_id is
   present
This commit is contained in:
Yedhu Krishnan
2015-10-18 11:13:20 +05:30
parent fb3b514f3d
commit 3947889282
3 changed files with 29 additions and 6 deletions

View File

@@ -4,10 +4,27 @@ RSpec.describe DevicesController, type: :controller do
describe "POST #create" do
it "creates a device" do
expect {
expect do
post :create, device: attributes_for(:device), format: :json
}.to change{ Device.count }.by(1)
#expect(response).to have_http_status(:success)
end.to change{ Device.count }.by(1)
end
describe "when device with existing unique id comes" do
before(:example) do
device = create(:device)
@device_params = { model: "New Device", unique_id: device.unique_id }
end
it "does not create a new device" do
expect do
post :create, device: @device_params, format: :json
end.to change { Device.count }.by(0)
end
it "updated the existing device with new params" do
post :create, device: @device_params, format: :json
expect(Device.last.model).to eq("New Device")
end
end
end