aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-01-23 14:54:56 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2013-01-23 14:54:56 +0000
commit1b75b94de6d474d56a6c47e74bdbd985ec14087b (patch)
tree3c81b8d69628833041e596f101cf6770e482f5be
parente20c0e3a8f17d716720d248d3db5f022f7cb021a (diff)
downloadrails-1b75b94de6d474d56a6c47e74bdbd985ec14087b.tar.gz
rails-1b75b94de6d474d56a6c47e74bdbd985ec14087b.tar.bz2
rails-1b75b94de6d474d56a6c47e74bdbd985ec14087b.zip
Remove warning by using a custom coder
The native JSON library bypasses the `to_json` overrides in active_support/core_ext/object/to_json.rb by calling its native implementation directly. However `ActiveRecord::Store` uses a HWIA so `JSON.dump` will call our `to_json` instead with a `State` object for options rather than a `Hash`. This generates a warning when the `:encoding`, `:only` & `:except` keys are accessed in `Hash#as_json` because the `State` object delegates unknown keys to `instance_variable_get` in its `:[]` method. Workaround this warning in the test by using a custom coder that calls `ActiveSupport::JSON.encode` directly.
-rw-r--r--activerecord/test/models/admin/user.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/test/models/admin/user.rb b/activerecord/test/models/admin/user.rb
index 467f3ccd39..024fede266 100644
--- a/activerecord/test/models/admin/user.rb
+++ b/activerecord/test/models/admin/user.rb
@@ -1,10 +1,24 @@
class Admin::User < ActiveRecord::Base
+ class Coder
+ def initialize(default = {})
+ @default = default
+ end
+
+ def dump(o)
+ ActiveSupport::JSON.encode(o || @default)
+ end
+
+ def load(s)
+ s.present? ? ActiveSupport::JSON.decode(s) : @default.clone
+ end
+ end
+
belongs_to :account
store :settings, :accessors => [ :color, :homepage ]
store_accessor :settings, :favorite_food
store :preferences, :accessors => [ :remember_login ]
- store :json_data, :accessors => [ :height, :weight ], :coder => JSON
- store :json_data_empty, :accessors => [ :is_a_good_guy ], :coder => JSON
+ store :json_data, :accessors => [ :height, :weight ], :coder => Coder.new
+ store :json_data_empty, :accessors => [ :is_a_good_guy ], :coder => Coder.new
def phone_number
read_store_attribute(:settings, :phone_number).gsub(/(\d{3})(\d{3})(\d{4})/,'(\1) \2-\3')