we upgraded our Application from Rails 4.1.14 to 4.2.5.1 and hit the following issue:
string = "SomeString"
ar_model = SomeArModel.new
ar_model.some_attribute = string
# next line is true for 4.1, but fails for 4.2
ar_model.some_attribute.object_id == string.object_id
Apparently, object setters dup every object (if I have an array, every object inside will be duped as well) and I wonder, if this is intended and part of some new security feature?
Update
I use ruby-2.2.2p95 for both rails version. For reference I did a small project:
rails new testproject
rails g model Building name:string
rails db:migrate
rails c
>> b = Building.new
>> name = "Testname"
>> b.name = name
>> name.object_id # => 70199493308960
>> b.name.object_id # => 70199493278780
Afterwards, I only changed Rails version to 4.1.14 in Gemfile, and tried again => both object_ids were the same. So it can't rely only on the Ruby version...
Update2
It also holds true for ruby-2.2.3 and JRuby 9.0.4.0...
ar_model.attributes_before_type_cast['some_attribute']
contains the real object.