Rails: Shoulda-matchers belong_to optional test
For the first, you should read this conversation.
@mcmire We have a pre-release version out now! Try v4.0.0.rc1 to get optional.
And then, the expected code should look like this:
RSpec.describe Certificate, type: :model do it { should belong_to(:user) } it { should belong_to(:share_class).optional } it { should belong_to(:round).optional } it { should belong_to(:company).optional } it { should have_many(:approvals) } end
class Person < ActiveRecord::Base belongs_to :organization, optional: trueend# RSpecdescribe Person it { should belong_to(:organization).optional }end# Minitest (Shoulda)class PersonTest < ActiveSupport::TestCase should belong_to(:organization).optionalend