<commit_before>require 'rails_helper'

describe PageDecorator do
  describe '#options_for_parents' do
    before(:each) do
      @a = create(:page)
      @b = create(:page, parent: @a)
      @c = create(:page, parent: @a)
    end

    it 'selected' do
      expected = [
        [@a.description, @a.id],
        ["- #{@b.description}", @b.id],
        ["- #{@c.description}", @c.id]
      ]

      result = @b.decorate.options_for_parents
      expect(result).to eq expected
    end
  end

  describe '#path' do
    context 'without routes' do
      before(:each) do
        @team = create(:page)
        @team.seo(:nl).slug = 'team'
        @team.seo(:nl).save

        @devs = create(:page, parent: @team)
        @devs.seo(:nl).slug = 'devs'
        @devs.seo(:nl).save

        @foo = create(:page, parent: @devs)
        @foo.seo(:nl).slug = 'foo'
        @foo.seo(:nl).save
      end

      it 'first level' do
        expect(@team.decorate.path(locale: :nl)).to eq '/nl/team'
      end

      it 'second level' do
        expect(@devs.decorate.path(locale: :nl)).to eq '/nl/team/devs'
      end

      it 'third level' do
        expect(@foo.decorate.path(locale: :nl)).to eq '/nl/team/devs/foo'
      end
    end

    context 'with routes' do
      it 'first level' do
        page = create(:page, route: 'backend_path')
        expect(page.decorate.path).to eq '/backend'
      end

      describe 'second level' do
        it 'with route / without route' do
          backend = create(:page, route: 'backend_path')

          pages = create(:page, parent: backend)
          pages.seo.slug = 'pages'
          pages.seo.save

          expect(pages.decorate.path).to eq '/backend/pages'
        end

        it 'without route / with route' do
          backend = create(:page)
          backend.seo.slug = 'does-not-matter'
          backend.seo.save<commit_msg>Cleanup.<commit_after>require 'rails_helper'

describe PageDecorator do
  describe '#options_for_parents' do
    before(:each) do
      @a = create(:page)
      @b = create(:page, parent: @a)
      @c = create(:page, parent: @a)
    end

    it 'selected' do
      expected = [
        [@a.description, @a.id],
        ["- #{@b.description}", @b.id],
        ["- #{@c.description}", @c.id]
      ]

      result = @b.decorate.options_for_parents
      expect(result).to eq expected
    end
  end

  describe '#path' do
    describe 'without routes' do
      before(:each) do
        @team = create(:page)
        @team.seo(:nl).slug = 'team'
        @team.seo(:nl).save

        @devs = create(:page, parent: @team)
        @devs.seo(:nl).slug = 'devs'
        @devs.seo(:nl).save

        @foo = create(:page, parent: @devs)
        @foo.seo(:nl).slug = 'foo'
        @foo.seo(:nl).save
      end

      it 'first level' do
        expect(@team.decorate.path(locale: :nl)).to eq '/nl/team'
      end

      it 'second level' do
        expect(@devs.decorate.path(locale: :nl)).to eq '/nl/team/devs'
      end

      it 'third level' do
        expect(@foo.decorate.path(locale: :nl)).to eq '/nl/team/devs/foo'
      end
    end

    describe 'with routes' do
      it 'first level' do
        page = create(:page, route: 'backend_path')
        expect(page.decorate.path).to eq '/backend'
      end

      describe 'second level' do
        it 'with route / without route' do
          backend = create(:page, route: 'backend_path')

          pages = create(:page, parent: backend)
          pages.seo.slug = 'pages'
          pages.seo.save

          expect(pages.decorate.path).to eq '/backend/pages'
        end

        it 'without route / with route' do
          backend = create(:page)
          backend.seo.slug = 'does-not-matter'
          backend.seo.save
{'fraction_non_alphanumeric': 0.14728682170542637, 'fraction_numerical': 0.0, 'mean_word_length': 1.9792993630573248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4213964', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1223, 'n_words': 293}