Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dynamic class creation where not needed #1850

Merged
merged 2 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/action_controller/json_api/transform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module Serialization
class JsonApi
class KeyTransformTest < ActionController::TestCase
class KeyTransformTestController < ActionController::Base
Post = Class.new(::Model)
class Post < ::Model; end
class Author < ::Model; end
class TopComment < ::Model; end
class PostSerializer < ActiveModel::Serializer
type 'posts'
attributes :title, :body, :publish_at
Expand All @@ -22,13 +24,11 @@ class PostSerializer < ActiveModel::Serializer
end
end

Author = Class.new(::Model)
class AuthorSerializer < ActiveModel::Serializer
type 'authors'
attributes :first_name, :last_name
end

TopComment = Class.new(::Model)
class TopCommentSerializer < ActiveModel::Serializer
type 'top_comments'
attributes :body
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/json/transform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def mock_request(key_transform = nil)
@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
Expand Down
7 changes: 4 additions & 3 deletions test/adapter/json_api/fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ 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
belongs_to :author
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
Expand Down
11 changes: 5 additions & 6 deletions test/adapter/json_api/linked_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -283,8 +282,8 @@ def test_nil_link_with_specified_serializer
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'
Expand All @@ -303,8 +302,8 @@ def setup
@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
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/json_api/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
7 changes: 4 additions & 3 deletions test/adapter/json_api/transform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,13 +26,11 @@ class PostSerializer < ActiveModel::Serializer
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
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/bm_caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/ruby-bench/ruby-bench-suite/blob/8ad567f7e43a044ae48c36833218423bb1e2bd9d/rails/benchmarks/actionpack_router.rb
class ApiAssertion
include Benchmark::ActiveModelSerializers::TestMethods
BadRevisionError = Class.new(StandardError)
class BadRevisionError < StandardError; end

def valid?
caching = get_caching
Expand Down
8 changes: 4 additions & 4 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

module ActiveModelSerializers
class CacheTest < ActiveSupport::TestCase
UncachedAuthor = Class.new(Author) do
class UncachedAuthor < Author
# To confirm cache_key is set using updated_at and cache_key option passed to cache
undef_method :cache_key
end

Article = Class.new(::Model) do
class Article < ::Model
# To confirm error is raised when cache_key is not set and cache_key option not passed to cache
undef_method :cache_key
end

ArticleSerializer = Class.new(ActiveModel::Serializer) do
class ArticleSerializer < ActiveModel::Serializer
cache only: [:place], skip_digest: true
attributes :title
end

InheritedRoleSerializer = Class.new(RoleSerializer) do
class InheritedRoleSerializer < RoleSerializer
cache key: 'inherited_role', only: [:name, :special_attribute]
attribute :special_attribute
end
Expand Down
2 changes: 1 addition & 1 deletion test/collection_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveModel
class Serializer
class CollectionSerializerTest < ActiveSupport::TestCase
MessagesSerializer = Class.new(ActiveModel::Serializer) do
class MessagesSerializer < ActiveModel::Serializer
type 'messages'
end

Expand Down
Loading