forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathar_classes.rb
44 lines (37 loc) · 960 Bytes
/
ar_classes.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
41
42
43
44
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
module Connections
def self.extended(host)
host.connection.execute <<-EOSQL
CREATE TABLE #{host.table_name} (
#{host.primary_key} integer PRIMARY KEY AUTOINCREMENT,
associated_model_id integer,
mockable_model_id integer,
nonexistent_model_id integer
)
EOSQL
host.reset_column_information
end
end
class NonActiveRecordModel
extend ActiveModel::Naming
include ActiveModel::Conversion
end
class MockableModel < ActiveRecord::Base
extend Connections
has_one :associated_model
end
class SubMockableModel < MockableModel
end
class AssociatedModel < ActiveRecord::Base
extend Connections
belongs_to :mockable_model
belongs_to :nonexistent_model, class_name: "Other"
end
class AlternatePrimaryKeyModel < ActiveRecord::Base
self.primary_key = :my_id
extend Connections
attr_accessor :my_id
end