From a0d506435fdc505c7bd7b2092ebc2dc25c35de31 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 3 Jul 2025 00:22:17 -0400 Subject: [PATCH 1/3] Scatter Honcho seeds over a 30 day period to make the activity page look a bit more realistic --- db/seeds.rb | 3 +++ db/seeds/honcho.rb | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 1a38c8310..f299e949f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,5 +1,8 @@ raise "Seeding is just for development" unless Rails.env.development? +require "active_support/testing/time_helpers" +include ActiveSupport::Testing::TimeHelpers + # Seed DSL def seed_account(name) print " #{name}…" diff --git a/db/seeds/honcho.rb b/db/seeds/honcho.rb index 0276a2a8a..70cbf958d 100644 --- a/db/seeds/honcho.rb +++ b/db/seeds/honcho.rb @@ -50,19 +50,29 @@ collections = [ "Documentation" ] +time_range = (60 .. 30.days.in_minutes) + collections.each_with_index do |collection_name, index| create_collection(collection_name, access_to: authors.sample(3)).tap do |collection| # Create 20 unique cards for each collection card_titles.each do |title| - create_card(title, - description: "#{title} for #{collection_name} phase #{index + 1}.", - collection: collection - ).tap do |card| + travel(-rand(time_range).minutes) do + card = create_card title, + description: "#{title} for #{collection_name} phase #{index + 1}.", + collection: collection, + creator: authors.sample + # Randomly assign to 1-2 authors + travel rand(0..20).minutes card.toggle_assignment(authors.sample) - card.toggle_assignment(authors.sample) if rand > 0.5 + + if rand > 0.5 + travel rand(0..20).minutes + card.toggle_assignment(authors.sample) + end # Randomly set card state + travel rand(0..20).minutes case rand(3) when 0 card.engage From 31007c7bdb7987fe7461e47dd05245e2798b6eb0 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 3 Jul 2025 01:08:53 -0400 Subject: [PATCH 2/3] Create a "published" event if a card is created published This isn't the normal workflow in the app, but this problem will show up if we create cards programmatically (e.g., the seeds) --- app/models/card/statuses.rb | 2 ++ test/models/card/statuses_test.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/card/statuses.rb b/app/models/card/statuses.rb index 636d9127d..73d3f122a 100644 --- a/app/models/card/statuses.rb +++ b/app/models/card/statuses.rb @@ -4,6 +4,8 @@ module Card::Statuses included do enum :status, %w[ creating drafted published ].index_by(&:itself) + after_create -> { track_event :published }, if: :published? + scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) } end diff --git a/test/models/card/statuses_test.rb b/test/models/card/statuses_test.rb index 4f0c54312..5a3e2cb8b 100644 --- a/test/models/card/statuses_test.rb +++ b/test/models/card/statuses_test.rb @@ -25,6 +25,33 @@ class Card::StatusesTest < ActiveSupport::TestCase assert_includes Card.published_or_drafted_by(users(:jz)), card end + test "an event is created when a card is created in the published state" do + Current.session = sessions(:david) + + assert_no_difference(-> { Event.count }) do + collections(:writebook).cards.create! creator: users(:kevin), title: "Draft Card" + end + + assert_difference(-> { Event.count } => +1) do + @card = collections(:writebook).cards.create! creator: users(:kevin), title: "Published Card", status: :published + end + + assert_equal @card, Event.last.eventable + assert_equal "card_published", Event.last.action + end + + test "an event is created when a card is published" do + Current.session = sessions(:david) + + card = collections(:writebook).cards.create! creator: users(:kevin), title: "Published Card" + assert_difference(-> { Event.count } => +1) do + card.publish + end + + assert_equal card, Event.last.eventable + assert_equal "card_published", Event.last.action + end + test "can_recover_abandoned_creation?" do card = collections(:writebook).cards.create! creator: users(:kevin) unsaved_card = collections(:writebook).cards.new creator: users(:kevin) From a565504113bf45e38f9e3433e236f7f92310df56 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 3 Jul 2025 01:36:21 -0400 Subject: [PATCH 3/3] Fix activity feed pagination to fetch on demand Commit 01c642e6 restructured the page so that the "next page" link was always in view, meaning the page always loaded the entire history. Now we load the next day as the user scrolls to the bottom, as intended. --- app/views/events/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index 6d1521d45..9859f6533 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -36,5 +36,5 @@
<%= render "events/day", day_timeline: @day_timeline %> - <%= event_next_page_link(@day_timeline.next_day) %>
+<%= event_next_page_link(@day_timeline.next_day) %>