Add GCM token field to device

This commit is contained in:
leenasn
2015-11-13 15:52:18 +05:30
parent 6dc20841c0
commit 93e3095925
6 changed files with 13 additions and 6 deletions

View File

@@ -19,6 +19,6 @@ class DevicesController < ApplicationController
private private
def device_params 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
end end

View File

@@ -3,7 +3,7 @@ class Device < ActiveRecord::Base
attr_accessor :status attr_accessor :status
validates :unique_id, :model, presence: true validates :unique_id, :model, :gcm_token, presence: true
validates :unique_id, uniqueness: true validates :unique_id, uniqueness: true
before_create :generate_access_token before_create :generate_access_token

View File

@@ -0,0 +1,5 @@
class AddGcmTokenToDevices < ActiveRecord::Migration
def change
add_column :devices, :gcm_token, :string
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -58,6 +58,7 @@ ActiveRecord::Schema.define(version: 20151109072450) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "heartbeats_count", default: 0 t.integer "heartbeats_count", default: 0
t.datetime "last_heartbeat_recd_time" t.datetime "last_heartbeat_recd_time"
t.string "gcm_token"
end end
create_table "heartbeats", force: :cascade do |t| create_table "heartbeats", force: :cascade do |t|

View File

@@ -1,7 +1,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :device do factory :device do
model "Nexus 6" model "LGE - Nexus 5"
unique_id "someuniqueid" unique_id "aa55589dd10a8819"
imei_number "someimeinumber" gcm_token "dAJukxHtV84iij0z5PJruUhcNnQSOl7NdeAWS9Y45UVhPoG1wRGp7i2Hp34SyrodDfdZieeDzbPusqYyFuEB_vAUl5EDyYqFdzMNF1JpN2ThkEl_dTawWP9F9rSsNadV1HZ"
end end
end end

View File

@@ -5,6 +5,7 @@ RSpec.describe Device, type: :model do
it { should validate_presence_of :unique_id } it { should validate_presence_of :unique_id }
it { should validate_presence_of :model } it { should validate_presence_of :model }
it { should validate_presence_of :gcm_token }
it { should validate_uniqueness_of :unique_id } it { should validate_uniqueness_of :unique_id }
describe "before create" do describe "before create" do