私は、機能テスト、テスト/機能/ cust_infos_controller_test.rbでのRails 3でアプリを書いて、私はこれらを持っている:それはちょうど見つけるとの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