Testing Ruby on Rails Migrations

21-Mar-2019 1823
How do you test the code into the up method that creates a new record on a newly added association between User and Email before removing the email column from the User table?It’s a pretty common scenario and you could think that this logic should live into a separate object that you can test in isolation. I agree, but you still can’t really test it since if you call that object with the last version of your database schema (after this migration run), you’ll have an exception since User has no more the email column. 🤷‍This example is easily fixable by just stubbing the email message on any instance of User:.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle