Ensure Account::ExternalIdSequenceTest.value is never nil

If no record exists, create it. This fixes a test in fizzy-saas in
test/models/signup_test.rb that was not actually testing with a valid
external account id.
This commit is contained in:
Mike Dalessio
2025-11-28 14:27:14 -05:00
parent a8c4c0fb4b
commit 434a9671cc
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ class Account::ExternalIdSequence < ApplicationRecord
end
def value
first&.value
first&.value || self.next
end
private
@@ -39,4 +39,16 @@ class Account::ExternalIdSequenceTest < ActiveSupport::TestCase
assert_equal values.min..values.max, values.sort.first..values.sort.last
assert_equal 20, values.max - values.min + 1, "Values should be sequential with no gaps"
end
test "#value creates the first record if it doesn't yet exist" do
assert_nil Account::ExternalIdSequence.first
value = nil
assert_difference -> { Account::ExternalIdSequence.count }, 1 do
value = Account::ExternalIdSequence.value
end
assert_not_nil value
assert_equal value, Account::ExternalIdSequence.first.value
end
end