1
0
Fork 0

Add model UserOmniauth

This commit is contained in:
Alex Kotov 2018-12-04 08:08:33 +05:00
parent 57f1f91156
commit 1edf8b0241
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
6 changed files with 60 additions and 1 deletions

View File

@ -17,6 +17,8 @@ class User < ApplicationRecord
belongs_to :account
has_many :user_omniauths, dependent: :restrict_with_exception
validates :account_id, uniqueness: true
before_validation do

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class UserOmniauth < ApplicationRecord
belongs_to :user
validates :provider, presence: true, uniqueness: { scope: :remote_id }
validates :remote_id, presence: true
validates :email, presence: true
end

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
class CreateUserOmniauths < ActiveRecord::Migration[5.2]
def change
create_table :user_omniauths do |t|
t.timestamps null: false
t.references :user, foreign_key: true
t.string :provider, null: false
t.string :remote_id, null: false
t.string :email, null: false
t.index %i[remote_id provider], unique: true
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_12_04_030126) do
ActiveRecord::Schema.define(version: 2018_12_04_030414) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -128,6 +128,17 @@ ActiveRecord::Schema.define(version: 2018_12_04_030126) do
t.string "api_token", null: false
end
create_table "user_omniauths", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "user_id"
t.string "provider", null: false
t.string "remote_id", null: false
t.string "email", null: false
t.index ["remote_id", "provider"], name: "index_user_omniauths_on_remote_id_and_provider", unique: true
t.index ["user_id"], name: "index_user_omniauths_on_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -163,5 +174,6 @@ ActiveRecord::Schema.define(version: 2018_12_04_030126) do
add_foreign_key "passport_confirmations", "accounts"
add_foreign_key "passport_confirmations", "passports"
add_foreign_key "passport_maps", "passports"
add_foreign_key "user_omniauths", "users"
add_foreign_key "users", "accounts"
end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user_omniauth do
association :user
provider { 'github' }
remote_id { SecureRandom.hex }
email { Faker::Internet.email }
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe UserOmniauth do
subject { create :user_omniauth }
pending "add some examples to (or delete) #{__FILE__}"
end