Skip to content

Commit

Permalink
CV2-3916: log archived update (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy authored Apr 3, 2024
1 parent 587bee6 commit 008b540
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectMedia < ApplicationRecord

accepts_nested_attributes_for :media, :claim_description

has_paper_trail on: [:create, :update, :destroy], only: [:source_id], if: proc { |_x| User.current.present? }, versions: { class_name: 'Version' }
has_paper_trail on: [:create, :update, :destroy], only: [:source_id, :archived], if: proc { |_x| User.current.present? }, versions: { class_name: 'Version' }

include ProjectAssociation
include ProjectMediaAssociations
Expand Down Expand Up @@ -382,8 +382,9 @@ def get_project_media_sources
sources.to_json
end

def version_metadata(_changes)
meta = { source_name: self.source&.name }
def version_metadata(changes)
changes = begin JSON.parse(changes) rescue {} end
meta = changes.keys.include?('source_id') ? { source_name: self.source&.name } : {}
meta.to_json
end

Expand Down
6 changes: 5 additions & 1 deletion test/models/project_media_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ def setup
assert_difference 'PaperTrail::Version.count', 2 do
pm = create_project_media team: t, media: m, user: u, skip_autocreate_source: false
end
assert_equal 2, pm.versions.count
assert_difference 'PaperTrail::Version.count' do
pm.archived = CheckArchivedFlags::FlagCodes::SPAM
pm.save!
end
assert_equal 3, Version.from_partition(t.id).where(item_type: 'ProjectMedia', item_id: pm.id).count
pm.destroy!
v = Version.from_partition(t.id).where(item_type: 'ProjectMedia', item_id: pm.id, event: 'destroy').last
assert_not_nil v
Expand Down

0 comments on commit 008b540

Please sign in to comment.