さて、私は Rails 4 で Postgres データベースを実行しています。私のモデルの 1 つで、Offer 属性:offer_status
はデフォルトで辞退する必要があります。ここに私の移行があります:
def change
create_table :offers do |t|
t.integer :offer_status, default: 0
t.timestamps null: false
end
この:offer_status
属性は、モデル内の列挙型を次のように参照します。
class Offer < ActiveRecord::Base
enum offer_status: [:declined, :accepted]
end
これら 2 つを用意して、新しく作成されたオファーのデフォルトoffer_status
が 0 になるかどうかを確認するテストを作成しました。
test "new offers should default to declined" do
@offer2=Offer.new()
assert @offer2.declined?
end
テスト中に byebug コンソールを呼び出して @offer2 を入力すると、次のようになります。
(byebug) o
<Offer id: nil, offer_status: nil, created_at: nil, updated_at: nil>
(byebug) exit
o=Offer.new()
ただし、 Rails コンソールでまったく同じ呼び出しを行うと、次のように返されます。
2.2.0 :001 > o=Offer.new
=> #<Offer id: nil, offer_status: 0, created_at: nil, updated_at: nil>
私の質問は、コンソールでは機能するのに、テストで失敗するのはなぜですか?