<commit_before># frozen_string_literal: true
require 'spec_helper'

RSpec.describe Fastly do
  let(:version) { a_version(locked: false) }
  let(:service) { version.service }

  it 'creates a response_object' do
    name = SecureRandom.hex(3)

    response_object = client.response_objects.create(
      service_id: service.id,
      version_number: version.number,
      name: name,
      content_type: 'application/json',
      status: '404',
      response: 'ok',
      content: "{'error': ['not found']}",
    )

    expect(response_object.name).to eq(name)
    expect(response_object.reload.name).to eq(name)
  end

  describe 'with a response_object' do
    let!(:response_object) { a_response_object(version: version) }

    it 'updates a response_object' do
      new_content = SecureRandom.uuid

      copy = response_object.dup

      expect do
        response_object.update(content: new_content)
      end.to change(response_object, :content).from(response_object.content).to(new_content)
        .and change { copy.reload.content } .from(response_object.content).to(new_content)
    end

    it 'lists response_objects' do
      expect(version.response_objects.all).to include(response_object)
    end

    it 'destroys a response_object' do<commit_msg>test(response_object): refactor create_attributes<commit_after># frozen_string_literal: true
require 'spec_helper'

RSpec.describe Fastly do
  let(:version) { a_version(locked: false) }
  let(:service) { version.service }

  def create_attributes(overrides = {})
    {
      service_id: service.id,
      version_number: version.number,
      name: SecureRandom.hex(3),
      content_type: 'application/json',
      status: '404',
      response: 'ok',
      content: "{'error': ['not found']}",
    }.merge(overrides)
  end

  it 'creates a response_object' do
    name = SecureRandom.hex(3)

    response_object = client.response_objects.create(create_attributes(name: name))

    expect(response_object.name).to eq(name)
    expect(response_object.reload.name).to eq(name)
  end

  describe 'with a response_object' do
    let!(:response_object) { a_response_object(version: version) }

    it 'updates a response_object' do
      new_content = SecureRandom.uuid

      copy = response_object.dup

      expect do
        response_object.update(content: new_content)
      end.to change(response_object, :content).from(response_object.content).to(new_content)
        .and change { copy.reload.content } .from(response_object.content).to(new_content)
    end

    it 'lists response_objects' do
      expect(version.response_objects.all).to include(response_object)
    end

    it 'destroys a response_object' do
{'fraction_non_alphanumeric': 0.10854158895934353, 'fraction_numerical': 0.0033569563595673255, 'mean_word_length': 3.6643478260869564, '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': '2240599', 'n_tokens_mistral': 841, 'n_tokens_neox': 812, 'n_words': 174}