# frozen_string_literal: true require "test_helper" class TableTest < ActiveSupport::TestCase test "name must exist" do assert_must_exist(tables(:table), "name") end test "uuid must exist" do assert_must_exist(tables(:table), "uuid") end test "slug must be unique" do table1 = Table.first table2 = Table.second table1.slug = table2.slug assert_not table1.valid? end 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 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 end