ruby-on-rails - 在 rspec 测试期间,超出范围错误,Type::Integer
问题描述
得到一个失败的 rspec 测试,说活动记录超出范围。不知道为什么它失败了
这是错误
Failure/Error: Order.create! params.merge(user: user, subscription: subscription, product: product)
ActiveModel::RangeError:
7554736346861994060 is out of range for ActiveModel::Type::Integer with limit 4 bytes
rspec 测试
context 'subscription order params' do
let(:subscription_order_params) { FactoryBot.attributes_for(:order,
party_user_id: subscription_user.party_id,
party_subscription_id: subscription.party_id,
party_product_id: product.party_id)}
it 'creates an order that belongs to a subscription customer' do
post :create, params: { order: subscription_order_params }, as: :json
expect(response.status).to eq 204
end
end
解决方案
在一个 4 字节的INT
字段中,您最多可以存储一个2147483647
整数。
7554736346861994060 比这个大得多2147483647
,它需要超过 4 个字节。
您需要一种不同的数据类型来支持这样的数字。
添加迁移以更改BigInteger
应该存储大量数字的列。
推荐阅读
- javascript - SignalR 仅在 azure 上偶尔发送消息
- node.js - Javascript异步函数正在等待响应而不等待
- node.js - 将数据库从 Firebase 转移到 Mongodb 问题?
- laravel - 两个模型可以在 laravel 中使用同一张表吗
- terraform - 是否可以输出使用 Terraform 在循环中创建的所有 EC2 实例?
- java - Java 急切的单例创建线程安全吗?
- r - 创建字典并用它替换R中的拉丁词
- java - 如何查看分层窗格中的组件
- python - 爬取本地托管网站时出错
- java - 如何将 Java 转换为 Kotlin