Merge branch 'master' of https://github.com/stympy/paper_trail into stympy-master
* 'master' of https://github.com/stympy/paper_trail: Added :skip option.
This commit is contained in:
commit
d4e8525702
|
@ -40,6 +40,9 @@ module PaperTrail
|
||||||
class_attribute :ignore
|
class_attribute :ignore
|
||||||
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
||||||
|
|
||||||
|
class_attribute :skip
|
||||||
|
self.skip = ([options[:skip]].flatten.compact || []).map &:to_s
|
||||||
|
|
||||||
class_attribute :only
|
class_attribute :only
|
||||||
self.only = ([options[:only]].flatten.compact || []).map &:to_s
|
self.only = ([options[:only]].flatten.compact || []).map &:to_s
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_to_string(object)
|
def object_to_string(object)
|
||||||
object.attributes.to_yaml
|
object.attributes.except(*self.class.skip).to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_notably?
|
def changed_notably?
|
||||||
|
@ -203,7 +206,7 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_and_not_ignored
|
def changed_and_not_ignored
|
||||||
changed - self.class.ignore
|
changed - self.class.ignore - self.class.skip
|
||||||
end
|
end
|
||||||
|
|
||||||
def switched_on?
|
def switched_on?
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Article < ActiveRecord::Base
|
class Article < ActiveRecord::Base
|
||||||
has_paper_trail :ignore => :title,
|
has_paper_trail :ignore => :title,
|
||||||
:only => [:content],
|
:only => [:content],
|
||||||
|
:skip => [:file_upload],
|
||||||
:meta => {:answer => 42,
|
:meta => {:answer => 42,
|
||||||
:action => :action_data_provider_method,
|
:action => :action_data_provider_method,
|
||||||
:question => Proc.new { "31 + 11 = #{31 + 11}" },
|
:question => Proc.new { "31 + 11 = #{31 + 11}" },
|
||||||
|
|
|
@ -65,6 +65,7 @@ class SetUpTestTables < ActiveRecord::Migration
|
||||||
t.string :title
|
t.string :title
|
||||||
t.string :content
|
t.string :content
|
||||||
t.string :abstract
|
t.string :abstract
|
||||||
|
t.string :file_upload
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table :books, :force => true do |t|
|
create_table :books, :force => true do |t|
|
||||||
|
|
|
@ -29,6 +29,35 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
should_not_change('the number of versions') { Version.count }
|
should_not_change('the number of versions') { Version.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'which updates a skipped column' do
|
||||||
|
setup { @article.update_attributes :file_upload => 'Your data goes here' }
|
||||||
|
should_not_change('the number of versions') { Version.count }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'which updates a skipped column and a selected column' do
|
||||||
|
setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
|
||||||
|
should_change('the number of versions', :by => 1) { Version.count }
|
||||||
|
|
||||||
|
should 'have stored only non-skipped attributes' do
|
||||||
|
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and when updated again' do
|
||||||
|
setup do
|
||||||
|
@article.update_attributes :file_upload => 'More data goes here', :content => 'More text here.'
|
||||||
|
@old_article = @article.versions.last
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'have removed the skipped attributes when saving the previous version' do
|
||||||
|
assert_equal nil, YAML::load(@old_article.object)['file_upload']
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'have kept the non-skipped attributes in the previous version' do
|
||||||
|
assert_equal 'Some text here.', YAML::load(@old_article.object)['content']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue