tabletop-companion/test/models/stat_test.rb

34 lines
1.1 KiB
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))
2024-06-17 13:53:09 +00:00
assert_equal "stats-foo", stat.character_sheet_feature.slug
2024-06-07 14:38:10 +00:00
end
test "generates unique slug always" do
existing_stat = Stat.first
2024-06-17 13:53:09 +00:00
stat = Stat.create(name: existing_stat.name)
stat.build_character_sheet_feature(character_sheet_section: character_sheet_sections(:subsection))
stat.valid?
assert_not_equal existing_stat.character_sheet_feature.slug, stat.character_sheet_feature.slug
assert_equal "#{existing_stat.character_sheet_feature.slug}-2", stat.character_sheet_feature.slug
2024-06-07 14:38:10 +00:00
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