forked from amazing-print/amazing_print
-
Notifications
You must be signed in to change notification settings - Fork 0
/
active_record_helper.rb
40 lines (34 loc) · 921 Bytes
/
active_record_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true
if ExtVerifier.has_rails?
# Required to use the column support
module Rails
def self.env
{}
end
end
# Establish connection to in-memory SQLite DB
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
# Create the users table
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.create_table :users do |t|
t.string :name
t.integer :rank
t.boolean :admin
t.datetime :created_at
end
ActiveRecord::Migration.create_table :emails do |t|
t.references :user
t.string :email_address
end
# Create models
class User < ActiveRecord::Base; has_many :emails; end
class SubUser < User; end
class Email < ActiveRecord::Base; belongs_to :user; end
class TableFreeModel
include ::ActiveModel::Validations
attr_reader(:name)
def attributes
{ 'name' => name }
end
end
end