tabletop-companion/test/models/stat_test.rb

32 lines
925 B
Ruby
Raw Normal View History

2024-06-07 14:38:10 +00:00
# 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
2024-06-11 13:55:39 +00:00
test "rolls with roll_command" do
stat = stats(:strength)
stat.roll_command = "1d6"
2024-06-13 12:03:34 +00:00
100.times { assert (1..6).cover?(stat.roll(tables(:dnd_table))) }
2024-06-11 13:55:39 +00:00
end
2024-06-07 14:38:10 +00:00
end