Files
fizzy/test/models/card/eventable/system_commenter_test.rb
T
Kevin McConnell 59dd8ca549 Make IDs more time-sortable in tests
In order for model ordering to work as expected in tests, we need to
keep two properties:

- Fixtures are all created in the past
- Models sort in the order that they were created

This allows us to do things like this:

    post cards_path, params: { ... }
    created_card = Card.last

When using UUIDv7 PKs rather than sequential integers, we have to make
sure a couple of things happen in order for this still to be true:

- Fixtures should generate deterministic IDs that translate to UUIDs
  that would have been created in the past (i.e. before today)
- Newly created objects must have enough precision in their timestamps
  so that they sort in the order they were created, and their random
  component doesn't come into play.

To solve this, we use the deterministic numeric ID as a number of
milliseconds after an early year. And we ensure that the new timestamps
we create have sub-millisecond precision.
2025-11-17 09:12:40 -05:00

54 lines
1.4 KiB
Ruby

require "test_helper"
class Card::Eventable::SystemCommenterTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
@card = cards(:text)
end
test "card_assigned" do
assert_system_comment "David assigned this to Kevin" do
@card.toggle_assignment users(:kevin)
end
end
test "card_unassigned" do
@card.toggle_assignment users(:kevin)
@card.comments.destroy_all # To skip deduplication logic
assert_system_comment "David unassigned from Kevin" do
@card.toggle_assignment users(:kevin)
end
end
test "card_closed" do
assert_system_comment "Moved to “Done” by David" do
@card.close
end
end
test "card_title_changed" do
assert_system_comment "David changed the title from “The text is too small” to “Make text larger”" do
@card.update! title: "Make text larger"
end
end
test "don't notify on system comments" do
@card.watch_by(users(:david))
assert_no_difference -> { Notification.count } do
@card.toggle_assignment users(:kevin)
end
end
private
def assert_system_comment(expected_comment)
assert_difference -> { @card.comments.count }, 1 do
yield
comment = @card.comments.last
assert comment.creator.system?
assert_match Regexp.new(expected_comment.strip, Regexp::IGNORECASE), comment.body.to_plain_text.strip
end
end
end