Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2474

Show
Ignore:
Timestamp:
10/06/05 04:15:14 (5 years ago)
Author:
nzkoz
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/base.rb

    r2434 r2474  
    10951095      # Turns an +attribute+ that's currently true into false and vice versa. Returns self. 
    10961096      def toggle(attribute) 
    1097         self[attribute] = quote(!send("#{attribute}?", column_for_attribute(attribute))
     1097        self[attribute] = !send("#{attribute}?"
    10981098        self 
    10991099      end 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

    r2371 r2474  
    1515            end 
    1616          when NilClass              then "NULL" 
    17           when TrueClass             then (column && column.type == :boolean ? quoted_true : "1"
    18           when FalseClass            then (column && column.type == :boolean ? quoted_false : "0"
     17          when TrueClass             then (column && column.type == :integer ? '1' : quoted_true
     18          when FalseClass            then (column && column.type == :integer ? '0' : quoted_false
    1919          when Float, Fixnum, Bignum then value.to_s 
    2020          when Date                  then "'#{value.to_s}'" 
    21           when Time, DateTime        then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'" 
     21          when Time, DateTime        then "'#{quoted_date(value)}'" 
    2222          else                            "'#{quote_string(value.to_yaml)}'" 
    2323        end 
     
    4343        "'f'" 
    4444      end 
     45       
     46      def quoted_date(value) 
     47        value.strftime("%Y-%m-%d %H:%M:%S") 
     48      end 
    4549    end 
    4650  end 
  • trunk/activerecord/test/base_test.rb

    r2378 r2474  
    381381 
    382382  def test_update_by_condition 
    383     Topic.update_all "content = 'bulk updated!'", "approved = 1" 
     383    Topic.update_all "content = 'bulk updated!'", ["approved = ?", true] 
    384384    assert_equal "Have a nice day", Topic.find(1).content 
    385385    assert_equal "bulk updated!", Topic.find(2).content 
     
    813813    topics(:first).toggle!(:approved) 
    814814    assert topics(:first).approved? 
     815    topic = topics(:first) 
     816    topic.toggle(:approved) 
     817    assert !topic.approved? 
     818    topic.reload 
     819    assert topic.approved? 
    815820  end 
    816821 
  • trunk/activerecord/test/deprecated_finder_test.rb

    r1583 r2474  
    3939   
    4040  def test_deprecated_find_on_conditions 
    41     assert Topic.find_on_conditions(1, "approved = 0"
    42     assert_raises(ActiveRecord::RecordNotFound) { Topic.find_on_conditions(1, "approved = 1") } 
     41    assert Topic.find_on_conditions(1, ["approved = ?", false]
     42    assert_raises(ActiveRecord::RecordNotFound) { Topic.find_on_conditions(1, ["approved = ?", true]) } 
    4343  end 
    4444   
  • trunk/activerecord/test/finder_test.rb

    r2324 r2474  
    101101 
    102102  def test_find_on_conditions 
    103     assert Topic.find(1, :conditions => "approved = 0"
    104     assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => "approved = 1") } 
     103    assert Topic.find(1, :conditions => ["approved = ?", false]
     104    assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => ["approved = ?", true]) } 
    105105  end 
    106106   
  • trunk/activerecord/test/fixtures/db_definitions/sqlite.sql

    r2040 r2474  
    2525  'last_read' DATE DEFAULT NULL, 
    2626  'content' TEXT, 
    27   'approved' INTEGER DEFAULT 1
     27  'approved' boolean DEFAULT 'f'
    2828  'replies_count' INTEGER DEFAULT 0, 
    2929  'parent_id' INTEGER DEFAULT NULL, 
  • trunk/activerecord/test/fixtures/topics.yml

    r2178 r2474  
    88  bonus_time: 2005-01-30t15:28:00.00+01:00 
    99  content: Have a nice day 
    10   approved: '0' 
     10  approved: false 
    1111  replies_count: 0 
    1212 
     
    1717  written_on: 2003-07-15t15:28:00.00+01:00 
    1818  content: Have a nice day 
    19   approved: '1' 
     19  approved: true 
    2020  replies_count: 2 
    2121  parent_id: 1