Add model UserOmniauth
This commit is contained in:
parent
57f1f91156
commit
1edf8b0241
|
@ -17,6 +17,8 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
|
has_many :user_omniauths, dependent: :restrict_with_exception
|
||||||
|
|
||||||
validates :account_id, uniqueness: true
|
validates :account_id, uniqueness: true
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
|
|
|
@ -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
|
|
@ -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
|
14
db/schema.rb
14
db/schema.rb
|
@ -10,7 +10,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: 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -128,6 +128,17 @@ ActiveRecord::Schema.define(version: 2018_12_04_030126) do
|
||||||
t.string "api_token", null: false
|
t.string "api_token", null: false
|
||||||
end
|
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|
|
create_table "users", force: :cascade do |t|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_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", "accounts"
|
||||||
add_foreign_key "passport_confirmations", "passports"
|
add_foreign_key "passport_confirmations", "passports"
|
||||||
add_foreign_key "passport_maps", "passports"
|
add_foreign_key "passport_maps", "passports"
|
||||||
|
add_foreign_key "user_omniauths", "users"
|
||||||
add_foreign_key "users", "accounts"
|
add_foreign_key "users", "accounts"
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Reference in New Issue