From adc3fc97429be065c19746dee35c3da828559bf8 Mon Sep 17 00:00:00 2001 From: Gauthier Delacroix Date: Wed, 3 Sep 2014 14:58:22 +0200 Subject: [PATCH] Default serializer tests Based on namespace serializer tests except namespace is set in default_serializer_options --- .../namespaced_serialization_test.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/integration/action_controller/namespaced_serialization_test.rb b/test/integration/action_controller/namespaced_serialization_test.rb index 4a5fbbf9..1e758d29 100644 --- a/test/integration/action_controller/namespaced_serialization_test.rb +++ b/test/integration/action_controller/namespaced_serialization_test.rb @@ -43,5 +43,54 @@ module ActionController assert_serializer CommentSerializer end end + + class OptionNamespacedSerializationTest < ActionController::TestCase + class MyController < ActionController::Base + def default_serializer_options + { + namespace: TestNamespace + } + end + + def render_profile_with_namespace_option + render json: Profile.new({ name: 'Name 1', description: 'Description 1'}) + end + + def render_profiles_with_namespace_option + render json: [Profile.new({ name: 'Name 1', description: 'Description 1'})] + end + + def render_comment + render json: Comment.new(content: 'Comment 1') + end + + def render_comments + render json: [Comment.new(content: 'Comment 1')] + end + end + + tests MyController + + def test_render_profile_with_namespace_option + get :render_profile_with_namespace_option + assert_serializer TestNamespace::ProfileSerializer + end + + def test_render_profiles_with_namespace_option + get :render_profiles_with_namespace_option + assert_serializer TestNamespace::ProfileSerializer + end + + def test_fallback_to_a_version_without_namespace + get :render_comment + assert_serializer CommentSerializer + end + + def test_array_fallback_to_a_version_without_namespace + get :render_comments + assert_serializer CommentSerializer + end + end + end end \ No newline at end of file