Changeset 2474
- Timestamp:
- 10/06/05 04:15:14 (5 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (2 diffs)
- trunk/activerecord/test/deprecated_finder_test.rb (modified) (1 diff)
- trunk/activerecord/test/finder_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/db_definitions/sqlite.sql (modified) (1 diff)
- trunk/activerecord/test/fixtures/topics.yml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/base.rb
r2434 r2474 1095 1095 # Turns an +attribute+ that's currently true into false and vice versa. Returns self. 1096 1096 def toggle(attribute) 1097 self[attribute] = quote(!send("#{attribute}?", column_for_attribute(attribute)))1097 self[attribute] = !send("#{attribute}?") 1098 1098 self 1099 1099 end trunk/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
r2371 r2474 15 15 end 16 16 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) 19 19 when Float, Fixnum, Bignum then value.to_s 20 20 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)}'" 22 22 else "'#{quote_string(value.to_yaml)}'" 23 23 end … … 43 43 "'f'" 44 44 end 45 46 def quoted_date(value) 47 value.strftime("%Y-%m-%d %H:%M:%S") 48 end 45 49 end 46 50 end trunk/activerecord/test/base_test.rb
r2378 r2474 381 381 382 382 def test_update_by_condition 383 Topic.update_all "content = 'bulk updated!'", "approved = 1"383 Topic.update_all "content = 'bulk updated!'", ["approved = ?", true] 384 384 assert_equal "Have a nice day", Topic.find(1).content 385 385 assert_equal "bulk updated!", Topic.find(2).content … … 813 813 topics(:first).toggle!(:approved) 814 814 assert topics(:first).approved? 815 topic = topics(:first) 816 topic.toggle(:approved) 817 assert !topic.approved? 818 topic.reload 819 assert topic.approved? 815 820 end 816 821 trunk/activerecord/test/deprecated_finder_test.rb
r1583 r2474 39 39 40 40 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]) } 43 43 end 44 44 trunk/activerecord/test/finder_test.rb
r2324 r2474 101 101 102 102 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]) } 105 105 end 106 106 trunk/activerecord/test/fixtures/db_definitions/sqlite.sql
r2040 r2474 25 25 'last_read' DATE DEFAULT NULL, 26 26 'content' TEXT, 27 'approved' INTEGER DEFAULT 1,27 'approved' boolean DEFAULT 'f', 28 28 'replies_count' INTEGER DEFAULT 0, 29 29 'parent_id' INTEGER DEFAULT NULL, trunk/activerecord/test/fixtures/topics.yml
r2178 r2474 8 8 bonus_time: 2005-01-30t15:28:00.00+01:00 9 9 content: Have a nice day 10 approved: '0'10 approved: false 11 11 replies_count: 0 12 12 … … 17 17 written_on: 2003-07-15t15:28:00.00+01:00 18 18 content: Have a nice day 19 approved: '1'19 approved: true 20 20 replies_count: 2 21 21 parent_id: 1