59dd8ca549
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.
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
require "test_helper"
|
|
|
|
class Boards::ColumnsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
sign_in_as :kevin
|
|
end
|
|
|
|
test "show" do
|
|
get board_column_path(boards(:writebook), columns(:writebook_in_progress))
|
|
assert_response :success
|
|
end
|
|
|
|
test "create" do
|
|
assert_difference -> { boards(:writebook).columns.count }, +1 do
|
|
post board_columns_path(boards(:writebook)), params: { column: { name: "New Column" } }, as: :turbo_stream
|
|
assert_response :success
|
|
end
|
|
|
|
assert_equal "New Column", boards(:writebook).columns.last.name
|
|
end
|
|
|
|
test "update" do
|
|
column = columns(:writebook_in_progress)
|
|
|
|
assert_changes -> { column.reload.name }, from: "In progress", to: "Updated Name" do
|
|
put board_column_path(boards(:writebook), column), params: { column: { name: "Updated Name" } }, as: :turbo_stream
|
|
assert_response :success
|
|
end
|
|
end
|
|
|
|
test "destroy" do
|
|
column = columns(:writebook_on_hold)
|
|
|
|
assert_difference -> { boards(:writebook).columns.count }, -1 do
|
|
delete board_column_path(boards(:writebook), column), as: :turbo_stream
|
|
assert_response :success
|
|
end
|
|
end
|
|
end
|