Distinct Account#roles
This commit is contained in:
parent
ab7e160c20
commit
77568c425e
2 changed files with 19 additions and 1 deletions
|
@ -29,7 +29,9 @@ class Account < ApplicationRecord
|
|||
inverse_of: :account,
|
||||
dependent: :restrict_with_exception
|
||||
|
||||
has_many :roles, through: :account_roles
|
||||
has_many :roles,
|
||||
-> { distinct },
|
||||
through: :account_roles
|
||||
|
||||
belongs_to :person, optional: true
|
||||
|
||||
|
|
|
@ -179,6 +179,22 @@ RSpec.describe Account do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#roles' do
|
||||
subject { create :usual_account }
|
||||
|
||||
let(:role) { subject.add_role :superuser }
|
||||
|
||||
context 'when role is added twice' do
|
||||
before do
|
||||
AccountRole.create! account: subject, role: role
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.roles).to eq [role]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_role?' do
|
||||
subject { create :usual_account }
|
||||
|
||||
|
|
Reference in a new issue