Closed
Description
After updating our app from Rails 4.2.2 to Rails 5 we have noticed that JSON strings are being stored as a string rather than a Hash or Array.
Is there a way we can reproduce the behaviour in Rails 5?
Steps to reproduce
-
Create Model
bundle exec rails g model OrderItem options:json
-
Run migration
bundle exec rake db:migrate
-
Open Console
bundle exec rails c
-
In Console (Rails 4.2.2)
item = OrderItem.new(options: "{\"key\":\"value\"}")
=> #<OrderItem id: nil, options: {"key"=>"value"}>
item.options
=> {"key"=>"value"}
item.options.is_a?(String)
=> false
item.options.is_a?(Hash)
=> true
- In Console (Rails 5.0.2)
item = OrderItem.new(options: "{\"key\":\"value\"}")
=> #<OrderItem id: nil, options: "{\"key\":\"value\"}">
item.options
=> "{\"key\":\"value\"}"
item.options.is_a?(String)
=> true
item.options.is_a?(Hash)
=> false
Expected behavior
The options attribute should return a hash
Actual behavior
The options attribute returns a string
System configuration
Rails version: 5.0.2
Ruby version: ruby 2.3.1p112
PostgreSQL: 9.4.5