aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/render_json_test.rb
diff options
context:
space:
mode:
authorJose and Yehuda <wycats@gmail.com>2011-09-26 18:48:19 -0400
committerJose and Yehuda <wycats@gmail.com>2011-10-15 18:40:37 +0200
commit8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe (patch)
tree143183598cfaf683fd0629b195d85c5e1a5bee55 /actionpack/test/controller/render_json_test.rb
parent098c95abcb2b101bde0d55ddd5e348fda0ec8f49 (diff)
downloadrails-8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe.tar.gz
rails-8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe.tar.bz2
rails-8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe.zip
Initial commit of serializer support
Diffstat (limited to 'actionpack/test/controller/render_json_test.rb')
-rw-r--r--actionpack/test/controller/render_json_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb
index fc604a2db3..f886af1a95 100644
--- a/actionpack/test/controller/render_json_test.rb
+++ b/actionpack/test/controller/render_json_test.rb
@@ -15,9 +15,32 @@ 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 active_model_serializer
+ JsonSerializer
+ 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
@@ -61,6 +84,11 @@ 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
end
tests TestController
@@ -132,4 +160,10 @@ 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
end