私は、モデル プロデューサーがモデル ユーザーから派生し、モデル ユーザーが連絡先から派生する単一テーブル継承を使用します。連絡先とユーザーには、次のような検証があります。
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
連絡先と
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
ユーザーモデルで。
私の factory.rb では、FactoryGirl で一連の「プロデューサー」レコードを次のように構築しています。
factory :producer do
sequence(:name) { |n| "Producer #{n}" }
sequence(:email) { |n| "producer_#{n}@example.com"}
password "foobar"
password_confirmation "foobar"
end
次に、仕様で私は
let(:producer) { FactoryGirl.create(:producer) }
これは一見検証に合格していないようです:
1) Client
Failure/Error: let(:producer) { FactoryGirl.create(:producer) }
ActiveRecord::RecordInvalid:
Validation failed: Name can't be blank, Email can't be blank,
Email is invalid, Password digest can't blank, Password is too short
(minimum is 6 characters), Password confirmation can't be blank
FactoryGirl でフィールドが割り当てられていませんか?