Sha256: 68d459be6d10b270dba397663331df4eb6551296e20720fb27154088a5f2eb60

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

shared_examples_for 'navigable' do # rubocop:disable Metrics/BlockLength
  let(:another_grandchild) { create factory }
  let(:child) { create factory }
  let(:child_sibling) { create factory }
  let(:grandchild) { create factory }
  let(:grandchild_sibling) { create factory }
  let(:grandchild_sibling_2) { create factory }
  let(:parent) { create factory }

  before(:all) do
    described_class.destroy_all
  end

  before do
    child.children << grandchild
    child.children << grandchild_sibling
    child.children << grandchild_sibling_2
    parent.children << child

    child_sibling.children << another_grandchild
    parent.children << child_sibling
  end

  describe '#parents' do
    it 'returns ancestors in reverse order' do
      expect(grandchild.parents).to eq [parent, child]
    end
  end

  describe '#previous' do
    xit 'returns previous sabling with lower level position' do
      expect(grandchild_sibling_2.previous).to eq grandchild_sibling
    end

    context 'when it is the first sibling' do
      it 'returns last element of previous node from parent level' do
        expect(another_grandchild.previous).to eq grandchild_sibling_2
      end
    end

    context 'when level position is nil' do
      before { child.update level_position: nil }

      it 'returns nil' do
        expect(child.previous).to be_nil
      end
    end
  end

  describe '#next' do
    it 'returns next sibling with higher level position' do
      expect(grandchild_sibling.next).to eq grandchild_sibling_2
    end

    context 'when it is the last sibling' do
      it 'returns first child of the next parent' do
        expect(grandchild_sibling_2.next).to eq another_grandchild
      end
    end

    context 'when level position is nil' do
      before { child.update level_position: nil }

      it 'returns nil' do
        expect(child.next).to be_nil
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lcms-engine-0.3.1 spec/support/concerns/navigable.rb
lcms-engine-0.1.4 spec/support/concerns/navigable.rb
lcms-engine-0.3.0 spec/support/concerns/navigable.rb
lcms-engine-0.1.3 spec/support/concerns/navigable.rb
lcms-engine-0.2.0 spec/support/concerns/navigable.rb
lcms-engine-0.1.2 spec/support/concerns/navigable.rb
lcms-engine-0.1.0 spec/support/concerns/navigable.rb