From 93e309592557f850774f031cd409517d3f63465b Mon Sep 17 00:00:00 2001 From: leenasn Date: Fri, 13 Nov 2015 15:52:18 +0530 Subject: [PATCH] Add GCM token field to device --- app/controllers/devices_controller.rb | 2 +- app/models/device.rb | 2 +- db/migrate/20151113095735_add_gcm_token_to_devices.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/devices.rb | 6 +++--- spec/models/device_spec.rb | 1 + 6 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20151113095735_add_gcm_token_to_devices.rb diff --git a/app/controllers/devices_controller.rb b/app/controllers/devices_controller.rb index fac24fd..7b2b58b 100644 --- a/app/controllers/devices_controller.rb +++ b/app/controllers/devices_controller.rb @@ -19,6 +19,6 @@ class DevicesController < ApplicationController private def device_params - params.require(:device).permit(:model, :unique_id, :imei_number) + params.require(:device).permit(:model, :unique_id, :imei_number,:gcm_token) end end diff --git a/app/models/device.rb b/app/models/device.rb index d804c37..d798c9a 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -3,7 +3,7 @@ class Device < ActiveRecord::Base attr_accessor :status - validates :unique_id, :model, presence: true + validates :unique_id, :model, :gcm_token, presence: true validates :unique_id, uniqueness: true before_create :generate_access_token diff --git a/db/migrate/20151113095735_add_gcm_token_to_devices.rb b/db/migrate/20151113095735_add_gcm_token_to_devices.rb new file mode 100644 index 0000000..4c7038f --- /dev/null +++ b/db/migrate/20151113095735_add_gcm_token_to_devices.rb @@ -0,0 +1,5 @@ +class AddGcmTokenToDevices < ActiveRecord::Migration + def change + add_column :devices, :gcm_token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index cb9b8fb..917add2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151109072450) do +ActiveRecord::Schema.define(version: 20151113095735) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -58,6 +58,7 @@ ActiveRecord::Schema.define(version: 20151109072450) do t.datetime "updated_at", null: false t.integer "heartbeats_count", default: 0 t.datetime "last_heartbeat_recd_time" + t.string "gcm_token" end create_table "heartbeats", force: :cascade do |t| diff --git a/spec/factories/devices.rb b/spec/factories/devices.rb index 24a77b1..512d874 100644 --- a/spec/factories/devices.rb +++ b/spec/factories/devices.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :device do - model "Nexus 6" - unique_id "someuniqueid" - imei_number "someimeinumber" + model "LGE - Nexus 5" + unique_id "aa55589dd10a8819" + gcm_token "dAJukxHtV84iij0z5PJruUhcNnQSOl7NdeAWS9Y45UVhPoG1wRGp7i2Hp34SyrodDfdZieeDzbPusqYyFuEB_vAUl5EDyYqFdzMNF1JpN2ThkEl_dTawWP9F9rSsNadV1HZ" end end diff --git a/spec/models/device_spec.rb b/spec/models/device_spec.rb index 25a8445..a402544 100644 --- a/spec/models/device_spec.rb +++ b/spec/models/device_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Device, type: :model do it { should validate_presence_of :unique_id } it { should validate_presence_of :model } + it { should validate_presence_of :gcm_token } it { should validate_uniqueness_of :unique_id } describe "before create" do