Add model PassportConfirmation
This commit is contained in:
parent
3abf35dd0a
commit
734bfe1dc1
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PassportConfirmation < ApplicationRecord
|
||||||
|
belongs_to :passport
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
validates :user_id, uniqueness: { scope: :passport_id }
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreatePassportConfirmations < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :passport_confirmations do |t|
|
||||||
|
t.timestamps null: false
|
||||||
|
t.references :passport, null: false, foreign_key: true
|
||||||
|
t.references :user, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.index %i[passport_id user_id], 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_11_30_040846) do
|
ActiveRecord::Schema.define(version: 2018_11_30_075817) 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"
|
||||||
|
@ -51,6 +51,16 @@ ActiveRecord::Schema.define(version: 2018_11_30_040846) do
|
||||||
t.text "comment"
|
t.text "comment"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "passport_confirmations", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.bigint "passport_id", null: false
|
||||||
|
t.bigint "user_id", null: false
|
||||||
|
t.index ["passport_id", "user_id"], name: "index_passport_confirmations_on_passport_id_and_user_id", unique: true
|
||||||
|
t.index ["passport_id"], name: "index_passport_confirmations_on_passport_id"
|
||||||
|
t.index ["user_id"], name: "index_passport_confirmations_on_user_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "passports", force: :cascade do |t|
|
create_table "passports", 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
|
||||||
|
@ -120,6 +130,8 @@ ActiveRecord::Schema.define(version: 2018_11_30_040846) do
|
||||||
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
|
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "passport_confirmations", "passports"
|
||||||
|
add_foreign_key "passport_confirmations", "users"
|
||||||
add_foreign_key "user_roles", "roles"
|
add_foreign_key "user_roles", "roles"
|
||||||
add_foreign_key "user_roles", "users"
|
add_foreign_key "user_roles", "users"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :passport_confirmation do
|
||||||
|
passport
|
||||||
|
user
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe PassportConfirmation do
|
||||||
|
subject { create :passport_confirmation }
|
||||||
|
|
||||||
|
it { is_expected.to belong_to(:passport).required }
|
||||||
|
it { is_expected.to belong_to(:user).required }
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to validate_uniqueness_of(:user_id).scoped_to(:passport_id)
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue