<commit_before># frozen_string_literal: true

require 'rails_helper'

describe PlantingsController, :search do
  login_member

  def valid_attributes
    {
      garden_id: FactoryBot.create(:garden, owner: subject.current_member).id,
      crop_id: FactoryBot.create(:crop).id
    }
  end

  describe "GET index", :search do
    let!(:member1)   { FactoryBot.create(:member)                                                       }
    let!(:member2)   { FactoryBot.create(:member)                                                       }
    let!(:tomato)    { FactoryBot.create(:tomato)                                                       }
    let!(:maize)     { FactoryBot.create(:maize)                                                        }
    let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago }
    let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago }

    describe "assigns all plantings as @plantings" do
      before { get :index }

      it { expect(assigns(:plantings).size).to eq 2 }
      it { expect(assigns(:plantings)[0]['slug']).to eq planting1.slug }<commit_msg>Reindex before running plantings controller specs<commit_after># frozen_string_literal: true

require 'rails_helper'

describe PlantingsController, :search do
  login_member

  def valid_attributes
    {
      garden_id: FactoryBot.create(:garden, owner: subject.current_member).id,
      crop_id:   FactoryBot.create(:crop).id
    }
  end

  describe "GET index", :search do
    let!(:member1)   { FactoryBot.create(:member)                                                       }
    let!(:member2)   { FactoryBot.create(:member)                                                       }
    let!(:tomato)    { FactoryBot.create(:tomato)                                                       }
    let!(:maize)     { FactoryBot.create(:maize)                                                        }
    let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago }
    let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago }
    before do
      Planting.reindex
    end

    describe "assigns all plantings as @plantings" do
      before { get :index }

      it { expect(assigns(:plantings).size).to eq 2 }
      it { expect(assigns(:plantings)[0]['slug']).to eq planting1.slug }
{'fraction_non_alphanumeric': 0.10893512851897184, 'fraction_numerical': 0.00897592819257446, 'mean_word_length': 1.8678362573099416, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951405', 'n_tokens_mistral': 680, 'n_tokens_neox': 662, 'n_words': 145}