<commit_before>require 'spec_helper'

describe ShopsController, type: :controller do
  render_views

  let!(:distributor) { create(:distributor_enterprise) }
  let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }

  before do
    allow(Enterprise).to receive_message_chain(:distributors_with_active_order_cycles, :ready_for_checkout) { [distributor] }
  end

  # Exclusion from actual rendered view handled in features/consumer/home
  it "shows JSON for invisible hubs" do
    get :index
    expect(response.body).to have_content(invisible_distributor.name)
  end

  it 'renders distributed properties' do
    duplicate_property = create(:property, presentation: 'dairy')
    producer = create(:supplier_enterprise, properties: [duplicate_property])
    property = create(:property, presentation: 'dairy')
    product = create(:product, properties: [property])
    producer.supplied_products << product

    create(
      :simple_order_cycle,
      coordinator: distributor,
      suppliers: [producer],
      distributors: [distributor],
      variants: [product.variants]
    )

    get :index
<commit_msg>Cover product and producer props. in ctrl. spec<commit_after>require 'spec_helper'

describe ShopsController, type: :controller do
  render_views

  let!(:distributor) { create(:distributor_enterprise) }
  let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }

  before do
    allow(Enterprise).to receive_message_chain(:distributors_with_active_order_cycles, :ready_for_checkout) { [distributor] }
  end

  # Exclusion from actual rendered view handled in features/consumer/home
  it "shows JSON for invisible hubs" do
    get :index
    expect(response.body).to have_content(invisible_distributor.name)
  end

  it 'renders distributed product properties' do
    product_property = create(:property, presentation: 'eggs')
    product = create(:product, properties: [product_property])
    producer = create(:supplier_enterprise)

    create(
      :simple_order_cycle,
      coordinator: distributor,
      suppliers: [producer],
      distributors: [distributor],
      variants: [product.variants]
    )

    get :index

    expect(response.body)
      .to match(/"distributed_properties":\[{"id":\d+,"name":"eggs","presentation":"eggs"}\]/)
  end

  it 'renders distributed producer properties' do
    producer_property = create(:property, presentation: 'certified')
    producer = create(:supplier_enterprise, properties: [producer_property])
    product = create(:product)

    create(
      :simple_order_cycle,
      coordinator: distributor,
      suppliers: [producer],
      distributors: [distributor],
      variants: [product.variants]
    )

    get :index

    expect(response.body)
      .to match(/"distributed_properties":\[{"id":\d+,"name":"certified","presentation":"certified"}\]/)
  end

  it 'renders distributed properties' do
    duplicate_property = create(:property, presentation: 'dairy')
    producer = create(:supplier_enterprise, properties: [duplicate_property])
    property = create(:property, presentation: 'dairy')

    product = create(:product, properties: [property])
    producer.supplied_products << product

    create(
      :simple_order_cycle,
      coordinator: distributor,
      suppliers: [producer],
      distributors: [distributor],
      variants: [product.variants]
    )

    get :index

{'fraction_non_alphanumeric': 0.10859994129732903, 'fraction_numerical': 0.0, 'mean_word_length': 4.366929133858267, 'pattern_counts': {'":': 8, '<': 7, '<?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': '4217080', 'n_tokens_mistral': 1007, 'n_tokens_neox': 963, 'n_words': 223}