Generate a DiceRoll when rolling
This commit is contained in:
parent
0658eca783
commit
5f682dff6e
|
@ -16,8 +16,10 @@ class Stat < ApplicationRecord
|
|||
numericality: true
|
||||
validate :validate_roll_command
|
||||
|
||||
def roll
|
||||
DiceRoller.new(roll_command, stat: self).roll
|
||||
def roll(table)
|
||||
result = DiceRoller.new(roll_command, stat: self).roll
|
||||
dice_rolls.create(result:, table:)
|
||||
result
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class DiceRollingTest < ActionDispatch::IntegrationTest
|
||||
test "rolling a stat should create a dice roll" do
|
||||
assert_changes("DiceRoll.count", +1) do
|
||||
stats(:strength).roll(tables(:dnd_table))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,6 +26,6 @@ class StatTest < ActiveSupport::TestCase
|
|||
test "rolls with roll_command" do
|
||||
stat = stats(:strength)
|
||||
stat.roll_command = "1d6"
|
||||
100.times { assert (1..6).cover?(stat.roll) }
|
||||
100.times { assert (1..6).cover?(stat.roll(tables(:dnd_table))) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue