Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/fbe/bylaws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 Zerocracy
# SPDX-License-Identifier: MIT

require 'delegate'
require 'liquid'
require_relative '../fbe'

Expand Down Expand Up @@ -48,6 +49,7 @@
# # \"deduct ${fee} points\")
# # )"
def Fbe.bylaws(anger: 2, love: 2, paranoia: 2)
anger, love, paranoia = [anger, love, paranoia].map { |v| v.is_a?(Delegator) ? v.__getobj__ : v }
raise(Fbe::Error, "The 'anger' must be an Integer: #{anger.inspect}") unless anger.is_a?(Integer)
raise(Fbe::Error, "The 'anger' must be in the [0..4] interval: #{anger.inspect}") unless !anger.negative? && anger < 5
raise(Fbe::Error, "The 'love' must be an Integer: #{love.inspect}") unless love.is_a?(Integer)
Expand Down
19 changes: 19 additions & 0 deletions test/fbe/test_bylaws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 Zerocracy
# SPDX-License-Identifier: MIT

require 'factbase'
require 'judges/options'
require 'loog'
require 'tmpdir'
require_relative '../../lib/fbe/award'
require_relative '../../lib/fbe/bylaws'
require_relative '../../lib/fbe/pmp'
require_relative '../test__helper'

# Test.
Expand Down Expand Up @@ -236,4 +239,20 @@ def test_rejects_non_integer_levels
end
end
end

def test_accepts_levels_from_pmp
fb = Factbase.new
{ 'hr' => ['anger', 4], 'cost' => ['love', 1], 'quality' => ['paranoia', 3] }.each do |area, (name, value)|
f = fb.insert
f.what = 'pmp'
f.area = area
f.public_send(:"#{name}=", value)
end
pmp = Fbe.pmp(fb:, global: {}, options: Judges::Options.new, loog: Loog::NULL)
assert_equal(
Fbe.bylaws(anger: 4, love: 1, paranoia: 3),
Fbe.bylaws(anger: pmp.hr.anger, love: pmp.cost.love, paranoia: pmp.quality.paranoia),
'the levels from the PMP were not taken as Integers'
)
end
end
Loading