Created
November 20, 2013 11:35
-
-
Save carpodaster/7561755 to your computer and use it in GitHub Desktop.
Dynamically create an ActiveRecord class with an in-memory database
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
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
ActiveRecord::Base.connection.execute <<-EOSQL | |
CREATE TABLE in_memory_records( | |
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | |
name TEXT | |
); | |
EOSQL | |
Object.const_set 'InMemoryRecord', Class.new(ActiveRecord::Base) | |
InMemoryRecord.create name: 'Foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment