From 0297ae56230ae8f792245b479dd1bd0f9954de88 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 13:27:44 +0000 Subject: [PATCH 1/5] Fix plantings ICS feed regression and enable request spec - Update `app/views/plantings/index.ics.erb` to use ActiveRecord method calls instead of hash bracket access. - Enable `spec/requests/plantings_spec.rb` and update it to account for mirrored harvest events. - Add `config/initializers/faraday_patch.rb` to fix Searchkick/Faraday 2.x compatibility issues. Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com> --- app/views/plantings/index.ics.erb | 28 ++++++++++++++-------------- config/initializers/faraday_patch.rb | 10 ++++++++++ spec/requests/plantings_spec.rb | 15 ++++++++------- 3 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 config/initializers/faraday_patch.rb diff --git a/app/views/plantings/index.ics.erb b/app/views/plantings/index.ics.erb index 6fbb44d62e..0c4ffdffcc 100644 --- a/app/views/plantings/index.ics.erb +++ b/app/views/plantings/index.ics.erb @@ -7,29 +7,29 @@ cal.description = "Plantings by #{@owner.login_name}" event = Icalendar::Event.new lines = [] - lines << "Quantity: #{planting['quantity'] ? planting['quantity'] : 'unknown' }" - lines << "Planted on: #{planting['planted_at'] ? planting['planted_at'] : 'unknown' }" - lines << "Sunniness: #{planting['sunniness'] ? planting['sunniness'] : 'unknown' }" - lines << "Planted from: #{planting['planted_from'] ? planting['planted_from'] : 'unknown' }" - lines << "First harvest from: #{planting['first_harvest_predicted_at'] ? planting['first_harvest_predicted_at'] : 'unknown' }" - lines << "Last harvest from: #{planting['last_harvest_predicted_at'] ? planting['last_harvest_predicted_at'] : 'unknown' }" - lines << "Finish predicted at: #{planting['finish_predicted_at'] ? planting['finish_predicted_at'] : 'unknown'}" - lines << "Finished at: #{planting['finished_at'] ? planting['finished_at'] : 'unknown' }" + lines << "Quantity: #{planting.quantity || 'unknown' }" + lines << "Planted on: #{planting.planted_at || 'unknown' }" + lines << "Sunniness: #{planting.sunniness || 'unknown' }" + lines << "Planted from: #{planting.planted_from || 'unknown' }" + lines << "First harvest from: #{planting.first_harvest_predicted_at || 'unknown' }" + lines << "Last harvest from: #{planting.last_harvest_predicted_at || 'unknown' }" + lines << "Finish predicted at: #{planting.finish_predicted_at || 'unknown'}" + lines << "Finished at: #{planting.finished_at || 'unknown' }" lines << planting.description - finish_date = Date.parse(planting['finished_at'] || planting['finish_predicted_at'] || planting['last_harvest_predicted_at']) rescue nil + finish_date = (planting.finished_at || planting.finish_predicted_at || planting.last_harvest_predicted_at)&.to_date - event.dtstart = Time.at(planting['created_at']) - event.dtend = finish_date || 1.day.from_now + event.dtstart = planting.created_at + event.dtend = finish_date || 1.day.from_now.to_date event.summary = planting.crop.name event.description = lines.join("\n") event.ip_class = "PUBLIC" - event.url = planting_url(slug: planting['slug']) + event.url = planting_url(slug: planting.slug) cal.add_event(event) if finish_date && finish_date > Date.today - predicted_date = Date.parse(planting['first_harvest_predicted_at']) if planting['first_harvest_predicted_at'] + predicted_date = planting.first_harvest_predicted_at&.to_date todo = Icalendar::Todo.new todo.dtstart = predicted_date || finish_date || Date.today @@ -44,7 +44,7 @@ cal.description = "Plantings by #{@owner.login_name}" event.dtend = finish_date event.summary = "Harvest #{planting.crop.name}" event.ip_class = "PUBLIC" - event.url = planting_url(slug: planting['slug']) + event.url = planting_url(slug: planting.slug) cal.add_event(event) end diff --git a/config/initializers/faraday_patch.rb b/config/initializers/faraday_patch.rb new file mode 100644 index 0000000000..8815694319 --- /dev/null +++ b/config/initializers/faraday_patch.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Compatibility shim for Searchkick/Faraday 2.x +# See https://github.com/ankane/searchkick/issues/1628 +module Faraday + class Error < StandardError + ConnectionFailed = Faraday::ConnectionFailed + TimeoutError = Faraday::TimeoutError + end +end diff --git a/spec/requests/plantings_spec.rb b/spec/requests/plantings_spec.rb index 4516af117e..c94eebad7c 100644 --- a/spec/requests/plantings_spec.rb +++ b/spec/requests/plantings_spec.rb @@ -15,7 +15,7 @@ before do @member = create(:interesting_member) - @predictable_planting = create(:predictable_planting, owner: @member, planted_at: 1.days.ago, days_to_first_harvest: 10, + @predictable_planting = create(:predictable_planting, owner: @member, planted_at: 1.day.ago, days_to_first_harvest: 10, days_to_last_harvest: 20) @predictable_planting.crop.update(median_days_to_first_harvest: 10) @@ -27,25 +27,26 @@ end describe "GET /members/x/plantings.ics" do - it "works!", pending: "Regression from elasticsearch" do + it "works!" do get member_plantings_path(@member, format: "ics") calendar = Icalendar::Parser.new(response.body, true).parse.first expect(calendar.description[0].to_s).to eq "Plantings by #{@member.login_name}" events = calendar.events - expect(events.length).to eq 6 + # puts events.map { |e| [e.summary.to_s, e.dtstart.to_datetime, e.dtend.to_date, e.description.to_s] }.inspect + expect(events.length).to eq 7 # TODO: Better date comparison # Predicted finish should be used - expect(events[2].summary.to_s).to include @predictable_planting.crop.name - expect(events[2].dtstart.to_datetime.to_i).to be_within(1.second).of @predictable_planting.created_at.to_i - expect(events[2].dtend.to_date).to eq @predictable_planting.finish_predicted_at + predictable_event = events.find { |e| e.dtend.to_date == @predictable_planting.finish_predicted_at } + expect(predictable_event.summary.to_s).to include @predictable_planting.crop.name + expect(predictable_event.dtstart.to_datetime.to_i).to be_within(1.second).of @predictable_planting.created_at.to_i # Actual finish should be used # expect(events[4].dtend.to_date).to be_within(1.second).of @finished_planting.finished_at # Otherwise, tomorrow should be used - expect(events[3].dtend.to_date).to eq 1.day.from_now.to_date + expect(events.map { |e| e.dtend.to_date }).to include 1.day.from_now.to_date # TBA: Perennial and annual crops predictions of 'next' harvest date don't really fit From 7ab4928b5d33929120294d067e319302f450f4b8 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Wed, 24 Jun 2026 23:16:23 +0930 Subject: [PATCH 2/5] Delete config/initializers/faraday_patch.rb --- config/initializers/faraday_patch.rb | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 config/initializers/faraday_patch.rb diff --git a/config/initializers/faraday_patch.rb b/config/initializers/faraday_patch.rb deleted file mode 100644 index 8815694319..0000000000 --- a/config/initializers/faraday_patch.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -# Compatibility shim for Searchkick/Faraday 2.x -# See https://github.com/ankane/searchkick/issues/1628 -module Faraday - class Error < StandardError - ConnectionFailed = Faraday::ConnectionFailed - TimeoutError = Faraday::TimeoutError - end -end From 829154236536b32a61f023fddc0b1b9bbbc0e15c Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Wed, 24 Jun 2026 23:16:54 +0930 Subject: [PATCH 3/5] Apply suggestion from @CloCkWeRX --- spec/requests/plantings_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/requests/plantings_spec.rb b/spec/requests/plantings_spec.rb index c94eebad7c..be07f50925 100644 --- a/spec/requests/plantings_spec.rb +++ b/spec/requests/plantings_spec.rb @@ -33,7 +33,6 @@ calendar = Icalendar::Parser.new(response.body, true).parse.first expect(calendar.description[0].to_s).to eq "Plantings by #{@member.login_name}" events = calendar.events - # puts events.map { |e| [e.summary.to_s, e.dtstart.to_datetime, e.dtend.to_date, e.description.to_s] }.inspect expect(events.length).to eq 7 # TODO: Better date comparison From f15d5d07b39745465a96408de680f2508c1e87f3 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Wed, 24 Jun 2026 23:17:44 +0930 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Daniel O'Connor --- spec/requests/plantings_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/requests/plantings_spec.rb b/spec/requests/plantings_spec.rb index be07f50925..a676eb954b 100644 --- a/spec/requests/plantings_spec.rb +++ b/spec/requests/plantings_spec.rb @@ -35,7 +35,6 @@ events = calendar.events expect(events.length).to eq 7 - # TODO: Better date comparison # Predicted finish should be used predictable_event = events.find { |e| e.dtend.to_date == @predictable_planting.finish_predicted_at } expect(predictable_event.summary.to_s).to include @predictable_planting.crop.name From 43dcff8874c30b07b2c9f50352605bff6e8d1218 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Wed, 24 Jun 2026 23:18:02 +0930 Subject: [PATCH 5/5] Apply suggestion from @CloCkWeRX --- spec/requests/plantings_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/requests/plantings_spec.rb b/spec/requests/plantings_spec.rb index a676eb954b..e47b7752e2 100644 --- a/spec/requests/plantings_spec.rb +++ b/spec/requests/plantings_spec.rb @@ -35,7 +35,6 @@ events = calendar.events expect(events.length).to eq 7 - # Predicted finish should be used predictable_event = events.find { |e| e.dtend.to_date == @predictable_planting.finish_predicted_at } expect(predictable_event.summary.to_s).to include @predictable_planting.crop.name expect(predictable_event.dtstart.to_datetime.to_i).to be_within(1.second).of @predictable_planting.created_at.to_i