A curious Ruby and Elixir developer with a strong passion for Linux and OSS.
Using PostgreSQL's temporary tables with RSpec
Let’s say you have a new ActiveRecord concern to add a new feature to your models. This concern extracts a database behavior. For simplicity, we are going to use a database query for tagging:
How do you test concerns in isolation without including them in an application model?
PostgreSQL is packed full of wonderful features. One of those features is hidden in the CREATE TABLE synopsis:
Using this in Rails is pretty straightforward because create_table accepts :temporary as boolean argument to mark the table as ephemeral and options parameter to add extra options for the table definition, like when to remove it: