我正在写使用Rails 3应用程序在我的功能测试,测试/功能/ cust_infos_controller_test.rb,我有这些:的Rails 3控制器测试
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
我得到了以下ERR或:
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?任何提示?
您可以发布您的customerinfo方法吗? –
我刚发布了它。它使用activerecord查找所有客户。就是这样。视图将显示结果。 – swingfuture