Add ActiveRecord-backed fixtures.

This commit is contained in:
Lucas Hosseini 2015-08-31 05:11:32 +02:00
parent 64168cbecd
commit d0d00d02a0
2 changed files with 62 additions and 2 deletions

58
test/fixtures/active_record.rb vendored Normal file
View File

@ -0,0 +1,58 @@
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :title
t.text :body
t.references :author
t.timestamps null: false
end
create_table :authors, force: true do |t|
t.string :name
t.timestamps null: false
end
create_table :comments, force: true do |t|
t.text :contents
t.references :author
t.references :post
t.timestamp null: false
end
end
module ARModels
class Post < ActiveRecord::Base
has_many :comments
belongs_to :author
end
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :posts
end
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body
params :title, :body
has_many :comments
belongs_to :author
url :comments
end
class CommentSerializer < ActiveModel::Serializer
attributes :id, :contents
belongs_to :author
end
class AuthorSerializer < ActiveModel::Serializer
attributes :id, :name
has_many :posts
end
end

View File

@ -34,6 +34,8 @@ require 'support/stream_capture'
require 'support/rails_app'
require 'fixtures/poro'
require 'support/test_case'
require 'fixtures/active_record'
require 'fixtures/poro'