我正在尝试测试我的多态关联,但我似乎无法让它通过
模型:
class Foo < ApplicationRecord
belongs_to :bar, polymorphic: true, optional: true
end
Run Code Online (Sandbox Code Playgroud)
现在我的测试看起来像
RSpec.describe Foo, type: :model do
subject { build(:foo) }
it { is_expected.to belong_to(:bar) }
end
Run Code Online (Sandbox Code Playgroud)
我收到的错误
Foo
is expected to belong to bar required: true (FAILED - 1)
Failures:
> 1) Foo is expected to belong to bar required: true
> Failure/Error: it { is_expected.to belong_to(:bar) }
> Expected Foo to have a belongs_to association called bar (and for the record to fail validation if :bar …Run Code Online (Sandbox Code Playgroud)