mirror of
http://ghproxy.cn/https://github.com/multunus/onemdm-server
synced 2025-12-06 02:04:57 +00:00
Update device create API
- Update the existing device if a device with existing unique_id is present
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe Device, type: :model do
|
||||
it { should validate_presence_of :model }
|
||||
it { should validate_uniqueness_of :unique_id }
|
||||
|
||||
describe "after create" do
|
||||
describe "before create" do
|
||||
it "generates an access token for the device" do
|
||||
expect(device.access_token).not_to be_nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user