<commit_before>require 'spec_helper'

describe 'Yt::Channel.where', :server do
  subject(:channels) { Yt::Channel.where id: channel_ids }

  context 'given multiple channel IDs' do
    let(:channel_ids) { [$existing_channel_id, $unknown_channel_id,
      $terminated_channel_id, $another_channel_id] }

    it 'returns the list of *existing* channels matching the conditions' do
      expect(channels).to be_present
      expect(channels).to all( be_a Yt::Channel )
      expect(channels.map &:id).to eq [$existing_channel_id, $another_channel_id]
    end

    it 'does not make any HTTP requests unless iterated' do
      expect(Net::HTTP).not_to receive(:start)
      channels
    end

    it 'makes as many HTTP requests as the number of channels divided by 50' do
      expect(Net::HTTP).to receive(:start).at_most(1).times.and_call_original
      channels.map &:id
    end

    it 'reuses the previous HTTP response if the request is the same' do
      expect(Net::HTTP).to receive(:start).once.and_call_original
      Yt::Channel.where(id: [$existing_channel_id]).map &:id
      Yt::Channel.where(id: [$existing_channel_id]).map &:id
    end

    it 'makes a new HTTP request if the request has changed' do
      expect(Net::HTTP).to receive(:start).twice.and_call_original
      Yt::Channel.where(id: [$existing_channel_id]).map &:id
      Yt::Channel.where(id: [$another_channel_id]).map &:id
    end

    it 'allocates at most one Yt::Relation object, no matter the requests' do<commit_msg>Fix test to not depend on test order<commit_after>require 'spec_helper'

describe 'Yt::Channel.where', :server do
  subject(:channels) { Yt::Channel.where id: channel_ids }

  context 'given multiple channel IDs' do
    let(:channel_ids) { [$existing_channel_id, $unknown_channel_id,
      $terminated_channel_id, $another_channel_id] }

    it 'returns the list of *existing* channels matching the conditions' do
      expect(channels).to be_present
      expect(channels).to all( be_a Yt::Channel )
      expect(channels.map &:id).to eq [$existing_channel_id, $another_channel_id]
    end

    it 'does not make any HTTP requests unless iterated' do
      expect(Net::HTTP).not_to receive(:start)
      channels
    end

    it 'makes as many HTTP requests as the number of channels divided by 50' do
      expect(Net::HTTP).to receive(:start).at_most(1).times.and_call_original
      channels.map &:id
    end

    it 'reuses the previous HTTP response if the request is the same' do
      expect(Net::HTTP).to receive(:start).once.and_call_original
      Yt::Channel.where(id: [$existing_channel_id]).map &:id
      Yt::Channel.where(id: [$existing_channel_id]).map &:id
    end

    it 'makes a new HTTP request if the request has changed' do
      expect(Net::HTTP).to receive(:start).twice.and_call_original
      Yt::Channel.where(id: [$unknown_channel_id]).map &:id
      Yt::Channel.where(id: [$another_channel_id]).map &:id
    end

    it 'allocates at most one Yt::Relation object, no matter the requests' do
{'fraction_non_alphanumeric': 0.11059602649006622, 'fraction_numerical': 0.001986754966887417, 'mean_word_length': 3.856913183279743, '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': '4481809', 'n_tokens_mistral': 964, 'n_tokens_neox': 917, 'n_words': 272}