rspec testing has_many :through and after_save

前端 未结 3 1498
小鲜肉
小鲜肉 2021-02-06 11:20

I have an (I think) relatively straightforward has_many :through relationship with a join table:

class User < ActiveRecord::Base
  has_many :user         


        
3条回答
  •  不知归路
    2021-02-06 12:08

    My guess is that you need to reload your Thing instance by doing @thing.reload (I'm sure there's a way to avoid this, but that might get your test passing at first and then you can figure out where you've gone wrong).

    Few questions:

    I don't see you calling @thing.save in your spec. Are you doing that, just like in your console example?

    Why are you calling t.save and not u.save in your console test, considering you're pushing t onto u? Saving u should trigger a save to t, getting the end result you want, and I think it would "make more sense" considering you are really working on u, not t.

提交回复
热议问题