8bb7783215
So that we can reuse in other scenarios
41 lines
1.3 KiB
Ruby
41 lines
1.3 KiB
Ruby
require "test_helper"
|
|
|
|
class Event::ActivitySummaryTest < ActiveSupport::TestCase
|
|
include VcrTestHelper
|
|
|
|
vcr_record!
|
|
|
|
setup do
|
|
@events = Event.limit(3)
|
|
|
|
# Make sure we fix dates since they change the prompt and this gets VCR confused
|
|
anchor_date = Time.zone.parse("2025-08-12 9am")
|
|
[ Event, Card, Comment ].each do |klass|
|
|
klass.update_all created_at: anchor_date
|
|
end
|
|
end
|
|
|
|
test "create summaries only once for a given set of events" do
|
|
summary = assert_difference -> { Event::ActivitySummary.count }, +1 do
|
|
Event::ActivitySummary.create_for(@events)
|
|
end
|
|
|
|
assert_no_difference -> { Event::ActivitySummary.count } do
|
|
assert_equal summary, Event::ActivitySummary.create_for(@events)
|
|
assert_equal summary, Event::ActivitySummary.create_for(@events.order("action desc").where(id: @events.ids)) # order does not matter
|
|
end
|
|
end
|
|
|
|
test "fetching a existing summary" do
|
|
assert_nil Event::ActivitySummary.for(@events)
|
|
|
|
summary = Event::ActivitySummary.create_for(@events)
|
|
assert_equal summary, Event::ActivitySummary.for(@events)
|
|
end
|
|
|
|
test "getting an HTML summary for a set of events" do
|
|
summary = Event::ActivitySummary.create_for(@events)
|
|
assert_includes summary.to_html, "layout"
|
|
end
|
|
end
|