Sha256: 8823813d34e032db48ef93319ce294fd72780c17d355c6109664e8f66a275cfe

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Location do
  before do
    @building = Building.create!(name: 'big house')

    1.upto(5) do |index|
      floor = Floor.create!(name: "#{index}. Floor")

      @building.children << floor

      1.upto(5) do |index_room|
        floor.children << Room.create!(name: "#{index_room}. Room")
      end
    end
  end

  describe 'building' do
    it 'has 30 descendants' do
      expect(@building.descendants.count).to eq(5 + (5 * 5))
    end

    context '::descendants_of' do
      context 'with Room' do
        let(:rooms) { Room.descendants_of(@building) }

        it 'has 25 rooms' do
          expect(rooms.count).to eq(25)
        end

        it 'alls be of type Room' do
          expect(rooms.all).to all(be_an(Room))
        end
      end

      context 'with Floor' do
        let(:floors) { Floor.descendants_of(@building) }

        it 'has 5 Floors' do
          expect(floors.count).to eq(5)
        end

        it 'alls be of type Floor' do
          expect(floors.all).to all(be_an(Floor))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_recursive_tree-3.2.0 spec/model/location_spec.rb
acts_as_recursive_tree-3.1.0 spec/model/location_spec.rb
acts_as_recursive_tree-3.0.0 spec/model/location_spec.rb