2013-03-21 20:49:24 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class PaperTrailCleanerTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
test 'Baseline' do
|
|
|
|
@animal = Animal.create :name => 'Animal'
|
|
|
|
@animal.update_attributes :name => 'Animal from the Muppets'
|
|
|
|
@animal.update_attributes :name => 'Animal Muppet'
|
|
|
|
|
|
|
|
@dog = Dog.create :name => 'Snoopy'
|
|
|
|
@dog.update_attributes :name => 'Scooby'
|
|
|
|
@dog.update_attributes :name => 'Scooby Doo'
|
|
|
|
|
|
|
|
@cat = Cat.create :name => 'Garfield'
|
|
|
|
@cat.update_attributes :name => 'Garfield (I hate Mondays)'
|
|
|
|
@cat.update_attributes :name => 'Garfield The Cat'
|
2013-07-30 19:14:50 +00:00
|
|
|
assert_equal 9, PaperTrail::Version.count
|
2013-03-21 20:49:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'cleaner removes extra versions' do
|
|
|
|
@animal = Animal.create :name => 'Animal'
|
|
|
|
@animal.update_attributes :name => 'Animal from the Muppets'
|
|
|
|
@animal.update_attributes :name => 'Animal Muppet'
|
|
|
|
PaperTrail.clean_paper_trail_versions
|
2013-07-30 19:14:50 +00:00
|
|
|
assert_equal 1, PaperTrail::Version.all.count
|
2013-03-21 20:49:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'cleaner removes versions' do
|
|
|
|
@animal = Animal.create :name => 'Animal'
|
|
|
|
@animal.update_attributes :name => 'Animal from the Muppets'
|
|
|
|
@animal.update_attributes :name => 'Animal Muppet'
|
|
|
|
|
|
|
|
@dog = Dog.create :name => 'Snoopy'
|
|
|
|
@dog.update_attributes :name => 'Scooby'
|
|
|
|
@dog.update_attributes :name => 'Scooby Doo'
|
|
|
|
|
|
|
|
@cat = Cat.create :name => 'Garfield'
|
|
|
|
@cat.update_attributes :name => 'Garfield (I hate Mondays)'
|
|
|
|
@cat.update_attributes :name => 'Garfield The Cat'
|
|
|
|
PaperTrail.clean_paper_trail_versions
|
2013-07-30 19:14:50 +00:00
|
|
|
assert_equal 3, PaperTrail::Version.all.count
|
2013-03-21 20:49:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'cleaner keeps the correct (last) version' do
|
|
|
|
@animal = Animal.create :name => 'Animal'
|
|
|
|
@animal.update_attributes :name => 'Animal from the Muppets'
|
|
|
|
@animal.update_attributes :name => 'Animal Muppet'
|
|
|
|
PaperTrail.clean_paper_trail_versions
|
2013-07-30 19:14:50 +00:00
|
|
|
assert_equal 1, PaperTrail::Version.all.count
|
2013-03-21 20:49:24 +00:00
|
|
|
assert_equal "Animal Muppet", @animal.name
|
|
|
|
end
|
2013-07-17 00:55:39 +00:00
|
|
|
|
|
|
|
test 'cleaner accepts variable arguments' do
|
|
|
|
@animal = Animal.create :name => 'Animal'
|
|
|
|
@animal.update_attributes :name => 'Animal from the Muppets'
|
|
|
|
@animal.update_attributes :name => 'Animal Muppet'
|
|
|
|
PaperTrail.clean_paper_trail_versions(2)
|
2013-07-30 19:14:50 +00:00
|
|
|
assert_equal 2, PaperTrail::Version.all.count
|
2013-07-17 00:55:39 +00:00
|
|
|
assert_equal "Animal Muppet", @animal.name
|
|
|
|
end
|
2013-03-21 20:49:24 +00:00
|
|
|
end
|