Files
fizzy/test/models/card/closeable_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

35 lines
874 B
Ruby

require "test_helper"
class Card::CloseableTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
end
test "closed scope" do
assert_equal [ cards(:shipping) ], Card.closed
assert_not_includes Card.open, cards(:shipping)
end
test "close cards" do
assert_not cards(:logo).closed?
assert_difference -> { cards(:logo).events.count }, +1 do
cards(:logo).close(user: users(:kevin))
end
assert cards(:logo).closed?
assert cards(:logo).events.last.action.card_closed?
assert_equal users(:kevin), cards(:logo).closed_by
end
test "reopen cards" do
assert cards(:shipping).closed?
assert_difference -> { cards(:shipping).events.count }, +1 do
cards(:shipping).reopen
end
assert cards(:shipping).reload.open?
assert cards(:shipping).events.last.action.card_reopened?
end
end