Skip to content

Commit

Permalink
Only render Monday-specific chores on Mondays
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 5, 2024
1 parent e0c6ed4 commit 8931bfb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 52 deletions.
1 change: 1 addition & 0 deletions app/models/daily_packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/daily_packet/pdf_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/daily_packet/producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
115 changes: 65 additions & 50 deletions spec/models/daily_packet/pdf_view_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8931bfb

Please sign in to comment.