rails/rails — Issue #4659: Documentation/Implementation of attributes method for ActiveModel::Serialization is out of sync
Author: hammerdr
Created: 2012-01-25 08:25:12+00:00
State: open

From what I can tell, it looks like the documentation and the implementation (or, rather, the expected implementation) of ActiveModel::Serialization#attributes are different. In the documentation, it looks like you are expected to return a hash with key/value pairs. However, what actually happens is that the value pairs are ignored and the keys are used to send a message to the serialized object.

In ActiveModel::Serialization API documentation, the following example is given (https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb#L13):

```ruby
class Person

include ActiveModel::Serialization

attr_accessor :name

def attributes
{'name' => name}
end

end
```

and in the tests the following example is given (https://github.com/rails/rails/blob/master/activemodel/test/cases/serialization_test.rb#L24):

```ruby
class Address
include ActiveModel::Serialization

attr_accessor :street, :city, :state, :zip

def attributes
instance_values
end
end
```

So, one of two things would be wrong by my estimation: either the documentation needs to be updated to reflect that the value set in the hash is not used (which would be a little weird?) or the implementation of serialization is wrong. I can do work and issue a pull request on either but I'm not sure which is correct :)