File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change
1
+ require 'active_record'
2
+
3
+ ActiveRecord ::Base . establish_connection ( adapter : 'sqlite3' , database : ':memory:' )
4
+ ActiveRecord ::Schema . define do
5
+ create_table :posts , force : true do |t |
6
+ t . string :title
7
+ t . text :body
8
+ t . references :author
9
+ t . timestamps null : false
10
+ end
11
+ create_table :authors , force : true do |t |
12
+ t . string :name
13
+ t . timestamps null : false
14
+ end
15
+ create_table :comments , force : true do |t |
16
+ t . text :contents
17
+ t . references :author
18
+ t . references :post
19
+ t . timestamp null : false
20
+ end
21
+ end
22
+
23
+ module ARModels
24
+ class Post < ActiveRecord ::Base
25
+ has_many :comments
26
+ belongs_to :author
27
+ end
28
+
29
+ class Comment < ActiveRecord ::Base
30
+ belongs_to :post
31
+ belongs_to :author
32
+ end
33
+
34
+ class Author < ActiveRecord ::Base
35
+ has_many :posts
36
+ end
37
+
38
+ class PostSerializer < ActiveModel ::Serializer
39
+ attributes :id , :title , :body
40
+ params :title , :body
41
+
42
+ has_many :comments
43
+ belongs_to :author
44
+ url :comments
45
+ end
46
+
47
+ class CommentSerializer < ActiveModel ::Serializer
48
+ attributes :id , :contents
49
+
50
+ belongs_to :author
51
+ end
52
+
53
+ class AuthorSerializer < ActiveModel ::Serializer
54
+ attributes :id , :name
55
+
56
+ has_many :posts
57
+ end
58
+ end
Original file line number Diff line number Diff line change 34
34
35
35
require 'support/rails_app'
36
36
37
- require 'fixtures/poro'
38
-
39
37
require 'support/test_case'
38
+
39
+ require 'fixtures/active_record'
40
+
41
+ require 'fixtures/poro'
You can’t perform that action at this time.
0 commit comments