こんにちは、私は私のような問題をいくつか見てきましたが、解決策のどれも私の問題を解決していないようです.
このモデルのMySQLデータベースにテーブルがあります:
class Client< ActiveRecord::Base
validates :name, :length => {:maximum => 255}, :presence => true
validates :client_status, inclusion: { in: 0..2, :presence => true }
validates :client_type, inclusion: { in: 0..2, :presence => true}
end
したがって、client_status と client_type は 0 から 2 の間の数値のみにする必要があります。これに対応するために書いた rspec を次に示します。
describe Client do
before do
@client = Client.new
end
it "should allow name that is less than 255 characters" do
long_char = 'a' *254
@client.name = long_char
@client.client_status = 0
@client.client_type = 1
@client.should be_valid
end
end
これは非常に単純なテストです。client_status と client_type の両方でプレゼンスが true であるため、RSPEC に追加する必要がありますが、この rspec を実行すると、次のエラー メッセージが表示されます。
got errors: Value type is not included in the list, Status is not included in the list
出力が何であるかを確認するために、これを試しました:
puts "client type is: #{@client.client_type} and status is: #{@client.client_status} ."
この出力を受け取りました:
client type is: false and status is: .
この長い投稿を読んでくれてありがとう。誰かが私のためにこの問題に光を当てることができることを本当に願っています。
注: 会社の NDA に違反しないように、モデル/rspec といくつかのフィールドの名前を変更しました。
よろしく、シュレップ