From d9f16fafecad13cfe4ca1d4ff825de768b39b9ee Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 8 Jun 2009 17:56:23 -0700 Subject: Update for Active Model yielding per error not per attribute --- activerecord/lib/active_record/validations.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 85b65ecf1a..a150ba4acf 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -40,6 +40,7 @@ module ActiveRecord full_messages = [] each do |attribute, messages| + messages = Array.wrap(messages) next if messages.empty? if attribute == :base -- cgit v1.2.3 From 6e73cf6bdf0ab3961f212735b4ac46f7e924fcd5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 8 Jun 2009 19:25:56 -0700 Subject: Fix AR json encoding --- activerecord/lib/active_record/serialization.rb | 5 ++-- .../active_record/serializers/json_serializer.rb | 32 +++++----------------- 2 files changed, 10 insertions(+), 27 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 7959f2b510..23d085bea9 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -3,8 +3,9 @@ module ActiveRecord #:nodoc: class Serializer #:nodoc: attr_reader :options - def initialize(record, options = {}) - @record, @options = record, options.dup + def initialize(record, options = nil) + @record = record + @options = options ? options.dup : {} end # To replicate the behavior in ActiveRecord#attributes, diff --git a/activerecord/lib/active_record/serializers/json_serializer.rb b/activerecord/lib/active_record/serializers/json_serializer.rb index 67e2b2abb3..e49cf59494 100644 --- a/activerecord/lib/active_record/serializers/json_serializer.rb +++ b/activerecord/lib/active_record/serializers/json_serializer.rb @@ -1,4 +1,5 @@ require 'active_support/json' +require 'active_support/core_ext/module/model_naming' module ActiveRecord #:nodoc: module Serialization @@ -74,36 +75,17 @@ module ActiveRecord #:nodoc: # "title": "Welcome to the weblog"}, # {"comments": [{"body": "Don't think too hard"}], # "title": "So I was thinking"}]} - def to_json(options = {}) - json = JsonSerializer.new(self, options).to_s - if include_root_in_json - "{#{self.class.json_class_name}:#{json}}" - else - json - end + def encode_json(encoder) + hash = Serializer.new(self, encoder.options).serializable_record + hash = { self.class.model_name.element => hash } if include_root_in_json + ActiveSupport::JSON.encode(hash) end + def as_json(options = nil) self end #:nodoc: + def from_json(json) self.attributes = ActiveSupport::JSON.decode(json) self end - - private - # For compatibility with ActiveSupport::JSON.encode - def rails_to_json(options, *args) - to_json(options) - end - - class JsonSerializer < ActiveRecord::Serialization::Serializer #:nodoc: - def serialize - ActiveSupport::JSON.encode(serializable_record) - end - end - - module ClassMethods - def json_class_name - @json_class_name ||= name.demodulize.underscore.inspect - end - end end end -- cgit v1.2.3 From 74c1249d0727e6375529e4bb5b2e2ac78f4a91dc Mon Sep 17 00:00:00 2001 From: Eugene Pimenov Date: Thu, 23 Apr 2009 13:45:12 +0400 Subject: PostgreSQL adapter should call thread safe quote_string function Signed-off-by: Michael Koziarski --- .../connection_adapters/postgresql_adapter.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 002696d2c4..18b499904e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -288,7 +288,13 @@ module ActiveRecord # Escapes binary strings for bytea input to the database. def escape_bytea(value) - if PGconn.respond_to?(:escape_bytea) + if @connection.respond_to?(:escape_bytea) + self.class.instance_eval do + define_method(:escape_bytea) do |value| + @connection.escape_bytea(value) if value + end + end + elsif PGconn.respond_to?(:escape_bytea) self.class.instance_eval do define_method(:escape_bytea) do |value| PGconn.escape_bytea(value) if value @@ -377,7 +383,13 @@ module ActiveRecord # Quotes strings for use in SQL input in the postgres driver for better performance. def quote_string(s) #:nodoc: - if PGconn.respond_to?(:escape) + if @connection.respond_to?(:escape) + self.class.instance_eval do + define_method(:quote_string) do |s| + @connection.escape(s) + end + end + elsif PGconn.respond_to?(:escape) self.class.instance_eval do define_method(:quote_string) do |s| PGconn.escape(s) -- cgit v1.2.3