1
0
Fork 0

Distinct Account#roles

This commit is contained in:
Alex Kotov 2019-07-08 18:13:54 +05:00
parent ab7e160c20
commit 77568c425e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 19 additions and 1 deletions

View file

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

View file

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