Sha256: 9504d4e016e60cc5cff9e6335d1621f6c2bdeab3f34b6005af3c880f9c31e353

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe Vehicle do

  before {
    @vehicles = {
      :ford     => Car.create( :manufacturer => 'Ford' ),
      :bmw      => Car.create( :manufacturer => 'BMW' ),
      :daimler  => Truck.create( :manufacturer => 'Daimler' ),
      :volvo    => Truck.create( :manufacturer => 'Volvo' ),
      :kenworth => Truck.create( :manufacturer => 'Kenworth' )
    }
    @vehicles.each { |name, vehicle|
      vehicle.reload
      vehicle.update :parking_order_position => 0
    }
    @vehicles.each {|name, vehicle| vehicle.reload }
  }

  describe "ranking by STI parent" do

    before {
      @vehicles[:volvo].update :parking_order_position => :first
      @vehicles[:ford].update :parking_order_position => :first
    }

    describe "Vehicle" do

      subject { Vehicle.rank(:parking_order) }

      its(:size) { should == 5 }

      its(:first) { should == @vehicles[:ford] }

      its(:second) { should == @vehicles[:volvo] }

    end

  end

  describe "overriding parent's ranking" do

    describe "Vehicle" do

      it "should have one ranker object" do
        expect(Vehicle.rankers.count).to eq(1)
      end

      subject { Vehicle.rankers.first }

      its(:class_name) { should == 'Vehicle' }

      its(:column) { should == :parking_order }

    end

    describe "MotorBike" do

      it "should have one ranker object" do
        expect(MotorBike.rankers.count).to eq(1)
      end

      subject { MotorBike.rankers.first }

      its(:class_name) { should == 'Vehicle' }

      its(:column) { should == :parking_order }

      its(:with_same) { should == :color }

    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ranked-model-0.4.11 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.10 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.9 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.8 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.7 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.6 spec/sti-model/vehicle_spec.rb
ranked-model-0.4.5 spec/sti-model/vehicle_spec.rb