tests for namespaced controlleler

This commit is contained in:
Theodore Konukhov
2014-08-26 18:07:31 +02:00
parent 26c0847563
commit dde1492934
4 changed files with 63 additions and 1 deletions

View File

@@ -73,3 +73,12 @@ end
class WebLogLowerCamelSerializer < WebLogSerializer
format_keys :lower_camel
end
class ShortUserSerializer < ActiveModel::Serializer
attributes :name
end
module TestNamespace
class ProfileSerializer < ::ProfileSerializer; end
class UserSerializer < ::UserSerializer; end
end

View File

@@ -0,0 +1,47 @@
require 'test_helper'
module ActionController
module Serialization
class NamespacedSerializationTest < ActionController::TestCase
class TestNamespace::MyController < ActionController::Base
def render_profile_with_namespace
render json: Profile.new({ name: 'Name 1', description: 'Description 1'})
end
def render_profiles_with_namespace
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 TestNamespace::MyController
def test_render_profile_with_namespace
get :render_profile_with_namespace
assert_serializer TestNamespace::ProfileSerializer
end
def test_render_profiles_with_namespace
get :render_profiles_with_namespace
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