From 6bf87c243c4dfe03e466be24f3edc8341572a681 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 6 Nov 2017 22:38:48 +1300 Subject: [PATCH] Feature spec for crop predictions on crop#show --- spec/features/crops/crop_detail_page_spec.rb | 65 ++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index 5f0fa2ba4..e43a603e7 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -169,6 +169,71 @@ feature "crop detail page", js: true do end end + shared_examples "lots of harvests" do + def planting + FactoryBot.create :planting, crop: crop, planted_at: 100.days.ago, finished_at: 1.day.ago + end + before do + # 50 days to harvest + FactoryBot.create(:harvest, harvested_at: 50.days.ago, crop: crop, planting: planting) + # 20 days to harvest + FactoryBot.create(:harvest, harvested_at: 80.days.ago, crop: crop, planting: planting) + # 10 days to harvest + FactoryBot.create(:harvest, harvested_at: 90.days.ago, crop: crop, planting: planting) + planting.crop.plantings.each(&:update_harvest_days) + planting.crop.update_lifespan_medians + planting.crop.update_harvest_medians + end + it { is_expected.to have_text("First harvest expected after 20 days") } + it { is_expected.to have_text "Median Lifespan of #{crop.name} plants is 99 days" } + end + + subject do + visit crop_path(crop) + page + end + + context 'predictions' do + context 'crop is an annual' do + let(:crop) { FactoryBot.create :annual_crop } + + describe 'with no harvests' do + end + + describe 'with harvests' do + include_examples "lots of harvests" + end + it do + is_expected.to have_text( + "#{crop.name} is an annual crop (living and reproducing in a single year or less)" + ) + end + end + + context 'crop is perennial' do + let(:crop) { FactoryBot.create :perennial_crop } + + describe 'with no harvests' do + end + + describe 'with harvests' do + include_examples "lots of harvests" + end + it { is_expected.to have_text("#{crop.name} is a perennial crop (living more than two years)") } + end + + context 'crop perennial value is null' do + let(:crop) { FactoryBot.create :crop, perennial: nil } + + describe 'with no harvests' do + end + + describe 'with harvests' do + include_examples "lots of harvests" + end + end + end + context 'annual and perennial' do before { visit crop_path(crop) } context 'crop is an annual' do