, 나는이 있습니다레일 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
내가 잘못을 다음있어 또는 :
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가 있습니다. 하지만 컨트롤러 테스트를 실행하여 레코드를 얻는 이유는 무엇인지 모릅니다. 활성 레코드는 insert 문을 실행합니다. 이 문제를 어떻게 해결할 수 있습니까?
업데이트 : customerinfo 메서드의 모든 줄을 주석 처리하고 같은 테스트를 실행했습니다. 정확한 결과를 얻었다. 그래서 나는 그것을 내 방식의 행동이 아니라 Rails라고 추측하고 있습니까? 어떤 힌트?
고객 정보를 게시 할 수 있습니까? –
방금 게시했습니다. 모든 고객을 찾기 위해 activerecord를 사용합니다. 그게 전부입니다. 보기에 결과가 표시됩니다. – swingfuture