78fc80cf35
* Allow Card#last_updated_at to be set This is useful when doing an import from another system. I'm currently working on a script to import our Github issues into Fizzy. This is discussed in https://github.com/basecamp/fizzy/pull/2056#discussion_r2609560246 * Add nil fallback and expand test coverage for last_active_at Adds a safety fallback to Time.current if created_at is unexpectedly nil during card creation. Test coverage to verify: * last_active_at defaults to created_at when not provided * last_active_at can be updated via API on existing cards * import workflow where last_active_at is restored after comments * publishing doesn't overwrite explicit last_active_at values --------- Co-authored-by: Jeremy Daer <jeremy@37signals.com>
58 lines
1.7 KiB
Ruby
58 lines
1.7 KiB
Ruby
require "test_helper"
|
|
|
|
class Card::EventableTest < ActiveSupport::TestCase
|
|
setup do
|
|
Current.session = sessions(:david)
|
|
end
|
|
|
|
test "new cards default last_active_at to created_at" do
|
|
freeze_time
|
|
|
|
card = boards(:writebook).cards.create!(title: "Some card", creator: users(:david))
|
|
assert_equal card.created_at, card.last_active_at
|
|
end
|
|
|
|
test "new cards with custom created_at default last_active_at to that time" do
|
|
custom_time = 1.week.ago.change(usec: 0)
|
|
|
|
card = boards(:writebook).cards.create!(title: "Backdated card", creator: users(:david), created_at: custom_time)
|
|
assert_equal custom_time, card.created_at
|
|
assert_equal custom_time, card.last_active_at
|
|
end
|
|
|
|
test "new cards preserve explicit last_active_at" do
|
|
created_time = 2.weeks.ago.change(usec: 0)
|
|
last_active_time = 1.week.ago.change(usec: 0)
|
|
|
|
card = boards(:writebook).cards.create! \
|
|
title: "Card with explicit timestamps",
|
|
creator: users(:david),
|
|
created_at: created_time,
|
|
last_active_at: last_active_time
|
|
|
|
assert_equal created_time, card.created_at
|
|
assert_equal last_active_time, card.last_active_at
|
|
end
|
|
|
|
test "publishing a card does not overwrite last_active_at" do
|
|
created_time = 2.weeks.ago.change(usec: 0)
|
|
last_active_time = 1.week.ago.change(usec: 0)
|
|
|
|
card = boards(:writebook).cards.create! \
|
|
title: "Published card",
|
|
creator: users(:david),
|
|
status: :published,
|
|
created_at: created_time,
|
|
last_active_at: last_active_time
|
|
|
|
assert_equal last_active_time, card.last_active_at
|
|
end
|
|
|
|
test "tracking events update the last activity time" do
|
|
travel_to Time.current
|
|
|
|
cards(:logo).close
|
|
assert_equal Time.current, cards(:logo).last_active_at
|
|
end
|
|
end
|