Files
growstuff/spec/features/planting_reminder_spec.rb
T
b3446f6cc7 Add basic HTML email layout with Growstuff branding and footer (#5035)
* Add HTML email layout with Growstuff branding and footer

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Add HTML email layout with Growstuff branding, call-to-action buttons, and footer

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Add previewer

* Update spec

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-10-26 04:41:43 +00:00

67 lines
2.9 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
require 'capybara/email/rspec'
describe "Planting reminder email" do
let(:member) { create(:member) }
let(:mail) { NotifierMailer.planting_reminder(member) }
let(:mail_body) { mail.body.encoded }
# 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_body).to have_content "planting your first crop"
end
it "doesn't list plantings" do
expect(mail_body).not_to have_css("section.progress")
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!(:recent_planting) { create(:predictable_planting, planted_at: 10.days.ago, garden: member.gardens.first, owner: member) }
let!(:older_planting) { create(:predictable_planting, planted_at: 30.days.ago, garden: member.gardens.first, owner: member) }
describe "lists plantings" do
it { expect(mail_body).to have_content "Progress report" }
it { expect(mail_body).to have_link recent_planting.crop.to_s, href: planting_url(recent_planting) }
it { expect(mail_body).to have_link older_planting.crop.to_s, href: planting_url(older_planting) }
it { expect(mail_body).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_body).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!(:recent_planting) { create(:predictable_planting, garden: member.gardens.first, owner: member, planted_at: 20.days.ago) }
let!(:older_planting) { create(:predictable_planting, garden: member.gardens.first, owner: member) }
let!(:recent_harvest) { create(:harvest, owner: member, planting: recent_planting, harvested_at: 1.day.ago) }
let!(:older_harvest) { create(:harvest, owner: member, planting: older_planting, harvested_at: 3.days.ago) }
describe "lists planting that are ready for harvest" do
it { expect(mail_body).to have_content "Ready to harvest" }
it { expect(mail_body).to have_link recent_planting.crop.name, href: planting_url(recent_planting) }
it { expect(mail_body).to have_link older_planting.crop.name, href: planting_url(older_planting) }
it { expect(mail_body).to have_content "Harvested anything lately?" }
end
end
end