Article model file I have:
before_create :generate_token validates :token, presence: true private def generate_token self.token = SecureRandom.urlsafe_base64 end
And in my migration:
t.string :token, null: false
But now tests that create an article fail with
ActiveRecord::RecordInvalid: Validation failed: Token can't be blank. In these tests I indeed don't give a value for
token. However, shouldn't the
before_create method above do this automatically? It concerns test that call upon the
create method for a new author, of which the controller method includes the line
@author.articles.create! (so without a token value for the article).
P.S. I put the
debugger at the top of the
generate_token method, and it never fires for any of the tests.