私はRails 4(4.2.6)アプリケーションを構築していますが、今は 'リーフレットマップに印刷される興味のあるポイントを表すモデル。 DBとして、私たちはPostgresを 'pg'宝石で使っています(これはテストとは関係ありません)。 bundle exec rake test:models
Railsモデルテスト:ERROR:列[null]のnull値がnullでない制約に違反しています
class PlaceTest < ActiveSupport::TestCase
def setup
@place = Place.new(latitude: 12, longitude: 52, name: 'foo', categories: 'bar')
end
test 'valid place is valid' do
assert @place.valid?
end
を実行するときに残念なことに、エラーで次のような結果のようにも簡単なテストエラーがlatitude
がでnullではないので、私は、エラーをどのように解釈するか見当もつかない次
PlaceTest#test_valid_place_is_valid:
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "latitude" violates not-null constraint
DETAIL: Failing row contains (980190962, null, null, 2016-04-06 11:16:08, 2016-04-06 11:16:08, null, null).
: INSERT INTO "places" ("created_at", "updated_at", "id") VALUES ('2016-04-06 11:16:08', '2016-04-06 11:16:08', 980190962)
ですすべて。明らかに、インスタンスがdbに書き込まれていないため、データベース関連のエラーにはなりません。それにもかかわらず、エラーメッセージに何らかの形でこの音がします。
ActiveRecord::Schema.define(version: 20160403170121) do
enable_extension "plpgsql"
create_table "descriptions", force: :cascade do |t|
t.integer "place_id"
t.string "language"
t.text "text"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "descriptions", ["place_id"], name: "index_descriptions_on_place_id", using: :btree
create_table "places", force: :cascade do |t|
t.float "latitude", null: false
t.float "longitude", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", null: false
t.string "categories", null: false
end
add_foreign_key "descriptions", "places"
end
ところで:私は完全にレールコンソール内の場所のオブジェクトをインスタンス化し、.valid?
かどうかを確認することができますschema.rbファイルは次のようになります。私は誰かが私にそのエラーメッセージを解釈するのを助けることができたらうれしいだろう、事前にありがとう
編集:私はモデルファイル(実際にはsth私はテスト駆動を欲したい、正常に動作しています...)