tabletop-companion/test/models/table_test.rb

36 lines
933 B
Ruby
Raw Normal View History

2024-05-28 11:08:19 +00:00
# frozen_string_literal: true
require "test_helper"
class TableTest < ActiveSupport::TestCase
test "name must exist" do
assert_must_exist(tables(:table), "name")
end
2024-05-28 19:40:51 +00:00
test "uuid must exist" do
assert_must_exist(tables(:table), "uuid")
2024-05-28 11:08:19 +00:00
end
test "slug must be unique" do
table1 = Table.first
table2 = Table.second
table1.slug = table2.slug
assert_not table1.valid?
end
2024-05-28 19:40:51 +00:00
test "creating adds UUID and slug" do
table = Table.create(name: "New table", game_system: GameSystem.first, owner: User.first)
table.reload
assert_not_nil table.uuid
assert_not_nil table.slug
assert table.slug.start_with?("new-table")
end
2024-05-29 08:09:58 +00:00
test "creating adds creator as a player" do
table = Table.create(name: "New table", game_system: GameSystem.first, owner: User.first)
table.reload
assert_equal 1, table.players.count
assert_equal User.first, table.players.first.user
end
2024-05-28 11:08:19 +00:00
end