mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Merge branch '74_method_defined' of https://github.com/edtsech/paper_trail into edtsech-74_method_defined
* '74_method_defined' of https://github.com/edtsech/paper_trail: #74: Changed method_defined? to column_names.include? & Fix test for case without object_changes column
This commit is contained in:
commit
2e49b5abd0
4 changed files with 5 additions and 16 deletions
|
@ -121,7 +121,7 @@ module PaperTrail
|
||||||
:object => object_to_string(item_before_change),
|
:object => object_to_string(item_before_change),
|
||||||
:whodunnit => PaperTrail.whodunnit
|
:whodunnit => PaperTrail.whodunnit
|
||||||
}
|
}
|
||||||
if Version.method_defined? :object_changes
|
if self.class.version_class_name.constantize.column_names.include?('object_changes')
|
||||||
# The double negative (reject, !include?) preserves the hash structure of self.changes.
|
# The double negative (reject, !include?) preserves the hash structure of self.changes.
|
||||||
data[:object_changes] = self.changes.reject do |key, value|
|
data[:object_changes] = self.changes.reject do |key, value|
|
||||||
!notably_changed.include?(key)
|
!notably_changed.include?(key)
|
||||||
|
|
|
@ -82,7 +82,7 @@ class Version < ActiveRecord::Base
|
||||||
# Returns what changed in this version of the item. Cf. `ActiveModel::Dirty#changes`.
|
# Returns what changed in this version of the item. Cf. `ActiveModel::Dirty#changes`.
|
||||||
# Returns nil if your `versions` table does not have an `object_changes` text column.
|
# Returns nil if your `versions` table does not have an `object_changes` text column.
|
||||||
def changeset
|
def changeset
|
||||||
if Version.method_defined?(:object_changes)
|
if self.class.column_names.include?('object_changes')
|
||||||
if changes = object_changes
|
if changes = object_changes
|
||||||
YAML::load(changes)
|
YAML::load(changes)
|
||||||
else
|
else
|
||||||
|
|
|
@ -47,11 +47,3 @@ def change_schema
|
||||||
end
|
end
|
||||||
ActiveRecord::Migration.verbose = true
|
ActiveRecord::Migration.verbose = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_object_changes_column
|
|
||||||
ActiveRecord::Migration.verbose = false
|
|
||||||
ActiveRecord::Schema.define do
|
|
||||||
remove_column :versions, :object_changes
|
|
||||||
end
|
|
||||||
ActiveRecord::Migration.verbose = true
|
|
||||||
end
|
|
||||||
|
|
|
@ -109,12 +109,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
assert_equal ({'name' => ['Henry', 'Harry']}), @widget.versions.last.changeset
|
assert_equal ({'name' => ['Henry', 'Harry']}), @widget.versions.last.changeset
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not have stored changes if object_changes column doesn't exist" do
|
|
||||||
remove_object_changes_column
|
|
||||||
Version.reset_column_information
|
|
||||||
assert_nil @widget.versions.last.changeset
|
|
||||||
end
|
|
||||||
|
|
||||||
if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without)
|
if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without)
|
||||||
should 'not clobber the IdentityMap when reifying' do
|
should 'not clobber the IdentityMap when reifying' do
|
||||||
module ActiveRecord::IdentityMap
|
module ActiveRecord::IdentityMap
|
||||||
|
@ -786,6 +780,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
setup { @post.update_attributes({ :content => "Some new content" }) }
|
setup { @post.update_attributes({ :content => "Some new content" }) }
|
||||||
should_change('the number of post versions') { PostVersion.count }
|
should_change('the number of post versions') { PostVersion.count }
|
||||||
should_not_change('the number of versions') { Version.count }
|
should_not_change('the number of versions') { Version.count }
|
||||||
|
should "not have stored changes when object_changes column doesn't exist" do
|
||||||
|
assert_nil @post.versions.last.changeset
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue