Out of ranger error, Type::Integer during rspec test

Viewed 234

Getting a failed rspec test saying active record is out of range. Not sure why it's failing though

Heres the error

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 test

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 Answers

In a 4byte INT field you can store up to a 2147483647 integer.

7554736346861994060 is way bigger than 2147483647 thus, it takes more than 4bytes.

You need a different data type that can support such a number.

Add a migration to alter the column to BigInteger which is supposed to store the large number.

Related