-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep.rb
82 lines (67 loc) · 1.67 KB
/
prep.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# --- Bundle dependencies ---
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "active_model_serializers", '0.9.7'
gem "activerecord", "~> 5.1"
gem "alba"
gem "benchmark-ips"
gem "benchmark-memory"
gem "blueprinter"
gem "jsonapi-serializer"
gem "jbuilder"
gem 'turbostreamer'
gem "jserializer"
gem "multi_json"
gem "panko_serializer"
gem "pg"
gem "primalize"
gem "oj"
gem "representable"
gem "simple_ams"
gem "sqlite3"
end
# --- Test data model setup ---
require "pg"
require "active_record"
require "active_record/connection_adapters/postgresql_adapter"
require "logger"
require "oj"
require "sqlite3"
Oj.optimize_rails unless ENV['NO_OJ_OPTIMIZE_RAILS']
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
# ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :body
end
create_table :comments, force: true do |t|
t.integer :post_id
t.string :body
t.integer :commenter_id
end
create_table :users, force: true do |t|
t.string :name
end
end
class Post < ActiveRecord::Base
has_many :comments
has_many :commenters, through: :comments, class_name: 'User', source: :commenter
def attributes
{id: nil, body: nil, commenter_names: commenter_names}
end
def commenter_names
commenters.pluck(:name)
end
end
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :commenter, class_name: 'User'
def attributes
{id: nil, body: nil}
end
end
class User < ActiveRecord::Base
has_many :comments
end