Skip to content

Commit d0d00d0

Browse files
committed
Add ActiveRecord-backed fixtures.
1 parent 64168cb commit d0d00d0

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

test/fixtures/active_record.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

test/test_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
require 'support/rails_app'
3636

37-
require 'fixtures/poro'
38-
3937
require 'support/test_case'
38+
39+
require 'fixtures/active_record'
40+
41+
require 'fixtures/poro'

0 commit comments

Comments
 (0)