Skip to content

Commit

Permalink
Add edition number to daily packets
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 6, 2024
1 parent 4fd0889 commit b69909e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/models/daily_packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ class DailyPacket < ApplicationRecord
delegate :save_to_disk, :save_to_s3, to: :producer

validates :built_on, presence: true
validates :edition_number, presence: true
validates :feedbin_oldest_ago, presence: true
validates :feedbin_unread_count, presence: true
validates :reading_list_pace, presence: true

def self.next_edition_number
(DailyPacket.maximum(:edition_number) || 0) + 1
end

def built_on_phrase
"#{built_on.to_fs}\nweek #{built_on.cweek}"
end
Expand All @@ -25,7 +30,7 @@ def feedbin_unread_phrase
end

def headline_phrase
"Daily Packet ##{id}"
"Daily Packet ##{edition_number}"
end

def reading_list_phrase
Expand Down
1 change: 1 addition & 0 deletions app/models/daily_packet/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.find_or_build_for(built_on)
warm_fuzzy = WarmFuzzy.random

attributes = {
edition_number: DailyPacket.next_edition_number,
feedbin_oldest_ago: feedbin_oldest_ago,
feedbin_unread_count: feedbin_unread_count,
reading_list_pace: reading_list.pace,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEditionNumberToDailyPackets < ActiveRecord::Migration[7.2]
def change
add_column :daily_packets, :edition_number, :integer, null: false, default: 0
end
end
1 change: 1 addition & 0 deletions spec/factories/daily_packet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :daily_packet do
built_on { Date.parse("2007-07-07") }
edition_number { 19 }
feedbin_oldest_ago { 14 }
feedbin_unread_count { 9 }
reading_list_pace { 7.7 }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/daily_packet/pdf_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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}",
"DAILY PACKET #19",
"11/05/2024",
"week 45",
"Random Warm Fuzzy",
Expand Down
25 changes: 25 additions & 0 deletions spec/models/daily_packet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,29 @@
expect(daily_packet).to be_valid
end
end

describe ".next_edition_number" do
context "with no DailyPacket records" do
it "returns 1" do
expect(DailyPacket.next_edition_number).to eq 1
end
end

context "with a DailyPacket record" do
it "returns the edition number after that record's value" do
FactoryBot.create(:daily_packet, edition_number: 7)
expect(DailyPacket.next_edition_number).to eq 8
end
end

context "with a few DailyPacket records" do
it "returns the edition number after the record with the highest value" do
FactoryBot.create(:daily_packet, edition_number: 1)
FactoryBot.create(:daily_packet, edition_number: 7)
FactoryBot.create(:daily_packet, edition_number: 3)

expect(DailyPacket.next_edition_number).to eq 8
end
end
end
end

0 comments on commit b69909e

Please sign in to comment.