Skip to content

Commit f0a2b36

Browse files
zachasmeclaude
andcommitted
Test that an import fails as invalid when a value is too long for its column
A 256-character account name raises ValueTooLong on MySQL and CheckViolation on SQLite, so removing either from the list now fails CI on that database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent becdfbe commit f0a2b36

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

‎test/models/account/data_transfer/record_set_test.rb‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,20 @@ def import_batch(files)
251251
assert_not Webhook.exists?(id: webhook_data["id"])
252252
end
253253

254-
test "import fails as invalid when a count is out of range for its column" do
255-
account_data = { "name" => "Overflow", "cards_count" => 2**63,
256-
"join_code" => { "code" => "ABCD-EFGH-IJKL", "usage_count" => 0, "usage_limit" => 10 } }
254+
test "import fails as invalid when a value is too long for its column" do
255+
error = assert_raises(Account::DataTransfer::RecordSet::IntegrityError) do
256+
import_account(build_account_data("name" => "a" * 256))
257+
end
257258

258-
tempfile = Tempfile.new([ "import_test", ".zip" ])
259-
tempfile.binmode
260-
writer = ZipFile::Writer.new(tempfile)
261-
writer.add_file("data/account.json", account_data.to_json)
262-
writer.close
263-
tempfile.rewind
259+
assert_match(/invalid data/i, error.message)
260+
end
264261

262+
test "import fails as invalid when a count is out of range for its column" do
265263
error = assert_raises(Account::DataTransfer::RecordSet::IntegrityError) do
266-
Account::DataTransfer::AccountRecordSet.new(importing_account).import(from: ZipFile::Reader.new(tempfile))
264+
import_account(build_account_data("cards_count" => 2**63))
267265
end
268266

269267
assert_match(/invalid data/i, error.message)
270-
ensure
271-
tempfile&.close
272-
tempfile&.unlink
273268
end
274269

275270
test "import fails as invalid when a user's email address doesn't validate" do
@@ -392,6 +387,24 @@ def exported_user_data
392387
}
393388
end
394389

390+
def build_account_data(overrides)
391+
{ "name" => "Imported", "join_code" => { "code" => "ABCD-EFGH-IJKL", "usage_count" => 0, "usage_limit" => 10 } }.merge(overrides)
392+
end
393+
394+
def import_account(account_data)
395+
tempfile = Tempfile.new([ "import_test", ".zip" ])
396+
tempfile.binmode
397+
writer = ZipFile::Writer.new(tempfile)
398+
writer.add_file("data/account.json", account_data.to_json)
399+
writer.close
400+
tempfile.rewind
401+
402+
Account::DataTransfer::AccountRecordSet.new(importing_account).import(from: ZipFile::Reader.new(tempfile))
403+
ensure
404+
tempfile&.close
405+
tempfile&.unlink
406+
end
407+
395408
def build_reader(dir:, data:, users: [])
396409
tempfile = Tempfile.new([ "import_test", ".zip" ])
397410
tempfile.binmode

0 commit comments

Comments
 (0)