From b51d535cfe154eb9275c261b5977dcac52fb9a0a Mon Sep 17 00:00:00 2001 From: leenasn Date: Mon, 9 Nov 2015 15:21:54 +0530 Subject: [PATCH] Change the registration API to return next heartbeat time --- app/controllers/devices_controller.rb | 5 ++++- spec/controllers/devices_controller_spec.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/devices_controller.rb b/app/controllers/devices_controller.rb index 2a11f5d..3d741ad 100644 --- a/app/controllers/devices_controller.rb +++ b/app/controllers/devices_controller.rb @@ -6,7 +6,10 @@ class DevicesController < ApplicationController device = Device.find_or_initialize_by(unique_id: device_params[:unique_id]) device.assign_attributes(device_params) if device.save - render json: { access_token: device.access_token }, status: :created + render json: { access_token: device.access_token, + next_heartbeat_time: device.next_heartbeat_time + }, + status: :created else render json: { error: device.errors.full_messages }, status: :unprocessable_entity end diff --git a/spec/controllers/devices_controller_spec.rb b/spec/controllers/devices_controller_spec.rb index a1dd3b5..7c38ab9 100644 --- a/spec/controllers/devices_controller_spec.rb +++ b/spec/controllers/devices_controller_spec.rb @@ -6,6 +6,8 @@ RSpec.describe DevicesController, type: :controller do it "creates a device" do expect do post :create, device: attributes_for(:device), format: :json + expect(JSON.parse(response.body)["access_token"]).not_to be_nil + expect(JSON.parse(response.body)["next_heartbeat_time"]).not_to be_nil end.to change{ Device.count }.by(1) end