<commit_before>require 'spec_helper'

describe Crop do
  it 'has a valid factory' do
    expect(FactoryGirl.create(:crop)).to be_valid
  end

  it 'requires a name' do
    expect(Crop.create(name: nil)).to_not be_valid
  end

  context '#search' do

    let!(:crop) { FactoryGirl.create(:crop, :radish) }

    it 'searches by name' do
      Crop.searchkick_index.refresh
      result = Crop.search('Common Horseradish').first
      expect(result).to eq(crop)
    end

    it 'searches by binomial name' do
      Crop.searchkick_index.refresh
      expect(Crop.search('Armoracia rusticana').first).to eq(crop)
    end

    it 'searches by description' do
      Crop.searchkick_index.refresh
      expect(Crop.search('Brassicaceae family').first).to eq(crop)
    end

    it 'displays the main_image_path' do
      expect(crop.main_image_path).to eq(nil)
      fancy_crop = FactoryGirl.create(:crop_picture).photographic
      expect(fancy_crop.main_image_path).to be_kind_of(String)
      expect(fancy_crop.main_image_path).to include("pictures/attachments")
    end
  end
end<commit_msg>Fix test for crops without set images<commit_after>require 'spec_helper'

describe Crop do
  it 'has a valid factory' do
    expect(FactoryGirl.create(:crop)).to be_valid
  end

  it 'requires a name' do
    expect(Crop.create(name: nil)).to_not be_valid
  end

  context '#search' do

    let!(:crop) { FactoryGirl.create(:crop, :radish) }

    it 'searches by name' do
      Crop.searchkick_index.refresh
      result = Crop.search('Common Horseradish').first
      expect(result).to eq(crop)
    end

    it 'searches by binomial name' do
      Crop.searchkick_index.refresh
      expect(Crop.search('Armoracia rusticana').first).to eq(crop)
    end

    it 'searches by description' do
      Crop.searchkick_index.refresh
      expect(Crop.search('Brassicaceae family').first).to eq(crop)
    end

    it 'displays the main_image_path' do
      expect(crop.main_image_path).to_not eq(nil)
      # TODO: test for placeholder image?
      fancy_crop = FactoryGirl.create(:crop_picture).photographic
      expect(fancy_crop.main_image_path).to be_kind_of(String)
      expect(fancy_crop.main_image_path).to include("pictures/attachments")
    end
  end
end
{'fraction_non_alphanumeric': 0.10204991087344029, 'fraction_numerical': 0.0, 'mean_word_length': 3.498997995991984, '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': '4117422', 'n_tokens_mistral': 797, 'n_tokens_neox': 756, 'n_words': 166}