From cd3f5f303ea9c4a94d244f2b62941dd480bf6a33 Mon Sep 17 00:00:00 2001 From: Sean Marcia Date: Thu, 21 Mar 2013 16:49:24 -0400 Subject: [PATCH] Added tests for the new methods created for cleaning paper trail versions. --- test/unit/cleaner_test.rb | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/unit/cleaner_test.rb diff --git a/test/unit/cleaner_test.rb b/test/unit/cleaner_test.rb new file mode 100644 index 00000000..3a68ee1d --- /dev/null +++ b/test/unit/cleaner_test.rb @@ -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