Merge remote-tracking branch 'upstream/master' into improve-tests

This commit is contained in:
Lucas Hosseini
2015-09-01 21:25:28 +02:00
11 changed files with 158 additions and 50 deletions

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

@@ -0,0 +1,57 @@
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
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

@@ -134,10 +134,11 @@ end
AuthorSerializer = Class.new(ActiveModel::Serializer) do
cache key:'writer', skip_digest: true
attributes :id, :name
attribute :id
attribute :name
has_many :posts, embed: :ids
has_many :roles, embed: :ids
has_many :posts
has_many :roles
has_one :bio
end

View File

@@ -6,7 +6,7 @@ module ActiveModel
AuthorSummarySerializer = Class.new
class AssociationsTestSerializer < Serializer
belongs_to :author, serializer: AuthorSummarySerializer
has_many :comments, embed: :ids
has_many :comments
has_one :category
end
@@ -21,7 +21,7 @@ module ActiveModel
end
def test_has_many_defines_reflection
has_many_reflection = HasManyReflection.new(:comments, embed: :ids)
has_many_reflection = HasManyReflection.new(:comments, {})
assert_includes(@reflections, has_many_reflection)
end

View File

@@ -52,13 +52,13 @@ module ActiveModel
case key
when :posts
assert_equal({ embed: :ids }, options)
assert_equal({}, options)
assert_kind_of(ActiveModel::Serializer.config.array_serializer, serializer)
when :bio
assert_equal({}, options)
assert_nil serializer
when :roles
assert_equal({ embed: :ids }, options)
assert_equal({}, options)
assert_kind_of(ActiveModel::Serializer.config.array_serializer, serializer)
else
flunk "Unknown association: #{key}"

View File

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