Skip to content

Commit

Permalink
Merge pull request #1491 from internetee/1489-fix-ignored-columns-in-…
Browse files Browse the repository at this point in the history
…papertrail

Fix ignored attributes on history models
  • Loading branch information
vohmar authored Jan 27, 2020
2 parents 7d86362 + e4352d1 commit b572b82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/concerns/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def all_versions_for(ids, time)
preceding(time + 1, true).
select("distinct on (item_id) #{ver_klass.table_name}.*").
map do |ver|
o = new(ver.object)
valid_columns = ver.item_type.constantize&.column_names
o = new(ver.object&.slice(*valid_columns))
o.version_loader = ver
ver.object_changes.to_h.each { |k, v| o.public_send("#{k}=", v[-1]) }
o
Expand Down
28 changes: 28 additions & 0 deletions test/models/concerns/versions_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class VersionsTest < ActiveSupport::TestCase

def test_if_gets_all_versions_without_error_if_ignored_column_present
@nameserver = nameservers(:shop_ns1)
@nameserver.update(hostname: 'ns99.bestnames.test')
@ignored_column_title = Nameserver.ignored_columns.first

version = NameserverVersion.last
hash = version.object
hash[@ignored_column_title] = 123456
version.update(object: hash)

assert_nothing_raised do
Nameserver.all_versions_for([@nameserver.id], Time.zone.now)
end
end

def test_if_gets_all_versions_without_error_if_no_ignored_column
@account = accounts(:cash)
@account.update(currency: 'USD')

assert_nothing_raised do
Account.all_versions_for([@account.id], Time.zone.now)
end
end
end

0 comments on commit b572b82

Please sign in to comment.