Files
growstuff/spec/features/planting_reminder_spec.rb
Daniel O'Connor 8b4f0771c5 Ruby 3.2: Rubocop - Fix Negation matcher (#3780)
* Ruby 3.2/Bundler 2.4

* Fix creation

* Upgrade to js-routes 2. Put all js routes into a global namespace.

* Remove js-routes

* Remove

* Adjust ownership

* Appease codeclimate for the nth time

* Fix deprecation warning by explicitly calling to_fs

* Fix deprecation warning by explicitly calling to_fs

* Fix deprecation warning by explicitly calling to_fs

* Swap to will paginate successor for bootstrap

* Update app/views/members/show.html.haml

* Update app/views/plantings/index.rss.haml

* Update .env

* Update .devcontainer/.env

* Fix spec

* Update spec

* Fix spec

* Pin to 2.4.22

* 3 space indent

* Regenerate

* Update rubocop

* Rubocop

* More rubocop

* Regenerate

* Fix Capybara/NegationMatcher
2024-07-13 15:20:11 +09:30

66 lines
2.7 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
require 'capybara/email/rspec'
describe "Planting reminder email", :js do
let(:member) { create(:member) }
let(:mail) { NotifierMailer.planting_reminder(member) }
# Unfortunately, we can't use the default url options for ActionMailer as configured in
# test.rb, since this isn't a mailer spec.
def self.default_url_options
{ host: 'localhost', port: 8080 }
end
it "has a greeting" do
expect(mail).to have_content "Hello"
end
context "when member has no plantings" do
it "tells you to track your plantings" do
expect(mail).to have_content "planting your first crop"
end
it "doesn't list plantings" do
expect(mail).to have_no_content "Progress report"
end
end
context "when member has some plantings" do
# Bangs are used on the following 2 let blocks in order to ensure that the plantings are present
# in the database before the email is generated: otherwise, they won't be present in the email.
let!(:p1) { FactoryBot.create(:predictable_planting, planted_at: 10.days.ago, garden: member.gardens.first, owner: member) }
let!(:p2) { FactoryBot.create(:predictable_planting, planted_at: 30.days.ago, garden: member.gardens.first, owner: member) }
describe "lists plantings" do
it { expect(mail).to have_content "Progress report" }
it { expect(mail).to have_link p1.crop.to_s, href: planting_url(p1) }
it { expect(mail).to have_link p2.crop.to_s, href: planting_url(p2) }
it { expect(mail).to have_content "keep your garden records up to date" }
end
end
context "when member has no harvests" do
it "doesn't list plantings" do
expect(mail).to have_no_content "Ready to harvest"
end
end
context "when member has some harvests" do
# Bangs are used on the following 2 let blocks in order to ensure that the plantings are present
# in the database before the spec is run.
let!(:p1) { FactoryBot.create(:predictable_planting, garden: member.gardens.first, owner: member, planted_at: 20.days.ago) }
let!(:p2) { FactoryBot.create(:predictable_planting, garden: member.gardens.first, owner: member) }
let!(:h1) { FactoryBot.create(:harvest, owner: member, planting: p1, harvested_at: 1.day.ago) }
let!(:h2) { FactoryBot.create(:harvest, owner: member, planting: p2, harvested_at: 3.days.ago) }
describe "lists planting that are ready for harvest" do
it { expect(mail).to have_content "Ready to harvest" }
it { expect(mail).to have_link p1.crop.name, href: planting_url(p1) }
it { expect(mail).to have_link p2.crop.name, href: planting_url(p2) }
it { expect(mail).to have_content "Harvested anything lately?" }
end
end
end