mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Lookup fieldset using either string or symbol
This commit is contained in:
@@ -5,11 +5,21 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class FieldsetTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
|
||||
end
|
||||
|
||||
def test_fieldset_with_hash
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
|
||||
expected = { post: [:id, :title], comment: [:body] }
|
||||
|
||||
assert_equal(expected, fieldset.fields)
|
||||
assert_equal(expected, @fieldset.fields)
|
||||
end
|
||||
|
||||
def test_fields_for_accepts_string_or_symbol
|
||||
expected = [:id, :title]
|
||||
|
||||
assert_equal(expected, @fieldset.fields_for(:post))
|
||||
assert_equal(expected, @fieldset.fields_for('post'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user