<commit_before>require 'spec_helper'

describe Jsonapi::Matchers::RecordIncluded do
  include Jsonapi::Matchers::Record

  let(:id) { }
  let(:record) { double(:record, {id: id}) }

  context 'expected is not a request object' do
    let(:subject) { have_record(record) }
    let(:response) { String.new }

    before do
      subject.matches?(response)
    end

    it 'tells you that the response is not an ActionController::TestResponse' do
      expect(subject.failure_message).to eq("Expected response to be ActionController::TestResponse or hash but was \"\"")
    end
  end

  context 'expected is not a json body' do
    let(:subject) { have_record(record) }
    let(:response) { ActionController::TestResponse.new(response_data.to_json) }
    let(:response_data) { nil }

    before do
      subject.matches?(response)
    end

    it 'tells you that the response body is not json' do
      expect(subject.failure_message).to eq("Expected response to be json string but was \"null\". JSON::ParserError - 757: unexpected token at 'null'")
    end
  end

  context 'checks :included' do
    let(:subject) { include_record(record) }
    let(:response) { ActionController::TestResponse.new(response_data.to_json) }
    let(:response_data) do
      {
        included: [{
          id: '3'
        }]
      }
    end

    context 'record is found' do
      let(:id) { '3' }

      it 'matches' do
        expect(subject.matches?(response)).to eq true
      end
    end

    context 'record is not found' do
      let(:id) { 'other_value' }

      it 'does not match' do
        expect(subject.matches?(response)).to eq false
      end<commit_msg>update ruby parse error code for newer ruby version<commit_after>require 'spec_helper'

describe Jsonapi::Matchers::RecordIncluded do
  include Jsonapi::Matchers::Record

  let(:id) { }
  let(:record) { double(:record, {id: id}) }

  context 'expected is not a request object' do
    let(:subject) { have_record(record) }
    let(:response) { String.new }

    before do
      subject.matches?(response)
    end

    it 'tells you that the response is not an ActionController::TestResponse' do
      expect(subject.failure_message).to eq("Expected response to be ActionController::TestResponse or hash but was \"\"")
    end
  end

  context 'expected is not a json body' do
    let(:subject) { have_record(record) }
    let(:response) { ActionController::TestResponse.new(response_data.to_json) }
    let(:response_data) { nil }

    before do
      subject.matches?(response)
    end

    it 'tells you that the response body is not json' do
      expect(subject.failure_message).to match("Expected response to be json string but was \"null\". JSON::ParserError - 776: unexpected token at 'null'")
    end
  end

  context 'checks :included' do
    let(:subject) { include_record(record) }
    let(:response) { ActionController::TestResponse.new(response_data.to_json) }
    let(:response_data) do
      {
        included: [{
          id: '3'
        }]
      }
    end

    context 'record is found' do
      let(:id) { '3' }

      it 'matches' do
        expect(subject.matches?(response)).to eq true
      end
    end

    context 'record is not found' do
      let(:id) { 'other_value' }

      it 'does not match' do
        expect(subject.matches?(response)).to eq false
      end
{'fraction_non_alphanumeric': 0.11194253217599522, 'fraction_numerical': 0.00299311583358276, 'mean_word_length': 2.9833134684147793, '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': '2960538', 'n_tokens_mistral': 1009, 'n_tokens_neox': 978, 'n_words': 295}