remove dynamic class creation where not needed (#1850)

* remove dynamic class creation where not needed
This commit is contained in:
L. Preston Sego III
2016-07-18 15:11:09 -04:00
committed by Benjamin Fleischer
parent 3ad2457aaf
commit aa4d89ab47
14 changed files with 90 additions and 85 deletions

View File

@@ -15,7 +15,7 @@ module ActiveModelSerializers
@adapter = ActiveModelSerializers::Adapter::Json.new(serializer, options)
end
Post = Class.new(::Model)
class Post < ::Model; end
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body, :publish_at
end

View File

@@ -4,7 +4,10 @@ module ActiveModelSerializers
module Adapter
class JsonApi
class FieldsTest < ActiveSupport::TestCase
Post = Class.new(::Model)
class Post < ::Model; end
class Author < ::Model; end
class Comment < ::Model; end
class PostSerializer < ActiveModel::Serializer
type 'posts'
attributes :title, :body
@@ -12,13 +15,11 @@ module ActiveModelSerializers
has_many :comments
end
Author = Class.new(::Model)
class AuthorSerializer < ActiveModel::Serializer
type 'authors'
attributes :name, :birthday
end
Comment = Class.new(::Model)
class CommentSerializer < ActiveModel::Serializer
type 'comments'
attributes :body

View File

@@ -1,10 +1,9 @@
require 'test_helper'
NestedPost = Class.new(Model)
class NestedPost < ::Model; end
class NestedPostSerializer < ActiveModel::Serializer
has_many :nested_posts
end
module ActiveModelSerializers
module Adapter
class JsonApi
@@ -283,8 +282,8 @@ module ActiveModelSerializers
end
class NoDuplicatesTest < ActiveSupport::TestCase
Post = Class.new(::Model)
Author = Class.new(::Model)
class Post < ::Model; end
class Author < ::Model; end
class PostSerializer < ActiveModel::Serializer
type 'posts'
@@ -303,8 +302,8 @@ module ActiveModelSerializers
@author.posts << @post1
@author.posts << @post2
@nestedpost1 = ::NestedPost.new(id: 1, nested_posts: [])
@nestedpost2 = ::NestedPost.new(id: 2, nested_posts: [])
@nestedpost1 = NestedPost.new(id: 1, nested_posts: [])
@nestedpost2 = NestedPost.new(id: 2, nested_posts: [])
@nestedpost1.nested_posts << @nestedpost1
@nestedpost1.nested_posts << @nestedpost2
@nestedpost2.nested_posts << @nestedpost1

View File

@@ -4,7 +4,7 @@ module ActiveModelSerializers
module Adapter
class JsonApi
class LinksTest < ActiveSupport::TestCase
LinkAuthor = Class.new(::Model)
class LinkAuthor < ::Model; end
class LinkAuthorSerializer < ActiveModel::Serializer
link :self do
href "http://example.com/link_author/#{object.id}"

View File

@@ -4,7 +4,10 @@ module ActiveModelSerializers
module Adapter
class JsonApi
class KeyCaseTest < ActiveSupport::TestCase
Post = Class.new(::Model)
class Post < ::Model; end
class Author < ::Model; end
class Comment < ::Model; end
class PostSerializer < ActiveModel::Serializer
type 'posts'
attributes :title, :body, :publish_at
@@ -23,13 +26,11 @@ module ActiveModelSerializers
end
end
Author = Class.new(::Model)
class AuthorSerializer < ActiveModel::Serializer
type 'authors'
attributes :first_name, :last_name
end
Comment = Class.new(::Model)
class CommentSerializer < ActiveModel::Serializer
type 'comments'
attributes :body