tabletop-companion/test/models/stat_test.rb

34 lines
1.1 KiB
Ruby

# 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.character_sheet_feature.slug
end
test "generates unique slug always" do
existing_stat = Stat.first
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
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