mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Tests refactor
This commit is contained in:
44
test/unit/active_model/serializer/attributes_test.rb
Normal file
44
test/unit/active_model/serializer/attributes_test.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
require 'newbase/test_helper'
|
||||
require 'newbase/active_model/serializer'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AttributesTest < ActiveModel::TestCase
|
||||
class Model
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
end
|
||||
|
||||
def setup
|
||||
model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
|
||||
@model_serializer = ModelSerializer.new(model)
|
||||
end
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal(['attr1', 'attr2'],
|
||||
@model_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_attributes_serialization_using_serializable_hash
|
||||
assert_equal({
|
||||
'attr1' => 'value1', 'attr2' => 'value2'
|
||||
}, @model_serializer.serializable_hash)
|
||||
end
|
||||
|
||||
def test_attributes_serialization_using_as_json
|
||||
assert_equal({
|
||||
'attr1' => 'value1', 'attr2' => 'value2'
|
||||
}, @model_serializer.as_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user