Sha256: 12e94114d777d3bd04e973e8368d4babddf6119783aaff64432d6bd914acbe8d

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

# Since the gem provides model methods these tests serve as a kind of 'integration tests' for the gem
require 'spec_helper'

describe Car do
  before :each do
    @car = Car.create(:name => 'MyCar', :mass => 1000, :number_of_wheels => 4, :stick_shift => true)
  end
  
  it "creates parent-class records on create" do
    Vehicle.count.should eq 1
    MotorVehicle.count.should eq 1
    Car.count.should eq 1
    MotorCycle.count.should eq 0
  end

  it "updates properties of ancestor classes" do
    id = @car.id
    @car.name = 'Porsche'
    @car.fuel = 'gasoline'
    @car.convertible = true
    @car.save!
    car = Car.find(id)
    car.name.should eq 'Porsche'
    car.mass.should eq 1000
    car.fuel.should eq 'gasoline'
    car.stick_shift.should be_true
    car.convertible.should be_true
  end
  
  it "deletes parent-class records on destroy" do
    @car.destroy
    Vehicle.count.should eq 0
    MotorVehicle.count.should eq 0
    Car.count.should eq 0
  end
  
  it "converts to parent classes" do
    motor_vehicle = @car.convert_to(:motor_vehicle)
    motor_vehicle.class.name.should eq 'MotorVehicle'
    motor_vehicle.specialize.id.should eq @car.id
    vehicle = @car.convert_to(:vehicle)
    vehicle.class.name.should eq 'Vehicle'
    vehicle.specialize.id.should eq @car.id
  end
  
  it "doesn't convert to non-parent class" do
    @car.convert_to(:motor_cycle).should be_nil
  end
  
  it "correctly reports ascendants" do
    Car.cti_ascendants.should eq %w( Vehicle MotorVehicle ) 
  end
  
  it "correctly reports descendants" do
    Car.cti_all_descendants.should eq [] 
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dbview_cti-0.1.4 spec/models/car_spec.rb
dbview_cti-0.1.3 spec/models/car_spec.rb
dbview_cti-0.1.2 spec/models/car_spec.rb
dbview_cti-0.1.1 spec/models/car_spec.rb
dbview_cti-0.1.0 spec/models/car_spec.rb
dbview_cti-0.0.3 spec/models/car_spec.rb
dbview_cti-0.0.2 spec/models/car_spec.rb
dbview_cti-0.0.1 spec/models/car_spec.rb