I’m upgrading from Rails 4.2 to 6. I'm also using FactoryBot 6.2.0. I have this model
class Book < ActiveRecord::Base
belongs_to :author, inverse_of: :book
…
validates :model, presence: true, unless: -> { author.check_vwf? }
I have an RSpec (rspec-rails 4.1.2 ) test where I want to test an association …
describe Book do
…
it { should belong_to :author }
But running this test fails with the below error. It appears that the “validates” method is getting run and the instance being constructed has no “belongs_to” association, but that is exactly what I’m trying to test …
Failure/Error: validates :model, presence: true, unless: -> { author.check_vwf? }
NoMethodError:
undefined method `check_vwf?' for nil:NilClass
Something about upgrading my Rails caused this test to suddenly fail. What’s the proper way with the given version of Rails and RSpec to test an association?