diff --git a/test/active_model_serializers/model_test.rb b/test/active_model_serializers/model_test.rb index 7bfb2edf4..0341282eb 100644 --- a/test/active_model_serializers/model_test.rb +++ b/test/active_model_serializers/model_test.rb @@ -4,7 +4,7 @@ module ActiveModelSerializers class ModelTest < ActiveSupport::TestCase include ActiveModel::Serializer::Lint::Tests - def setup + setup do @resource = ActiveModelSerializers::Model.new end @@ -18,5 +18,28 @@ def test_initialization_with_string_keys assert_equal model_instance.read_attribute_for_serialization(:key), value end + + def test_attributes_can_be_read_for_serialization + klass = Class.new(ActiveModelSerializers::Model) do + attr_accessor :one, :two, :three + end + original_attributes = { one: 1, two: 2, three: 3 } + instance = klass.new(original_attributes) + + # Initial value + expected_attributes = { one: 1, two: 2, three: 3 } + assert_equal expected_attributes, instance.attributes + assert_equal 1, instance.one + assert_equal 1, instance.read_attribute_for_serialization(:one) + + # Change via accessor + instance.one = :not_one + + expected_attributes = { one: :not_one, two: 2, three: 3 } + assert_equal expected_attributes, instance.attributes + assert_equal :not_one, instance.one + assert_equal :not_one, instance.read_attribute_for_serialization(:one) + end + end end