From cf5c02626df191e4208ab91be7851f02d6633ca5 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Wed, 8 May 2019 21:46:17 +0200 Subject: [PATCH] Add AndroidDeviceRegistrationToken model belonging to user --- app/models/android_device_registration_token.rb | 3 +++ app/models/user.rb | 1 + ...192738_create_android_device_registration_tokens.rb | 10 ++++++++++ db/schema.rb | 10 +++++++++- spec/factories/android_device_registration_tokens.rb | 6 ++++++ spec/models/android_device_registration_token_spec.rb | 5 +++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/models/android_device_registration_token.rb create mode 100644 db/migrate/20190508192738_create_android_device_registration_tokens.rb create mode 100644 spec/factories/android_device_registration_tokens.rb create mode 100644 spec/models/android_device_registration_token_spec.rb diff --git a/app/models/android_device_registration_token.rb b/app/models/android_device_registration_token.rb new file mode 100644 index 0000000..13d34ea --- /dev/null +++ b/app/models/android_device_registration_token.rb @@ -0,0 +1,3 @@ +class AndroidDeviceRegistrationToken < ActiveRecord::Base + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index e4c4266..c6fdc7f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,6 +23,7 @@ class User < ActiveRecord::Base has_many :outgoing_requests, class_name: 'Request', foreign_key: 'creditor_id' has_many :notifications + has_many :android_device_registration_tokens, class_name: 'AndroidDeviceRegistrationToken', foreign_key: 'user_id' has_many :issued_transactions, as: :issuer, class_name: 'Transaction' diff --git a/db/migrate/20190508192738_create_android_device_registration_tokens.rb b/db/migrate/20190508192738_create_android_device_registration_tokens.rb new file mode 100644 index 0000000..75ee080 --- /dev/null +++ b/db/migrate/20190508192738_create_android_device_registration_tokens.rb @@ -0,0 +1,10 @@ +class CreateAndroidDeviceRegistrationTokens < ActiveRecord::Migration[5.2] + def change + create_table :android_device_registration_tokens do |t| + t.string :token + t.belongs_to :user, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b00571f..9381d88 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,15 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_06_20_161021) do +ActiveRecord::Schema.define(version: 2019_05_08_192738) do + + create_table "android_device_registration_tokens", force: :cascade do |t| + t.string "token" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_android_device_registration_tokens_on_user_id" + end create_table "clients", force: :cascade do |t| t.string "name", null: false diff --git a/spec/factories/android_device_registration_tokens.rb b/spec/factories/android_device_registration_tokens.rb new file mode 100644 index 0000000..6d17a2c --- /dev/null +++ b/spec/factories/android_device_registration_tokens.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :android_device_registration_token do + token "MyString" + user nil + end +end diff --git a/spec/models/android_device_registration_token_spec.rb b/spec/models/android_device_registration_token_spec.rb new file mode 100644 index 0000000..770cacf --- /dev/null +++ b/spec/models/android_device_registration_token_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe AndroidDeviceRegistrationToken, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end