mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Added tests for the new methods created for cleaning paper trail versions.
This commit is contained in:
parent
dfe5e319ab
commit
cd3f5f303e
1 changed files with 52 additions and 0 deletions
52
test/unit/cleaner_test.rb
Normal file
52
test/unit/cleaner_test.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
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'
|
||||
assert_equal 9, Version.count
|
||||
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
|
||||
assert_equal 1, Version.all.count
|
||||
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
|
||||
assert_equal 3, Version.all.count
|
||||
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
|
||||
assert_equal 1, Version.all.count
|
||||
assert_equal "Animal Muppet", @animal.name
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue