Skip to content

Commit 4860fd4

Browse files
author
Adam Jazairi
authored
Merge pull request #752 from MITLibraries/etd-357-more-papertrail
ETD-357 Add papertrail to Thesis and User models
2 parents b831279 + 78eb4d1 commit 4860fd4

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

app/models/thesis.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#
2323

2424
class Thesis < ApplicationRecord
25+
has_paper_trail
26+
2527
belongs_to :copyright, optional: true
2628
belongs_to :license, optional: true
2729

app/models/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#
2020

2121
class User < ApplicationRecord
22+
has_paper_trail
23+
2224
# We need to initialize some fields before validation, or
2325
# the record won't save.
2426
before_validation(on: :create) do

test/models/thesis_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,21 @@ class ThesisTest < ActiveSupport::TestCase
735735
thesis.reload
736736
assert_equal 'Published', thesis.publication_status
737737
end
738+
739+
test 'editing thesis generates an audit trail' do
740+
t = theses(:one)
741+
assert_equal t.versions.count, 0
742+
t.title = 'updated'
743+
t.save
744+
assert_equal t.versions.count, 1
745+
assert_equal t.versions.last.event, 'update'
746+
end
747+
748+
test 'audit records include the changeset' do
749+
t = theses(:one)
750+
t.title = 'updated'
751+
t.save
752+
change = t.versions.last
753+
assert_equal change.changeset['title'], %w[MyString updated]
754+
end
738755
end

test/models/user_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,21 @@ class UserTest < ActiveSupport::TestCase
365365
u.reload
366366
assert_equal count - 1, u.editable_theses.count
367367
end
368+
369+
test 'editing user generates an audit trail' do
370+
u = users(:yo)
371+
assert_equal u.versions.count, 0
372+
u.given_name = 'Hello'
373+
u.save
374+
assert_equal u.versions.count, 1
375+
assert_equal u.versions.last.event, 'update'
376+
end
377+
378+
test 'audit records include the changeset' do
379+
u = users(:yo)
380+
u.given_name = 'Hello'
381+
u.save
382+
change = u.versions.last
383+
assert_equal change.changeset['given_name'], %w[Yo Hello]
384+
end
368385
end

0 commit comments

Comments
 (0)