Add scope AccountRole.active
This commit is contained in:
parent
2221710bdf
commit
3881972965
4 changed files with 6 additions and 2 deletions
|
@ -13,7 +13,7 @@ class Account < ApplicationRecord
|
||||||
self.adapter = Rolify::Adapter::Base.create 'role_adapter', role_cname, name
|
self.adapter = Rolify::Adapter::Base.create 'role_adapter', role_cname, name
|
||||||
|
|
||||||
has_many :account_roles,
|
has_many :account_roles,
|
||||||
-> { where deleted_at: nil },
|
-> { active },
|
||||||
inverse_of: :account,
|
inverse_of: :account,
|
||||||
dependent: :restrict_with_exception
|
dependent: :restrict_with_exception
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,6 @@
|
||||||
class AccountRole < ApplicationRecord
|
class AccountRole < ApplicationRecord
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
|
|
||||||
|
scope :active, -> { where(deleted_at: nil) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Role < ApplicationRecord
|
||||||
].map(&:freeze).freeze
|
].map(&:freeze).freeze
|
||||||
|
|
||||||
has_many :account_roles,
|
has_many :account_roles,
|
||||||
-> { where deleted_at: nil },
|
-> { active },
|
||||||
inverse_of: :role,
|
inverse_of: :role,
|
||||||
dependent: :restrict_with_exception
|
dependent: :restrict_with_exception
|
||||||
|
|
||||||
|
|
|
@ -5,4 +5,6 @@ require 'rails_helper'
|
||||||
RSpec.describe AccountRole do
|
RSpec.describe AccountRole do
|
||||||
it { is_expected.to belong_to :account }
|
it { is_expected.to belong_to :account }
|
||||||
it { is_expected.to belong_to :role }
|
it { is_expected.to belong_to :role }
|
||||||
|
|
||||||
|
pending '.active'
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue