Skip to content

Commit adc3fc9

Browse files
committed
Default serializer tests
Based on namespace serializer tests except namespace is set in default_serializer_options
1 parent 4d3d234 commit adc3fc9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/integration/action_controller/namespaced_serialization_test.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,54 @@ def test_array_fallback_to_a_version_without_namespace
4343
assert_serializer CommentSerializer
4444
end
4545
end
46+
47+
class OptionNamespacedSerializationTest < ActionController::TestCase
48+
class MyController < ActionController::Base
49+
def default_serializer_options
50+
{
51+
namespace: TestNamespace
52+
}
53+
end
54+
55+
def render_profile_with_namespace_option
56+
render json: Profile.new({ name: 'Name 1', description: 'Description 1'})
57+
end
58+
59+
def render_profiles_with_namespace_option
60+
render json: [Profile.new({ name: 'Name 1', description: 'Description 1'})]
61+
end
62+
63+
def render_comment
64+
render json: Comment.new(content: 'Comment 1')
65+
end
66+
67+
def render_comments
68+
render json: [Comment.new(content: 'Comment 1')]
69+
end
70+
end
71+
72+
tests MyController
73+
74+
def test_render_profile_with_namespace_option
75+
get :render_profile_with_namespace_option
76+
assert_serializer TestNamespace::ProfileSerializer
77+
end
78+
79+
def test_render_profiles_with_namespace_option
80+
get :render_profiles_with_namespace_option
81+
assert_serializer TestNamespace::ProfileSerializer
82+
end
83+
84+
def test_fallback_to_a_version_without_namespace
85+
get :render_comment
86+
assert_serializer CommentSerializer
87+
end
88+
89+
def test_array_fallback_to_a_version_without_namespace
90+
get :render_comments
91+
assert_serializer CommentSerializer
92+
end
93+
end
94+
4695
end
4796
end

0 commit comments

Comments
 (0)