【问题标题】:Test that associated model exists测试关联模型是否存在
【发布时间】:2015-04-05 08:34:59
【问题描述】:

一个用户有一个个人资料。配置文件是在创建用户后创建的。如何使用 rspec 测试配置文件是否存在?

let(:user) { FactoryGirl.create(:student) }
subject { user }
it { is_expected.to be_valid }
it { is_expected.to (#profile exist))   # I don't know what goes here

【问题讨论】:

    标签: ruby-on-rails ruby rspec factory-bot rspec-rails


    【解决方案1】:

    您可能无法将其写在一行中。这是我的想法-

    let(:user) { FactoryGirl.create(:student) }
    subject { user }
    it { is_expected.to be_valid }
    expect(user.profile).to be_present
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多