From d0d00d02a032b176284d2387a18663ce5c101f80 Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Mon, 31 Aug 2015 05:11:32 +0200 Subject: [PATCH 1/2] Add ActiveRecord-backed fixtures. --- test/fixtures/active_record.rb | 58 ++++++++++++++++++++++++++++++++++ test/test_helper.rb | 6 ++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/active_record.rb diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb new file mode 100644 index 000000000..e5029c309 --- /dev/null +++ b/test/fixtures/active_record.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 1327188e2..ce5164c32 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -34,6 +34,8 @@ require 'support/rails_app' -require 'fixtures/poro' - require 'support/test_case' + +require 'fixtures/active_record' + +require 'fixtures/poro' From 83f11acd6607fd2383250ba884eb84202f07f266 Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Mon, 31 Aug 2015 05:46:04 +0200 Subject: [PATCH 2/2] Add Gemfile dependencies to ActiveRecord and sqlite3. --- Gemfile | 6 ++++++ test/fixtures/active_record.rb | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ad21ffae2..e0a4364cb 100644 --- a/Gemfile +++ b/Gemfile @@ -25,5 +25,11 @@ else gem 'actionpack', gem_version end +group :test do + gem 'activerecord' + gem 'sqlite3', platform: :ruby + gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby +end + # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index e5029c309..ab3e4d85c 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -37,7 +37,6 @@ class Author < ActiveRecord::Base class PostSerializer < ActiveModel::Serializer attributes :id, :title, :body - params :title, :body has_many :comments belongs_to :author