Sha256: a2cc75527d3f7bd5d9788dcf98bbb7248a4f2aa96089b608b72d550700611697

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.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

5 entries across 5 versions & 1 rubygems

Version Path
acts_as_recursive_tree-4.1.0 spec/model/location_spec.rb
acts_as_recursive_tree-4.0.0 spec/model/location_spec.rb
acts_as_recursive_tree-3.5.0 spec/model/location_spec.rb
acts_as_recursive_tree-3.4.0 spec/model/location_spec.rb
acts_as_recursive_tree-3.3.0 spec/model/location_spec.rb