Created
April 24, 2023 16:10
-
-
Save krisleech/162dad80bea35b4bf150d4877fb53d4c to your computer and use it in GitHub Desktop.
ephemeral ActiveRecord model for specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let(:model_class) do | |
Class.new(ApplicationRecord) do | |
self.table_name = "model_class_#{SecureRandom.uuid.delete('-')}" | |
def self.up | |
connection.execute("CREATE TABLE #{table_name}(id INTEGER PRIMARY KEY AUTOINCREMENT)") | |
end | |
def self.down | |
ApplicationRecord.connection.execute("DROP TABLE #{table_name}") | |
end | |
end | |
end | |
around do |example| | |
model_class.up | |
example.run | |
model_class.down | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment