小编use*_*339的帖子

如何使用shoulda匹配器来测试多态分析?

我正在使用带有rails的shoulda-matcher,我正在创建一个名为"comments"的模型和另一个名为"post"的模型.评论是多态的.

当我在帖子中使用shoulda匹配器进行测试时,就像这样

    it {should have_many(:comments)}
Run Code Online (Sandbox Code Playgroud)

它收到了这条消息

预期Post有一个名为comments的has_many关联(Comment没有post_id外键.)

在我的评论模型中,我有

  belongs_to :commentable, :polymorphic => true
Run Code Online (Sandbox Code Playgroud)

如何测试我的多态关联,以便帖子可以有很多注释?

ps the shoulda matcher文档说它支持多态关联.

polymorphism ruby-on-rails shoulda

16
推荐指数
1
解决办法
5200
查看次数

标签 统计

polymorphism ×1

ruby-on-rails ×1

shoulda ×1