From 656fb866f91a87677ce501d3c9ad6aba9048d00f Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 6 Oct 2005 04:15:14 +0000 Subject: Quote booleans according the rules defined by the adapter * SQLite schema has been updated * Postgresql schema needs to be fixed too Simplify AR::Base#toggle to store the boolean, not the quoted value * expand the tests git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2474 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 2 +- .../lib/active_record/connection_adapters/abstract/quoting.rb | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 0e1c28e330..1c063c003d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1094,7 +1094,7 @@ module ActiveRecord #:nodoc: # Turns an +attribute+ that's currently true into false and vice versa. Returns self. def toggle(attribute) - self[attribute] = quote(!send("#{attribute}?", column_for_attribute(attribute))) + self[attribute] = !send("#{attribute}?") self end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index c8088bd978..c7e7d83ca1 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -14,11 +14,11 @@ module ActiveRecord "'#{quote_string(value)}'" # ' (for ruby-mode) end when NilClass then "NULL" - when TrueClass then (column && column.type == :boolean ? quoted_true : "1") - when FalseClass then (column && column.type == :boolean ? quoted_false : "0") + when TrueClass then (column && column.type == :integer ? '1' : quoted_true) + when FalseClass then (column && column.type == :integer ? '0' : quoted_false) when Float, Fixnum, Bignum then value.to_s when Date then "'#{value.to_s}'" - when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'" + when Time, DateTime then "'#{quoted_date(value)}'" else "'#{quote_string(value.to_yaml)}'" end end @@ -42,6 +42,10 @@ module ActiveRecord def quoted_false "'f'" end + + def quoted_date(value) + value.strftime("%Y-%m-%d %H:%M:%S") + end end end end \ No newline at end of file -- cgit v1.2.3