test/creation_test.rb in vestal_versions-0.8.3 vs test/creation_test.rb in vestal_versions-1.0.0

- old
+ new

@@ -1,17 +1,17 @@ -require 'test_helper' +require File.join(File.dirname(__FILE__), 'test_helper') class CreationTest < Test::Unit::TestCase context 'The number of versions' do setup do @name = 'Steve Richert' @user = User.create(:name => @name) @count = @user.versions.count end - should 'initially equal one' do - assert_equal 1, @count + should 'initially equal zero' do + assert_equal 0, @count end should 'not increase when no changes are made in an update' do @user.update_attribute(:name, @name) assert_equal @count, @user.versions.count @@ -20,51 +20,91 @@ should 'not increase when no changes are made before a save' do @user.save assert_equal @count, @user.versions.count end - should 'not increase when reverting to the current version' do - @user.revert_to!(@user.version) - assert_equal @count, @user.versions.count - end - context 'after an update' do setup do - @initial_count = @count - @name = 'Steve Jobs' - @user.update_attribute(:name, @name) - @count = @user.versions.count + @user.update_attribute(:last_name, 'Jobs') end should 'increase by one' do - assert_equal @initial_count + 1, @count + assert_equal @count + 1, @user.versions.count end + end - should 'increase by one when reverted' do - @user.revert_to!(:first) - assert_equal @count + 1, @user.versions.count + context 'after multiple updates' do + setup do + @user.update_attribute(:last_name, 'Jobs') + @user.update_attribute(:last_name, 'Richert') end - should 'not increase until a revert is saved' do - @user.revert_to(:first) - assert_equal @count, @user.versions.count - @user.save - assert_not_equal @count, @user.versions.count + should 'increase multiple times' do + assert_operator @count + 1, :<, @user.versions.count end end + end - context 'after multiple updates' do + context "A created version's changes" do + setup do + @user = User.create(:name => 'Steve Richert') + @user.update_attribute(:last_name, 'Jobs') + end + + should 'not contain Rails timestamps' do + %w(created_at created_on updated_at updated_on).each do |timestamp| + assert_does_not_contain @user.versions.last.changes.keys, timestamp + end + end + + context '(with :only options)' do setup do - @initial_count = @count - @new_name = 'Steve Jobs' - @user.update_attribute(:name, @new_name) - @user.update_attribute(:name, @name) - @count = @user.versions.count + @only = %w(first_name) + User.prepare_versioned_options(:only => @only) + @user.update_attribute(:name, 'Steven Tyler') end - should 'not increase when reverting to an identical version' do - @user.revert_to!(:first) - assert_equal @count, @user.versions.count + should 'only contain the specified columns' do + assert_equal @only, @user.versions.last.changes.keys + end + + teardown do + User.prepare_versioned_options(:only => nil) + end + end + + context '(with :except options)' do + setup do + @except = %w(first_name) + User.prepare_versioned_options(:except => @except) + @user.update_attribute(:name, 'Steven Tyler') + end + + should 'not contain the specified columns' do + @except.each do |column| + assert_does_not_contain @user.versions.last.changes.keys, column + end + end + + teardown do + User.prepare_versioned_options(:except => nil) + end + end + + context '(with both :only and :except options)' do + setup do + @only = %w(first_name) + @except = @only + User.prepare_versioned_options(:only => @only, :except => @except) + @user.update_attribute(:name, 'Steven Tyler') + end + + should 'respect only the :only options' do + assert_equal @only, @user.versions.last.changes.keys + end + + teardown do + User.prepare_versioned_options(:only => nil, :except => nil) end end end end