Sha256: 3f0205b89675321a149db8a1d3426b2b1d11f4244c24937f72146e5989c09234

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

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

Version data entries

9 entries across 9 versions & 6 rubygems

Version Path
houston-vestal_versions-2.0.1 spec/vestal_versions/version_spec.rb
houston-vestal_versions-2.0.0 spec/vestal_versions/version_spec.rb
vestal_versions-2.0.0 spec/vestal_versions/version_spec.rb
mil_vestal_versions-1.2.6 spec/vestal_versions/version_spec.rb
geothird_vestal_versions-1.2.5 spec/vestal_versions/version_spec.rb
geothird_vestal_versions-1.2.4 spec/vestal_versions/version_spec.rb
geothird_vestal_versions-1.2.3 spec/vestal_versions/version_spec.rb
set_vestal_versions-1.2.2 spec/vestal_versions/version_spec.rb
razenha-vestal_versions-1.2.2 spec/vestal_versions/version_spec.rb