Skip to content

Commit aa4d89a

Browse files
NullVoxPopulibf4
authored andcommitted
remove dynamic class creation where not needed (#1850)
* remove dynamic class creation where not needed
1 parent 3ad2457 commit aa4d89a

File tree

14 files changed

+90
-85
lines changed

14 files changed

+90
-85
lines changed

test/action_controller/json_api/transform_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module Serialization
55
class JsonApi
66
class KeyTransformTest < ActionController::TestCase
77
class KeyTransformTestController < ActionController::Base
8-
Post = Class.new(::Model)
8+
class Post < ::Model; end
9+
class Author < ::Model; end
10+
class TopComment < ::Model; end
911
class PostSerializer < ActiveModel::Serializer
1012
type 'posts'
1113
attributes :title, :body, :publish_at
@@ -22,13 +24,11 @@ class PostSerializer < ActiveModel::Serializer
2224
end
2325
end
2426

25-
Author = Class.new(::Model)
2627
class AuthorSerializer < ActiveModel::Serializer
2728
type 'authors'
2829
attributes :first_name, :last_name
2930
end
3031

31-
TopComment = Class.new(::Model)
3232
class TopCommentSerializer < ActiveModel::Serializer
3333
type 'top_comments'
3434
attributes :body

test/adapter/json/transform_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def mock_request(key_transform = nil)
1515
@adapter = ActiveModelSerializers::Adapter::Json.new(serializer, options)
1616
end
1717

18-
Post = Class.new(::Model)
18+
class Post < ::Model; end
1919
class PostSerializer < ActiveModel::Serializer
2020
attributes :id, :title, :body, :publish_at
2121
end

test/adapter/json_api/fields_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ module ActiveModelSerializers
44
module Adapter
55
class JsonApi
66
class FieldsTest < ActiveSupport::TestCase
7-
Post = Class.new(::Model)
7+
class Post < ::Model; end
8+
class Author < ::Model; end
9+
class Comment < ::Model; end
10+
811
class PostSerializer < ActiveModel::Serializer
912
type 'posts'
1013
attributes :title, :body
1114
belongs_to :author
1215
has_many :comments
1316
end
1417

15-
Author = Class.new(::Model)
1618
class AuthorSerializer < ActiveModel::Serializer
1719
type 'authors'
1820
attributes :name, :birthday
1921
end
2022

21-
Comment = Class.new(::Model)
2223
class CommentSerializer < ActiveModel::Serializer
2324
type 'comments'
2425
attributes :body

test/adapter/json_api/linked_test.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
require 'test_helper'
22

3-
NestedPost = Class.new(Model)
3+
class NestedPost < ::Model; end
44
class NestedPostSerializer < ActiveModel::Serializer
55
has_many :nested_posts
66
end
7-
87
module ActiveModelSerializers
98
module Adapter
109
class JsonApi
@@ -283,8 +282,8 @@ def test_nil_link_with_specified_serializer
283282
end
284283

285284
class NoDuplicatesTest < ActiveSupport::TestCase
286-
Post = Class.new(::Model)
287-
Author = Class.new(::Model)
285+
class Post < ::Model; end
286+
class Author < ::Model; end
288287

289288
class PostSerializer < ActiveModel::Serializer
290289
type 'posts'
@@ -303,8 +302,8 @@ def setup
303302
@author.posts << @post1
304303
@author.posts << @post2
305304

306-
@nestedpost1 = ::NestedPost.new(id: 1, nested_posts: [])
307-
@nestedpost2 = ::NestedPost.new(id: 2, nested_posts: [])
305+
@nestedpost1 = NestedPost.new(id: 1, nested_posts: [])
306+
@nestedpost2 = NestedPost.new(id: 2, nested_posts: [])
308307
@nestedpost1.nested_posts << @nestedpost1
309308
@nestedpost1.nested_posts << @nestedpost2
310309
@nestedpost2.nested_posts << @nestedpost1

test/adapter/json_api/links_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ActiveModelSerializers
44
module Adapter
55
class JsonApi
66
class LinksTest < ActiveSupport::TestCase
7-
LinkAuthor = Class.new(::Model)
7+
class LinkAuthor < ::Model; end
88
class LinkAuthorSerializer < ActiveModel::Serializer
99
link :self do
1010
href "http://example.com/link_author/#{object.id}"

test/adapter/json_api/transform_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ module ActiveModelSerializers
44
module Adapter
55
class JsonApi
66
class KeyCaseTest < ActiveSupport::TestCase
7-
Post = Class.new(::Model)
7+
class Post < ::Model; end
8+
class Author < ::Model; end
9+
class Comment < ::Model; end
10+
811
class PostSerializer < ActiveModel::Serializer
912
type 'posts'
1013
attributes :title, :body, :publish_at
@@ -23,13 +26,11 @@ class PostSerializer < ActiveModel::Serializer
2326
end
2427
end
2528

26-
Author = Class.new(::Model)
2729
class AuthorSerializer < ActiveModel::Serializer
2830
type 'authors'
2931
attributes :first_name, :last_name
3032
end
3133

32-
Comment = Class.new(::Model)
3334
class CommentSerializer < ActiveModel::Serializer
3435
type 'comments'
3536
attributes :body

test/benchmark/bm_caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://github.com/ruby-bench/ruby-bench-suite/blob/8ad567f7e43a044ae48c36833218423bb1e2bd9d/rails/benchmarks/actionpack_router.rb
55
class ApiAssertion
66
include Benchmark::ActiveModelSerializers::TestMethods
7-
BadRevisionError = Class.new(StandardError)
7+
class BadRevisionError < StandardError; end
88

99
def valid?
1010
caching = get_caching

test/cache_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
module ActiveModelSerializers
66
class CacheTest < ActiveSupport::TestCase
7-
UncachedAuthor = Class.new(Author) do
7+
class UncachedAuthor < Author
88
# To confirm cache_key is set using updated_at and cache_key option passed to cache
99
undef_method :cache_key
1010
end
1111

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

17-
ArticleSerializer = Class.new(ActiveModel::Serializer) do
17+
class ArticleSerializer < ActiveModel::Serializer
1818
cache only: [:place], skip_digest: true
1919
attributes :title
2020
end
2121

22-
InheritedRoleSerializer = Class.new(RoleSerializer) do
22+
class InheritedRoleSerializer < RoleSerializer
2323
cache key: 'inherited_role', only: [:name, :special_attribute]
2424
attribute :special_attribute
2525
end

test/collection_serializer_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActiveModel
44
class Serializer
55
class CollectionSerializerTest < ActiveSupport::TestCase
6-
MessagesSerializer = Class.new(ActiveModel::Serializer) do
6+
class MessagesSerializer < ActiveModel::Serializer
77
type 'messages'
88
end
99

0 commit comments

Comments
 (0)