From be2ff202a3b53e32b32b9f83feac972c43754723 Mon Sep 17 00:00:00 2001 From: Edward Tsech Date: Sat, 23 Jul 2011 01:54:03 +0700 Subject: [PATCH] #74: Changed method_defined? to column_names.include? & Fix test for case without object_changes column --- lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version.rb | 2 +- test/test_helper.rb | 8 -------- test/unit/model_test.rb | 9 +++------ 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 931ef71e..3ea50117 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -114,7 +114,7 @@ module PaperTrail :object => object_to_string(item_before_change), :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. data[:object_changes] = self.changes.reject do |key, value| !notably_changed.include?(key) diff --git a/lib/paper_trail/version.rb b/lib/paper_trail/version.rb index 465bc7b1..86b6166a 100644 --- a/lib/paper_trail/version.rb +++ b/lib/paper_trail/version.rb @@ -82,7 +82,7 @@ class Version < ActiveRecord::Base # 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. def changeset - if Version.method_defined?(:object_changes) + if self.class.column_names.include?('object_changes') if changes = object_changes YAML::load(changes) else diff --git a/test/test_helper.rb b/test/test_helper.rb index bcdcd364..c4099b65 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -47,11 +47,3 @@ def change_schema end ActiveRecord::Migration.verbose = true 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 diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 23fc6c5c..b21483a3 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -109,12 +109,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase assert_equal ({'name' => ['Henry', 'Harry']}), @widget.versions.last.changeset 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) should 'not clobber the IdentityMap when reifying' do module ActiveRecord::IdentityMap @@ -786,6 +780,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase setup { @post.update_attributes({ :content => "Some new content" }) } should_change('the number of post versions') { PostVersion.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