Skip to content

Commit 5f06e76

Browse files
authored
adds auditing for school class (#460)
Closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/340 * Adds auditing for School Class
1 parent 0ba030e commit 5f06e76

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/models/school_class.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class SchoolClass < ApplicationRecord
99
validates :name, presence: true
1010
validate :teacher_has_the_school_teacher_role_for_the_school
1111

12+
has_paper_trail(
13+
meta: {
14+
meta_school_id: ->(cm) { cm.school&.id }
15+
}
16+
)
17+
1218
def self.teachers
1319
User.from_userinfo(ids: pluck(:teacher_id))
1420
end

spec/models/school_class_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe SchoolClass do
5+
RSpec.describe SchoolClass, versioning: true do
66
before do
77
stub_user_info_api_for(teacher)
88
end
@@ -150,4 +150,12 @@
150150
expect(pair).to eq([school_class, nil])
151151
end
152152
end
153+
154+
describe 'auditing' do
155+
subject(:school_class) { create(:school_class, teacher_id: teacher.id, school:) }
156+
157+
it 'enables auditing' do
158+
expect(school_class.versions.length).to(eq(1))
159+
end
160+
end
153161
end

0 commit comments

Comments
 (0)