超出范围错误,在rspec测试期间输入Type :: Integer

时间:2019-06-30 20:43:49

标签: ruby-on-rails ruby rspec

得到一个失败的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

1 个答案:

答案 0 :(得分:2)

在4字节的INT字段中,您最多可以存储2147483647整数。

7554736346861994060比2147483647大得多,因此占用的字节数超过4个字节。

您需要支持这种数字的其他数据类型。

添加迁移以将列更改为应该存储大量数字的BigInteger