aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller.rb1
-rw-r--r--actionpack/lib/action_controller/metal/serialization.rb51
-rw-r--r--actionpack/test/controller/render_json_test.rb48
3 files changed, 0 insertions, 100 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 3829e60bb0..f4eaa2fd1b 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -31,7 +31,6 @@ module ActionController
autoload :RequestForgeryProtection
autoload :Rescue
autoload :Responder
- autoload :Serialization
autoload :SessionManagement
autoload :Streaming
autoload :Testing
diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb
deleted file mode 100644
index 628d5996d7..0000000000
--- a/actionpack/lib/action_controller/metal/serialization.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-module ActionController
- # Action Controller Serialization
- #
- # Overrides render :json to check if the given object implements +active_model_serializer+
- # as a method. If so, use the returned serializer instead of calling +to_json+ in the object.
- #
- # This module also provides a serialization_scope method that allows you to configure the
- # +serialization_scope+ of the serializer. Most apps will likely set the +serialization_scope+
- # to the current user:
- #
- # class ApplicationController < ActionController::Base
- # serialization_scope :current_user
- # end
- #
- # If you need more complex scope rules, you can simply override the serialization_scope:
- #
- # class ApplicationController < ActionController::Base
- # private
- #
- # def serialization_scope
- # current_user
- # end
- # end
- #
- module Serialization
- extend ActiveSupport::Concern
-
- include ActionController::Renderers
-
- included do
- class_attribute :_serialization_scope
- end
-
- def serialization_scope
- send(_serialization_scope)
- end
-
- def _render_option_json(json, options)
- if json.respond_to?(:active_model_serializer) && (serializer = json.active_model_serializer)
- json = serializer.new(json, serialization_scope)
- end
- super
- end
-
- module ClassMethods
- def serialization_scope(scope)
- self._serialization_scope = scope
- end
- end
- end
-end
diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb
index dc09812ba3..fc604a2db3 100644
--- a/actionpack/test/controller/render_json_test.rb
+++ b/actionpack/test/controller/render_json_test.rb
@@ -15,36 +15,9 @@ class RenderJsonTest < ActionController::TestCase
end
end
- class JsonSerializer
- def initialize(object, scope)
- @object, @scope = object, scope
- end
-
- def as_json(*)
- { :object => @object.as_json, :scope => @scope.as_json }
- end
- end
-
- class JsonSerializable
- def initialize(skip=false)
- @skip = skip
- end
-
- def active_model_serializer
- JsonSerializer unless @skip
- end
-
- def as_json(*)
- { :serializable_object => true }
- end
- end
-
class TestController < ActionController::Base
protect_from_forgery
- serialization_scope :current_user
- attr_reader :current_user
-
def self.controller_path
'test'
end
@@ -88,16 +61,6 @@ class RenderJsonTest < ActionController::TestCase
def render_json_without_options
render :json => JsonRenderable.new
end
-
- def render_json_with_serializer
- @current_user = Struct.new(:as_json).new(:current_user => true)
- render :json => JsonSerializable.new
- end
-
- def render_json_with_serializer_api_but_without_serializer
- @current_user = Struct.new(:as_json).new(:current_user => true)
- render :json => JsonSerializable.new(true)
- end
end
tests TestController
@@ -169,15 +132,4 @@ class RenderJsonTest < ActionController::TestCase
get :render_json_without_options
assert_equal '{"a":"b"}', @response.body
end
-
- def test_render_json_with_serializer
- get :render_json_with_serializer
- assert_match '"scope":{"current_user":true}', @response.body
- assert_match '"object":{"serializable_object":true}', @response.body
- end
-
- def test_render_json_with_serializer_api_but_without_serializer
- get :render_json_with_serializer_api_but_without_serializer
- assert_match '{"serializable_object":true}', @response.body
- end
end