I have a User model that has options created in a callback after it is created.
# User has_one :user_options after_create :create_options private def create_options UserOptions.create(user: self) end
I have a simple rspec coverage for this:
describe "new user" do it "creates user_options after the user is created" do user = create(:user) user.user_options.should be_kind_of(UserOptions) end end
Everything worked until I added custom validation to the user model.
validate :check_whatever, if: :blah_blah
Now the specification fails, and the only way to do this is to reload the record in the specification:
it "creates user_preferences for the user" do user = create(:user) user.reload user.user_options.should be_kind_of(UserOptions) end
What is the reason for this?
source share