Created
September 10, 2015 00:48
-
-
Save NullVoxPopuli/0cb9badfeedb85e8acab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveModel | |
class Serializer | |
module Utils | |
class UtilsTest < MiniTest::Test | |
def test_include_options_to_hash_from_symbol | |
expected = { author: {} } | |
input = :author | |
actual = ActiveModel::Serializer::Utils.include_options_to_hash(input) | |
assert_equal(expected, actual) | |
end | |
def test_include_options_to_hash_from_array | |
expected = { author: {}, comments: {} } | |
input = [:author, :comments] | |
actual = ActiveModel::Serializer::Utils.include_options_to_hash(input) | |
assert_equal(expected, actual) | |
end | |
def test_include_options_to_hash_from_nested_array | |
expected = { author: {}, comments: { author: {} } } | |
input = [:author, comments: [:author]] | |
actual = ActiveModel::Serializer::Utils.include_options_to_hash(input) | |
assert_equal(expected, actual) | |
end | |
def test_include_options_to_hash_from_array_of_hashes | |
expected = { | |
author: {}, | |
blogs: { posts: { contributors: {} } }, | |
comments: { author: { blogs: { posts: {} } } } | |
} | |
input = [ | |
:author, | |
blogs: [posts: :contributors], | |
comments: { author: { blogs: :posts } } | |
] | |
actual = ActiveModel::Serializer::Utils.include_options_to_hash(input) | |
assert_equal(expected, actual) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment