1
0
Fork 0

Add scope AccountRole.active

This commit is contained in:
Alex Kotov 2019-02-02 09:35:08 +05:00
parent 2221710bdf
commit 3881972965
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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