Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Created September 10, 2015 00:48
Show Gist options
  • Save NullVoxPopuli/0cb9badfeedb85e8acab to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/0cb9badfeedb85e8acab to your computer and use it in GitHub Desktop.
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