Permalink
Browse files

Get the version spec working

  • Loading branch information...
1 parent 2cf731c commit 77c1e9a20be02f8ec6b30e6d0cfe431d798a2a16 @alexcrichton alexcrichton committed Nov 21, 2010
Showing with 61 additions and 61 deletions.
  1. +61 −0 spec/vestal_versions/version_spec.rb
  2. +0 −61 spec/vestal_versions/version_test.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe VestalVersions::Versions do
+ let(:user){ User.create(:name => 'Stephen Richert') }
+
+ before do
+ user.update_attribute(:name, 'Steve Jobs')
+ user.update_attribute(:last_name, 'Richert')
+ @first_version, @last_version = user.versions.first, user.versions.last
+ end
+
+ it 'is comparable to another version based on version number' do
+ @first_version.should == @first_version
+ @last_version.should == @last_version
+ @first_version.should_not == @last_version
+ @last_version.should_not == @first_version
+ @first_version.should < @last_version
+ @last_version.should > @first_version
+ @first_version.should <= @last_version
+ @last_version.should >= @first_version
+ end
+
+ it "is not equal a separate model's version with the same number" do
+ other = User.create(:name => 'Stephen Richert')
+ other.update_attribute(:name, 'Steve Jobs')
+ other.update_attribute(:last_name, 'Richert')
+ first_version, last_version = other.versions.first, other.versions.last
+
+ @first_version.should_not == first_version
+ @last_version.should_not == last_version
+ end
+
+ it 'defaults to ordering by number when finding through association' do
+ numbers = user.versions.map(&:number)
+ numbers.sort.should == numbers
+ end
+
+ it 'returns true for the "initial?" method when the version number is 1' do
+ version = user.versions.build(:number => 1)
+ version.number.should == 1
+ version.should be_initial
+ end
+
+ it "sreturn the version number if it is not a revert" do
+ user.version.should == user.versions.last.original_number
+ end
+
+ it "return the reverted_version if it is a revert" do
+ user.revert_to!(1)
+ user.versions.last.original_number.should == 1
+ end
+
+ it "return the original version if it is a double revert" do
+ user.revert_to!(2)
+ version = user.version
+ user.update_attributes(:last_name => 'Gates')
+ user.revert_to!(version)
+ user.versions.last.original_number.should == 2
+ end
+
+end
@@ -1,61 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
-
-class VersionTest < Test::Unit::TestCase
- context 'Versions' do
- setup do
- @user = User.create(:name => 'Stephen Richert')
- @user.update_attribute(:name, 'Steve Jobs')
- @user.update_attribute(:last_name, 'Richert')
- @first_version, @last_version = @user.versions.first, @user.versions.last
- end
-
- should 'be comparable to another version based on version number' do
- assert @first_version == @first_version
- assert @last_version == @last_version
- assert @first_version != @last_version
- assert @last_version != @first_version
- assert @first_version < @last_version
- assert @last_version > @first_version
- assert @first_version <= @last_version
- assert @last_version >= @first_version
- end
-
- should "not equal a separate model's version with the same number" do
- user = User.create(:name => 'Stephen Richert')
- user.update_attribute(:name, 'Steve Jobs')
- user.update_attribute(:last_name, 'Richert')
- first_version, last_version = user.versions.first, user.versions.last
- assert_not_equal @first_version, first_version
- assert_not_equal @last_version, last_version
- end
-
- should 'default to ordering by number when finding through association' do
- numbers = @user.versions.map(&:number)
- assert_equal numbers.sort, numbers
- end
-
- should 'return true for the "initial?" method when the version number is 1' do
- version = @user.versions.build(:number => 1)
- assert_equal 1, version.number
- assert_equal true, version.initial?
- end
-
- should "return the version number if it is not a revert" do
- assert_equal @user.version, @user.versions.last.original_number
- end
-
- should "return the reverted_version if it is a revert" do
- @user.revert_to!(1)
- assert_equal 1, @user.versions.last.original_number
- end
-
- should "return the original version if it is a double revert" do
- @user.revert_to!(2)
- version = @user.version
- @user.update_attributes(:last_name => 'Gates')
- @user.revert_to!(version)
- assert_equal 2, @user.versions.last.original_number
- end
-
- end
-end

0 comments on commit 77c1e9a

Please sign in to comment.