Я пишу приложение с Rails 3. В моем функциональном тесте test / functions / cust_infos_controller_test.rb у меня есть эти:
require 'test_helper'
class CustInfosControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "should get cust" do
get :customerinfo
assert_response :success
assert_not_nil assigns("cust_infos")
end
end
Мой контроллер довольно прост, поскольку он просто находит всю информацию о клиенте:
class CustInfosController < ApplicationController
def customerinfo
@cust_info = CustInfo.find(:all, :order=>"cust_id")
@cust_info.each do |ci|
if ci.upload_freq == 'W'
ci.upload_freq = 'Weekly'
elsif ci.upload_freq == 'M'
ci.upload_freq = 'Monthly'
end
end
end
end
Когда я запустил его с:
$ ruby -Itest test/functional/cust_infos_controller_test.rb
Я получил следующую ошибку:
Loaded suite test/functional/cust_infos_controller_test
Started
E
Finished in 0.025258 seconds.
1) Error:
test_should_get_cust(CustInfosControllerTest):
ActiveRecord::StatementInvalid: PGError: ERROR: numeric field overflow
DETAIL: A field with precision 4, scale 0 must round to an absolute value less than 10^4.
: INSERT INTO "cust_infos" ("cust_id") VALUES (298486374)
1 tests, 0 assertions, 0 failures, 1 errors
В моей таблице cust_infos у меня есть cust_id как целое число. Но я не знаю, почему, когда я запустил тест контроллера, чтобы получить какую-то запись, активная запись выполнит оператор вставки. Как мне это исправить?
ОБНОВЛЕНИЕ: Я закомментировал все строки в методе customerinfo и провел тот же тест. Получил точно такой же результат. Я предполагаю, что это не мои методы поведения, а скорее Rails? Любой намек?