Skip to content

Commit 9445fed

Browse files
authored
Add auditing to roles (#491)
## Status - Related to RaspberryPiFoundation/digital-editor-issues#404 ## What's changed? Adds auditing to roles. ## Steps to perform after deploying to production N/A
1 parent 14f2f03 commit 9445fed

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/models/role.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class Role < ApplicationRecord
1010
validate :students_cannot_have_additional_roles
1111
validate :users_can_only_have_roles_in_one_school
1212

13+
has_paper_trail(
14+
meta: {
15+
meta_school_id: ->(cm) { cm.school&.id }
16+
}
17+
)
18+
1319
private
1420

1521
def students_cannot_have_additional_roles

spec/models/role_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rails_helper'
44

55
RSpec.describe Role do
6-
describe 'validations' do
6+
describe 'validations', versioning: true do
77
subject(:role) { build(:role) }
88

99
it 'has a valid default factory' do
@@ -39,6 +39,11 @@
3939
expect(duplicate_role).to be_invalid
4040
end
4141

42+
it 'enables auditing' do
43+
role.save
44+
expect(role.versions.length).to(eq(1))
45+
end
46+
4247
context 'when the student role exists for a user and school' do
4348
let(:user) { build(:user) }
4449
let(:school) { build(:school) }

0 commit comments

Comments
 (0)