# frozen_string_literal: true require "test_helper" class StatTest < ActiveSupport::TestCase test "name must exist" do assert_must_exist(stats(:strength), :name) end test "value must exist" do assert_must_exist(stats(:strength), :value) end test "saving generates appropriate slug" do stat = Stat.create(name: "Foo", character_sheet_section: character_sheet_sections(:subsection)) assert_equal "stats-foo", stat.slug end test "generates unique slug always" do existing_stat = Stat.first stat = Stat.create(name: existing_stat.name, character_sheet_section: existing_stat.character_sheet_section) assert_not_equal existing_stat.slug, stat.slug assert_equal "#{existing_stat.slug}-2", stat.slug end test "rolls with roll_command" do stat = stats(:strength) stat.roll_command = "1d6" 100.times { assert (1..6).cover?(stat.roll(tables(:dnd_table))) } end end