Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up lazy loading of serialization support for ActiveRecord::Base…

… and ActionController::Base
  • Loading branch information...
commit 506e2ac9ad355b78f6bc94823f2aa3f1aa73ef35 1 parent b706244
@dgeb authored
Showing with 14 additions and 2 deletions.
  1. +2 −2 lib/active_model_serializers.rb
  2. +12 −0 test/serializer_support_test.rb
View
4 lib/active_model_serializers.rb
@@ -57,7 +57,7 @@ def active_model_serializer
end
ActiveSupport.on_load(:active_record) do
- include ActiveModel::SerializerSupport
+ ActiveRecord::Base.send(:include, ActiveModel::SerializerSupport)
end
module ActiveModel::ArraySerializerSupport
@@ -78,7 +78,7 @@ def active_model_serializer
require 'action_controller/serialization'
ActiveSupport.on_load(:action_controller) do
- include ::ActionController::Serialization
+ ActionController::Base.send(:include, ActionController::Serialization)
end
rescue LoadError => ex
# rails on installed, continuing
View
12 test/serializer_support_test.rb
@@ -9,6 +9,8 @@ class RandomModelCollection
end
module ActiveRecord
+ class Base
+ end
class Relation
end
end
@@ -26,5 +28,15 @@ class SerializerSupportTest < ActiveModel::TestCase
ActiveSupport.run_load_hooks(:active_record)
assert_equal ActiveModel::ArraySerializer, ActiveRecord::Relation.new.active_model_serializer
end
+
+ test "it automatically includes serializer support in active_record/base" do
+ ActiveSupport.run_load_hooks(:active_record)
+ assert ActiveRecord::Base.new.respond_to?(:active_model_serializer)
+ end
+
+ test "it automatically includes serializer support in action_controller/base" do
+ ActiveSupport.run_load_hooks(:action_controller)
+ assert ActionController::Base.new.respond_to?(:serialization_scope)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.