<commit_before># frozen_string_literal: true

require 'rails_helper'

describe PlantingsController 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" 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)).to match [planting1, planting2] }
    end

    describe "picks up owner from params and shows owner's plantings only" do
      before { get :index, params: { member_slug: member1.slug } }

      it { expect(assigns(:owner)).to eq member1 }
      it { expect(assigns(:plantings)).to eq [planting1] }
    end

    describe "picks up crop from params and shows the plantings for the crop only" do
      before { get :index, params: { crop_slug: maize.slug } }

      it { expect(assigns(:crop)).to eq maize }
      it { expect(assigns(:plantings)).to eq [planting2] }
    end
  end

  describe "GET new" do
    describe "picks up crop from params" do
      let(:crop) { FactoryBot.create(:crop) }

      before { get :new, params: { crop_id: crop.id } }

      it { expect(assigns(:crop)).to eq(crop) }
    end

    describe "doesn't die if no crop specified" do<commit_msg>update plantings controller spec to look for a hash of searchkick results<commit_after># frozen_string_literal: true

require 'rails_helper'

describe PlantingsController 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" 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  { Planting.reindex }
    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 }
      it { expect(assigns(:plantings)[1]['slug']).to eq planting2.slug }
    end

    describe "picks up owner from params and shows owner's plantings only" do
      before { get :index, params: { member_slug: member1.slug } }

      it { expect(assigns(:owner)).to eq member1 }
      it { expect(assigns(:plantings).size).to eq 1 }
      it { expect(assigns(:plantings).first['slug']).to eq planting1.slug }
    end

    describe "picks up crop from params and shows the plantings for the crop only" do
      before { get :index, params: { crop_slug: maize.slug } }

      it { expect(assigns(:crop)).to eq maize }
      it { expect(assigns(:plantings).first['slug']).to eq planting2.slug }
    end
  end

  describe "GET new" do
    describe "picks up crop from params" do
      let(:crop) { FactoryBot.create(:crop) }

      before { get :new, params: { crop_id: crop.id } }

      it { expect(assigns(:crop)).to eq(crop) }
    end

    describe "doesn't die if no crop specified" do
{'fraction_non_alphanumeric': 0.11188142481472628, 'fraction_numerical': 0.007650011953143677, 'mean_word_length': 2.206130268199234, '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': '7240402', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1211, 'n_words': 329}