Add model MembershipPoolAccount
This commit is contained in:
parent
cc037519b8
commit
56df5e5030
9 changed files with 105 additions and 1 deletions
|
@ -9,6 +9,10 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
has_many :passport_confirmations, dependent: :restrict_with_exception
|
has_many :passport_confirmations, dependent: :restrict_with_exception
|
||||||
|
|
||||||
|
has_many :membership_pool_accounts, dependent: :restrict_with_exception
|
||||||
|
|
||||||
|
has_many :membership_pools, through: :membership_pool_accounts
|
||||||
|
|
||||||
scope :guests, -> { includes(:user).where(users: { id: nil }) }
|
scope :guests, -> { includes(:user).where(users: { id: nil }) }
|
||||||
|
|
||||||
def guest?
|
def guest?
|
||||||
|
|
|
@ -5,5 +5,9 @@ class MembershipPool < ApplicationRecord
|
||||||
|
|
||||||
has_many :membership_apps, through: :membership_pool_apps
|
has_many :membership_apps, through: :membership_pool_apps
|
||||||
|
|
||||||
|
has_many :membership_pool_accounts, dependent: :restrict_with_exception
|
||||||
|
|
||||||
|
has_many :accounts, through: :membership_pool_accounts
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
end
|
end
|
||||||
|
|
8
app/models/membership_pool_account.rb
Normal file
8
app/models/membership_pool_account.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class MembershipPoolAccount < ApplicationRecord
|
||||||
|
belongs_to :membership_pool
|
||||||
|
belongs_to :account
|
||||||
|
|
||||||
|
validates :account_id, uniqueness: { scope: :membership_pool_id }
|
||||||
|
end
|
16
db/migrate/20181206205529_create_membership_pool_accounts.rb
Normal file
16
db/migrate/20181206205529_create_membership_pool_accounts.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateMembershipPoolAccounts < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :membership_pool_accounts do |t|
|
||||||
|
t.timestamps null: false
|
||||||
|
|
||||||
|
t.references :membership_pool, null: false, foreign_key: true
|
||||||
|
t.references :account, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.index %i[membership_pool_id account_id],
|
||||||
|
name: 'index_membership_pool_accounts_on_pool_and_account',
|
||||||
|
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_06_194527) do
|
ActiveRecord::Schema.define(version: 2018_12_06_205529) 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"
|
||||||
|
@ -77,6 +77,16 @@ ActiveRecord::Schema.define(version: 2018_12_06_194527) do
|
||||||
t.index ["country_state_id"], name: "index_membership_apps_on_country_state_id"
|
t.index ["country_state_id"], name: "index_membership_apps_on_country_state_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "membership_pool_accounts", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.bigint "membership_pool_id", null: false
|
||||||
|
t.bigint "account_id", null: false
|
||||||
|
t.index ["account_id"], name: "index_membership_pool_accounts_on_account_id"
|
||||||
|
t.index ["membership_pool_id", "account_id"], name: "index_membership_pool_accounts_on_pool_and_account", unique: true
|
||||||
|
t.index ["membership_pool_id"], name: "index_membership_pool_accounts_on_membership_pool_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "membership_pool_apps", force: :cascade do |t|
|
create_table "membership_pool_apps", 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
|
||||||
|
@ -187,6 +197,8 @@ ActiveRecord::Schema.define(version: 2018_12_06_194527) do
|
||||||
add_foreign_key "account_roles", "roles"
|
add_foreign_key "account_roles", "roles"
|
||||||
add_foreign_key "membership_apps", "accounts"
|
add_foreign_key "membership_apps", "accounts"
|
||||||
add_foreign_key "membership_apps", "country_states"
|
add_foreign_key "membership_apps", "country_states"
|
||||||
|
add_foreign_key "membership_pool_accounts", "accounts"
|
||||||
|
add_foreign_key "membership_pool_accounts", "membership_pools"
|
||||||
add_foreign_key "membership_pool_apps", "membership_apps"
|
add_foreign_key "membership_pool_apps", "membership_apps"
|
||||||
add_foreign_key "membership_pool_apps", "membership_pools"
|
add_foreign_key "membership_pool_apps", "membership_pools"
|
||||||
add_foreign_key "passport_confirmations", "accounts"
|
add_foreign_key "passport_confirmations", "accounts"
|
||||||
|
|
8
factories/membership_pool_accounts.rb
Normal file
8
factories/membership_pool_accounts.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :membership_pool_account do
|
||||||
|
association :membership_pool
|
||||||
|
association :account, factory: :account_with_user
|
||||||
|
end
|
||||||
|
end
|
|
@ -23,6 +23,18 @@ RSpec.describe Account do
|
||||||
.dependent(:restrict_with_exception)
|
.dependent(:restrict_with_exception)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
have_many(:membership_pool_accounts)
|
||||||
|
.dependent(:restrict_with_exception)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
have_many(:membership_pools)
|
||||||
|
.through(:membership_pool_accounts)
|
||||||
|
end
|
||||||
|
|
||||||
it { is_expected.not_to validate_presence_of :user }
|
it { is_expected.not_to validate_presence_of :user }
|
||||||
|
|
||||||
pending '.guests'
|
pending '.guests'
|
||||||
|
|
28
spec/models/membership_pool_account_spec.rb
Normal file
28
spec/models/membership_pool_account_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe MembershipPoolAccount do
|
||||||
|
subject { create :membership_pool_account }
|
||||||
|
|
||||||
|
it { is_expected.to belong_to :membership_pool }
|
||||||
|
it { is_expected.to belong_to :account }
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
validate_presence_of(:membership_pool)
|
||||||
|
.with_message(:required)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
validate_presence_of(:account)
|
||||||
|
.with_message(:required)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
validate_uniqueness_of(:account_id)
|
||||||
|
.scoped_to(:membership_pool_id)
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,5 +17,17 @@ RSpec.describe MembershipPool do
|
||||||
.through(:membership_pool_apps)
|
.through(:membership_pool_apps)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
have_many(:membership_pool_accounts)
|
||||||
|
.dependent(:restrict_with_exception)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to \
|
||||||
|
have_many(:accounts)
|
||||||
|
.through(:membership_pool_accounts)
|
||||||
|
end
|
||||||
|
|
||||||
it { is_expected.to validate_presence_of :name }
|
it { is_expected.to validate_presence_of :name }
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue