Fix PaperTrail::Model::InstanceMethods#changed_notably? to return proper values when attrs are ignored
This commit is contained in:
parent
0dcdb32a44
commit
049a86f1ab
|
@ -367,8 +367,12 @@ module PaperTrail
|
|||
end
|
||||
|
||||
def changed_notably?
|
||||
if self.paper_trail_options[:ignore].any? && (changed & self.paper_trail_options[:ignore]).any?
|
||||
(notably_changed - timestamp_attributes_for_update_in_model.map(&:to_s)).any?
|
||||
else
|
||||
notably_changed.any?
|
||||
end
|
||||
end
|
||||
|
||||
def notably_changed
|
||||
only = self.paper_trail_options[:only].dup
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gadget do
|
||||
it { should be_versioned }
|
||||
|
||||
let(:gadget) { Gadget.create!(name: 'Wrench', brand: 'Acme') }
|
||||
|
||||
describe "updates", :versioning => true do
|
||||
it "should generate a version for updates to `name` attribute" do
|
||||
expect { gadget.update_attribute(:name, 'Hammer').to change{gadget.versions.size}.by(1) }
|
||||
end
|
||||
|
||||
it "should ignore for updates to `brand` attribute" do
|
||||
expect { gadget.update_attribute(:brand, 'Stanley') }.to_not change{gadget.versions.size}
|
||||
end
|
||||
|
||||
it "should still generate a version when only the `updated_at` attribute is updated" do
|
||||
expect { gadget.update_attribute(:updated_at, Time.now) }.to change{gadget.versions.size}.by(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Gadget < ActiveRecord::Base
|
||||
has_paper_trail :ignore => :brand
|
||||
end
|
|
@ -116,6 +116,12 @@ class SetUpTestTables < ActiveRecord::Migration
|
|||
t.string :language_code
|
||||
t.string :type
|
||||
end
|
||||
|
||||
create_table :gadgets, :force => true do |t|
|
||||
t.string :name
|
||||
t.string :brand
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
@ -136,5 +142,6 @@ class SetUpTestTables < ActiveRecord::Migration
|
|||
drop_table :documents
|
||||
drop_table :legacy_widgets
|
||||
drop_table :translations
|
||||
drop_table :gadgets
|
||||
end
|
||||
end
|
||||
|
|
|
@ -227,7 +227,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
'id' => [nil, @widget.id]
|
||||
}
|
||||
|
||||
assert_equal "Time", @widget.versions.last.changeset['updated_at'][1].class.to_s
|
||||
assert_equal Time, @widget.versions.last.changeset['updated_at'][1].class
|
||||
assert_equal changes, @widget.versions.last.changeset
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue