<commit_before># frozen_string_literal: true

require 'spec_helper'

RSpec.describe ActiveSet::PaginateProcessor::ActiveRecordAdapter do
  include_context 'for active record sets'

  let(:adapter) { described_class.new(active_record_set, instruction) }
  let(:instruction) { ActiveSet::Instructions::Entry.new(page, size) }

  subject { adapter.process[:set] }

  context 'when page size is smaller than set size' do
    let(:size) { 1 }

    context 'when on first page' do
      let(:page) { 1 }

      it { expect(subject.pluck(:id)).to eq [foo.id] }
    end

    context 'when on last page' do
      let(:page) { 2 }

      it { expect(subject.pluck(:id)).to eq [] }
    end

    context 'when on irrational page' do
      let(:page) { 10 }

      it { expect(subject.pluck(:id)).to eq [] }
    end
  end

  context 'when page size is equal to set size' do
    let(:size) { active_record_set.count }

    context 'when on only page' do
      let(:page) { 1 }

      it { expect(subject.pluck(:id)).to eq [foo.id, bar.id] }
    end

    context 'when on irrational page' do<commit_msg>Fix spec encoding expected behavior of bugged part of code<commit_after># frozen_string_literal: true

require 'spec_helper'

RSpec.describe ActiveSet::PaginateProcessor::ActiveRecordAdapter do
  include_context 'for active record sets'

  let(:adapter) { described_class.new(active_record_set, instruction) }
  let(:instruction) { ActiveSet::Instructions::Entry.new(page, size) }

  subject { adapter.process[:set] }

  context 'when page size is smaller than set size' do
    let(:size) { 1 }

    context 'when on first page' do
      let(:page) { 1 }

      it { expect(subject.pluck(:id)).to eq [foo.id] }
    end

    context 'when on last page' do
      let(:page) { 2 }

      it { expect(subject.pluck(:id)).to eq [bar.id] }
    end

    context 'when on irrational page' do
      let(:page) { 10 }

      it { expect(subject.pluck(:id)).to eq [] }
    end
  end

  context 'when page size is equal to set size' do
    let(:size) { active_record_set.count }

    context 'when on only page' do
      let(:page) { 1 }

      it { expect(subject.pluck(:id)).to eq [foo.id, bar.id] }
    end

    context 'when on irrational page' do
{'fraction_non_alphanumeric': 0.12168837000449034, 'fraction_numerical': 0.005388414907947912, 'mean_word_length': 3.088073394495413, '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': '4623028', 'n_tokens_mistral': 741, 'n_tokens_neox': 696, 'n_words': 215}