From 8931bfb22853a15beb736325d56bede64ed02548 Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Mon, 4 Nov 2024 21:05:43 -0600 Subject: [PATCH] Only render Monday-specific chores on Mondays --- app/models/daily_packet.rb | 1 + app/models/daily_packet/pdf_view.rb | 2 +- app/models/daily_packet/producer.rb | 2 +- spec/models/daily_packet/pdf_view_spec.rb | 115 ++++++++++++---------- 4 files changed, 68 insertions(+), 52 deletions(-) diff --git a/app/models/daily_packet.rb b/app/models/daily_packet.rb index 9cc1c07..413807e 100644 --- a/app/models/daily_packet.rb +++ b/app/models/daily_packet.rb @@ -2,6 +2,7 @@ class DailyPacket < ApplicationRecord belongs_to :warm_fuzzy has_object :pdf_view + delegate :pdf_data, to: :pdf_view has_object :producer delegate :save_to_disk, :save_to_s3, to: :producer diff --git a/app/models/daily_packet/pdf_view.rb b/app/models/daily_packet/pdf_view.rb index 8169ac8..2e939fe 100644 --- a/app/models/daily_packet/pdf_view.rb +++ b/app/models/daily_packet/pdf_view.rb @@ -108,7 +108,7 @@ def draw_chore_list_page text "mow front" text "mow back" text "mow way back" - text "put out garbage cans" + text "put out garbage cans" if daily_packet.built_on.monday? text "wipe off kitchen table" text "run dishwasher" end diff --git a/app/models/daily_packet/producer.rb b/app/models/daily_packet/producer.rb index 9fb3155..ca3a8bc 100644 --- a/app/models/daily_packet/producer.rb +++ b/app/models/daily_packet/producer.rb @@ -19,7 +19,7 @@ def save_to_disk def save_to_s3 timestamp = daily_packet.built_on.strftime("%Y-%m-%d") s3_key = "daily-packets/#{timestamp}.pdf" - pdf_data = daily_packet.pdf_view.pdf_data + pdf_data = daily_packet.pdf_data S3Api.write(s3_key, pdf_data) end end diff --git a/spec/models/daily_packet/pdf_view_spec.rb b/spec/models/daily_packet/pdf_view_spec.rb index c363ddc..df084f9 100644 --- a/spec/models/daily_packet/pdf_view_spec.rb +++ b/spec/models/daily_packet/pdf_view_spec.rb @@ -1,55 +1,70 @@ require "rails_helper" describe DailyPacket::PdfView do - it "renders the document" do - warm_fuzzy = FactoryBot.create(:warm_fuzzy, received_at: Time.at(0)) - daily_packet = FactoryBot.create(:daily_packet, warm_fuzzy: warm_fuzzy) - view = DailyPacket::PdfView.new(daily_packet) - inspector = PDF::Inspector::Page.analyze(view.pdf_data) - - expect(inspector.pages.size).to eq 3 - - page_one_strings, page_two_strings, page_three_strings = inspector.pages.map { |page| page[:strings] } - - expect(page_one_strings).to eq([ - "Daily Packet ##{daily_packet.id}", - "07/07/2007", - "week 27", - "Random Warm Fuzzy", - "Alright Haircut", - "Your haircut is adequate.", - "- Wife, 01/01/1970", - "Reading Pace", - "7.7 pages/day", - "Feedbin Stats", - "unread: 9", - "oldest: 14 days ago" - ]) - - expect(page_two_strings).to eq([ - "Top Three", - "Personal", - "1. #{"_" * 40}", - "2. #{"_" * 40}", - "3. #{"_" * 40}", - "Work", - "1. #{"_" * 40}", - "2. #{"_" * 40}", - "3. #{"_" * 40}" - ]) - - expect(page_three_strings).to eq([ - "Chore List", - "unload dishwasher", - "collect laundry", - "defrost meat", - "poop patrol", - "mow front", - "mow back", - "mow way back", - "put out garbage cans", - "wipe off kitchen table", - "run dishwasher" - ]) + let(:warm_fuzzy) { FactoryBot.create(:warm_fuzzy, received_at: Time.at(0)) } + let(:daily_packet) { FactoryBot.create(:daily_packet, built_on: built_on, warm_fuzzy: warm_fuzzy) } + + context "on a Tuesday" do + let(:built_on) { Date.parse("2024-11-05") } + + it "renders the document" do + inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data) + + expect(inspector.pages.size).to eq 3 + + page_one_strings, page_two_strings, page_three_strings = inspector.pages.map { |page| page[:strings] } + + expect(page_one_strings).to eq([ + "Daily Packet ##{daily_packet.id}", + "11/05/2024", + "week 45", + "Random Warm Fuzzy", + "Alright Haircut", + "Your haircut is adequate.", + "- Wife, 01/01/1970", + "Reading Pace", + "7.7 pages/day", + "Feedbin Stats", + "unread: 9", + "oldest: 14 days ago" + ]) + + expect(page_two_strings).to eq([ + "Top Three", + "Personal", + "1. #{"_" * 40}", + "2. #{"_" * 40}", + "3. #{"_" * 40}", + "Work", + "1. #{"_" * 40}", + "2. #{"_" * 40}", + "3. #{"_" * 40}" + ]) + + expect(page_three_strings).to eq([ + "Chore List", + "unload dishwasher", + "collect laundry", + "defrost meat", + "poop patrol", + "mow front", + "mow back", + "mow way back", + "wipe off kitchen table", + "run dishwasher" + ]) + end + end + + context "on a Monday" do + let(:built_on) { Date.parse("2024-11-04") } + + it "renders the Monday-specific chore" do + inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data) + + _, _, page_three_strings = inspector.pages.map { |page| page[:strings] } + + expect(page_three_strings).to include "put out garbage cans" + end end end