Ticket #8049: unit_tests.diff
| File unit_tests.diff, 15.9 kB (added by FooBarWidget, 1 year ago) |
|---|
-
activerecord/test/migration_test.rb
old new 194 194 Person.connection.create_table :testings do |t| 195 195 t.column :foo, :string 196 196 end 197 198 con = Person.connection 197 198 con = Person.connection 199 199 Person.connection.enable_identity_insert("testings", true) if current_adapter?(:SybaseAdapter) 200 200 Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}) values (1, 'hello')" 201 201 Person.connection.enable_identity_insert("testings", false) if current_adapter?(:SybaseAdapter) … … 278 278 279 279 # Test for 30 significent digits (beyond the 16 of float), 10 of them 280 280 # after the decimal place. 281 281 282 282 assert_equal BigDecimal.new("0012345678901234567890.0123456789"), bob.wealth 283 283 284 284 assert_equal true, bob.male? … … 405 405 t.column :url, :string 406 406 end 407 407 ActiveRecord::Base.connection.add_index :octopuses, :url 408 408 409 409 ActiveRecord::Base.connection.rename_table :octopuses, :octopi 410 410 411 411 # Using explicit id in insert for compatibility across all databases … … 436 436 old_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns") 437 437 assert old_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } 438 438 assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => false } 439 new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns") 439 new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns") 440 440 assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } 441 441 assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false } 442 442 assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true } 443 443 end 444 444 445 445 def test_change_column_with_nil_default 446 446 Person.connection.add_column "people", "contributor", :boolean, :default => true 447 447 Person.reset_column_information 448 448 assert Person.new.contributor? 449 449 450 450 assert_nothing_raised { Person.connection.change_column "people", "contributor", :boolean, :default => nil } 451 451 Person.reset_column_information 452 452 assert !Person.new.contributor? … … 466 466 ensure 467 467 Person.connection.remove_column("people", "administrator") rescue nil 468 468 end 469 469 470 470 def test_change_column_default 471 471 Person.connection.change_column_default "people", "first_name", "Tester" 472 472 Person.reset_column_information … … 731 731 def test_migrator_with_missing_version_numbers 732 732 ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 500) 733 733 assert !Person.column_methods_hash.include?(:middle_name) 734 assert_equal 4, ActiveRecord::Migrator.current_version735 736 ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 2)737 assert !Reminder.table_exists?738 assert Person.column_methods_hash.include?(:last_name) 739 assert_equal 2, ActiveRecord::Migrator.current_version734 assert_equal 4, ActiveRecord::Migrator.current_version 735 736 ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 2) 737 assert !Reminder.table_exists? 738 assert Person.column_methods_hash.include?(:last_name) 739 assert_equal 2, ActiveRecord::Migrator.current_version 740 740 end 741 741 742 742 def test_create_table_with_custom_sequence_name 743 743 return unless current_adapter? :OracleAdapter 744 744 … … 778 778 779 779 end 780 780 end 781 -
activerecord/test/datatype_test_postgresql.rb
old new 1 1 require 'abstract_unit' 2 2 3 class Postgresql Datatype< ActiveRecord::Base3 class PostgresqlArray < ActiveRecord::Base 4 4 end 5 5 6 class PGDataTypeTest < Test::Unit::TestCase 6 class PostgresqlMoney < ActiveRecord::Base 7 end 8 9 class PostgresqlNumber < ActiveRecord::Base 10 end 11 12 class PostgresqlTime < ActiveRecord::Base 13 end 14 15 class PostgresqlNetworkAddress < ActiveRecord::Base 16 end 17 18 class PostgresqlBitString < ActiveRecord::Base 19 end 20 21 class PostgresqlOid < ActiveRecord::Base 22 end 23 24 class PostgresqlDataTypeTest < Test::Unit::TestCase 7 25 self.use_transactional_fixtures = false 8 26 9 TABLE_NAME = 'postgresql_datatypes'10 COLUMNS = [27 ARRAY_TABLE_NAME = 'postgresql_arrays' 28 ARRAY_COLUMNS = [ 11 29 'id SERIAL PRIMARY KEY', 12 30 'commission_by_quarter INTEGER[]', 13 31 'nicknames TEXT[]' 14 32 ] 15 33 34 MONEY_TABLE_NAME = 'postgresql_moneys' 35 MONEY_COLUMNS = [ 36 'id SERIAL PRIMARY KEY', 37 'wealth MONEY' 38 ] 39 40 NUMBER_TABLE_NAME = 'postgresql_numbers' 41 NUMBER_COLUMNS = [ 42 'id SERIAL PRIMARY KEY', 43 'single REAL', 44 'double DOUBLE PRECISION' 45 ] 46 47 TIME_TABLE_NAME = 'postgresql_times' 48 TIME_COLUMNS = [ 49 'id SERIAL PRIMARY KEY', 50 'time_interval INTERVAL' 51 ] 52 53 NETWORK_ADDRESS_TABLE_NAME = 'postgresql_network_addresses' 54 NETWORK_ADDRESS_COLUMNS = [ 55 'id SERIAL PRIMARY KEY', 56 'cidr_address CIDR', 57 'inet_address INET', 58 'mac_address MACADDR' 59 ] 60 61 BIT_STRING_TABLE_NAME = 'postgresql_bit_strings' 62 BIT_STRING_COLUMNS = [ 63 'id SERIAL PRIMARY KEY', 64 'bit_string BIT(8)', 65 'bit_string_varying BIT VARYING(8)' 66 ] 67 68 OID_TABLE_NAME = 'postgresql_oids' 69 OID_COLUMNS = [ 70 'id SERIAL PRIMARY KEY', 71 'obj_id OID' 72 ] 73 16 74 def setup 17 75 @connection = ActiveRecord::Base.connection 18 @connection.execute "CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})" 19 @connection.execute "INSERT INTO #{TABLE_NAME} (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )" 20 @first = PostgresqlDatatype.find( 1 ) 76 77 @connection.execute("CREATE TABLE #{ARRAY_TABLE_NAME} (#{ARRAY_COLUMNS.join(',')})") 78 @connection.execute("INSERT INTO #{ARRAY_TABLE_NAME} (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )") 79 @first_array = PostgresqlArray.find(1) 80 81 @connection.execute("CREATE TABLE #{MONEY_TABLE_NAME} (#{MONEY_COLUMNS.join(',')})") 82 @connection.execute("INSERT INTO #{MONEY_TABLE_NAME} (wealth) VALUES ('$567.89')") 83 @connection.execute("INSERT INTO #{MONEY_TABLE_NAME} (wealth) VALUES ('-$567.89')") 84 @first_money = PostgresqlMoney.find(1) 85 @second_money = PostgresqlMoney.find(2) 86 87 @connection.execute("CREATE TABLE #{NUMBER_TABLE_NAME} (#{NUMBER_COLUMNS.join(',')})") 88 @connection.execute("INSERT INTO #{NUMBER_TABLE_NAME} (single, double) VALUES (123.456, 123456.789)") 89 @first_number = PostgresqlNumber.find(1) 90 91 @connection.execute("CREATE TABLE #{TIME_TABLE_NAME} (#{TIME_COLUMNS.join(',')})") 92 @connection.execute("INSERT INTO #{TIME_TABLE_NAME} (time_interval) VALUES ('1 year 2 days ago')") 93 @first_time = PostgresqlTime.find(1) 94 95 @connection.execute("CREATE TABLE #{NETWORK_ADDRESS_TABLE_NAME} (#{NETWORK_ADDRESS_COLUMNS.join(',')})") 96 @connection.execute("INSERT INTO #{NETWORK_ADDRESS_TABLE_NAME} (cidr_address, inet_address, mac_address) VALUES('192.168.0/24', '172.16.1.254/32', '01:23:45:67:89:0a')") 97 @first_network_address = PostgresqlNetworkAddress.find(1) 98 99 @connection.execute("CREATE TABLE #{BIT_STRING_TABLE_NAME} (#{BIT_STRING_COLUMNS.join(',')})") 100 @connection.execute("INSERT INTO #{BIT_STRING_TABLE_NAME} (bit_string, bit_string_varying) VALUES (B'00010101', X'15')") 101 @first_bit_string = PostgresqlBitString.find(1) 102 103 @connection.execute("CREATE TABLE #{OID_TABLE_NAME} (#{OID_COLUMNS.join(',')})") 104 @connection.execute("INSERT INTO #{OID_TABLE_NAME} (obj_id) VALUES (1234)") 105 @first_oid = PostgresqlOid.find(1) 21 106 end 22 107 23 108 def teardown 24 @connection.execute "DROP TABLE #{TABLE_NAME}" 109 @connection.execute("DROP TABLE #{ARRAY_TABLE_NAME}") 110 @connection.execute("DROP TABLE #{MONEY_TABLE_NAME}") 111 @connection.execute("DROP TABLE #{NUMBER_TABLE_NAME}") 112 @connection.execute("DROP TABLE #{TIME_TABLE_NAME}") 113 @connection.execute("DROP TABLE #{NETWORK_ADDRESS_TABLE_NAME}") 114 @connection.execute("DROP TABLE #{BIT_STRING_TABLE_NAME}") 115 @connection.execute("DROP TABLE #{OID_TABLE_NAME}") 25 116 end 26 117 27 118 def test_data_type_of_array_types 28 assert_equal :string, @first .column_for_attribute("commission_by_quarter").type29 assert_equal :string, @first .column_for_attribute("nicknames").type119 assert_equal :string, @first_array.column_for_attribute("commission_by_quarter").type 120 assert_equal :string, @first_array.column_for_attribute("nicknames").type 30 121 end 31 122 123 def test_data_type_of_money_types 124 assert_equal :decimal, @first_money.column_for_attribute("wealth").type 125 end 126 127 def test_data_type_of_number_types 128 assert_equal :float, @first_number.column_for_attribute("single").type 129 assert_equal :float, @first_number.column_for_attribute("double").type 130 end 131 132 def test_data_type_of_time_types 133 assert_equal :string, @first_time.column_for_attribute("time_interval").type 134 end 135 136 def test_data_type_of_network_address_types 137 assert_equal :string, @first_network_address.column_for_attribute("cidr_address").type 138 assert_equal :string, @first_network_address.column_for_attribute("inet_address").type 139 assert_equal :string, @first_network_address.column_for_attribute("mac_address").type 140 end 141 142 def test_data_type_of_bit_string_types 143 assert_equal :string, @first_bit_string.column_for_attribute("bit_string").type 144 assert_equal :string, @first_bit_string.column_for_attribute("bit_string_varying").type 145 end 146 147 def test_data_type_of_oid_types 148 assert_equal :integer, @first_oid.column_for_attribute("obj_id").type 149 end 150 32 151 def test_array_values 33 assert_equal '{35000,21000,18000,17000}', @first .commission_by_quarter34 assert_equal '{foo,bar,baz}', @first .nicknames152 assert_equal '{35000,21000,18000,17000}', @first_array.commission_by_quarter 153 assert_equal '{foo,bar,baz}', @first_array.nicknames 35 154 end 36 155 156 def test_money_values 157 assert_equal 567.89, @first_money.wealth 158 assert_equal -567.89, @second_money.wealth 159 end 160 161 def test_number_values 162 assert_equal 123.456, @first_number.single 163 assert_equal 123456.789, @first_number.double 164 end 165 166 def test_time_values 167 assert_equal '-1 years -2 days', @first_time.time_interval 168 end 169 170 def test_network_address_values 171 assert_equal '192.168.0.0/24', @first_network_address.cidr_address 172 assert_equal '172.16.1.254', @first_network_address.inet_address 173 assert_equal '01:23:45:67:89:0a', @first_network_address.mac_address 174 end 175 176 def test_bit_string_values 177 assert_equal '00010101', @first_bit_string.bit_string 178 assert_equal '00010101', @first_bit_string.bit_string_varying 179 end 180 181 def test_oid_values 182 assert_equal 1234, @first_oid.obj_id 183 end 184 37 185 def test_update_integer_array 38 186 new_value = '{32800,95000,29350,17000}' 39 assert @first .commission_by_quarter = new_value40 assert @first .save41 assert @first .reload42 assert_equal @first .commission_by_quarter, new_value187 assert @first_array.commission_by_quarter = new_value 188 assert @first_array.save 189 assert @first_array.reload 190 assert_equal @first_array.commission_by_quarter, new_value 43 191 end 44 192 45 193 def test_update_text_array 46 194 new_value = '{robby,robert,rob,robbie}' 47 assert @first .nicknames = new_value48 assert @first .save49 assert @first .reload50 assert_equal @first .nicknames, new_value195 assert @first_array.nicknames = new_value 196 assert @first_array.save 197 assert @first_array.reload 198 assert_equal @first_array.nicknames, new_value 51 199 end 200 201 def test_update_money 202 new_value = 123.45 203 assert @first_money.wealth = new_value 204 assert @first_money.save 205 assert @first_money.reload 206 assert_equal @first_money.wealth, new_value 207 end 208 209 def test_update_number 210 new_single = 789.012 211 new_double = 789012.345 212 assert @first_number.single = new_single 213 assert @first_number.double = new_double 214 assert @first_number.save 215 assert @first_number.reload 216 assert_equal @first_number.single, new_single 217 assert_equal @first_number.double, new_double 218 end 219 220 def test_update_time 221 assert @first_time.time_interval = '2 years 3 minutes' 222 assert @first_time.save 223 assert @first_time.reload 224 assert_equal @first_time.time_interval, '2 years 00:03:00' 225 end 226 227 def test_update_network_address 228 new_cidr_address = '10.1.2.3/32' 229 new_inet_address = '10.0.0.0/8' 230 new_mac_address = 'bc:de:f0:12:34:56' 231 assert @first_network_address.cidr_address = new_cidr_address 232 assert @first_network_address.inet_address = new_inet_address 233 assert @first_network_address.mac_address = new_mac_address 234 assert @first_network_address.save 235 assert @first_network_address.reload 236 assert_equal @first_network_address.cidr_address, new_cidr_address 237 assert_equal @first_network_address.inet_address, new_inet_address 238 assert_equal @first_network_address.mac_address, new_mac_address 239 end 240 241 def test_update_bit_string 242 new_bit_string = '11111111' 243 new_bit_string_varying = 'FF' 244 assert @first_bit_string.bit_string = new_bit_string 245 assert @first_bit_string.bit_string_varying = new_bit_string_varying 246 assert @first_bit_string.save 247 assert @first_bit_string.reload 248 assert_equal @first_bit_string.bit_string, new_bit_string 249 assert_equal @first_bit_string.bit_string, @first_bit_string.bit_string_varying 250 end 251 252 def test_update_oid 253 new_value = 567890 254 assert @first_oid.obj_id = new_value 255 assert @first_oid.save 256 assert @first_oid.reload 257 assert_equal @first_oid.obj_id, new_value 258 end 52 259 end -
activerecord/test/finder_test.rb
old new 232 232 end 233 233 234 234 def test_bind_enumerable 235 quoted_abc = %(#{ActiveRecord::Base.connection.quote('a')},#{ActiveRecord::Base.connection.quote('b')},#{ActiveRecord::Base.connection.quote('c')}) 236 235 237 assert_equal '1,2,3', bind('?', [1, 2, 3]) 236 assert_equal %('a','b','c'), bind('?', %w(a b c))238 assert_equal quoted_abc, bind('?', %w(a b c)) 237 239 238 240 assert_equal '1,2,3', bind(':a', :a => [1, 2, 3]) 239 assert_equal %('a','b','c'), bind(':a', :a => %w(a b c)) # '241 assert_equal quoted_abc, bind(':a', :a => %w(a b c)) # ' 240 242 241 243 require 'set' 242 244 assert_equal '1,2,3', bind('?', Set.new([1, 2, 3])) 243 assert_equal %('a','b','c'), bind('?', Set.new(%w(a b c)))245 assert_equal quoted_abc, bind('?', Set.new(%w(a b c))) 244 246 245 247 assert_equal '1,2,3', bind(':a', :a => Set.new([1, 2, 3])) 246 assert_equal %('a','b','c'), bind(':a', :a => Set.new(%w(a b c))) # '248 assert_equal quoted_abc, bind(':a', :a => Set.new(%w(a b c))) # ' 247 249 end 248 250 249 251 def test_bind_empty_enumerable … … 254 256 end 255 257 256 258 def test_bind_string 257 assert_equal "''", bind('?', '')259 assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '') 258 260 end 259 261 260 262 def test_bind_record … … 267 269 268 270 def test_string_sanitation 269 271 assert_not_equal "'something ' 1=1'", ActiveRecord::Base.sanitize("something ' 1=1") 270 assert_equal "'something; select table'", ActiveRecord::Base.sanitize("something; select table") 272 assert_not_equal "#{ActiveRecord::Base.connection.quoted_string_prefix}'something ' 1=1'", ActiveRecord::Base.sanitize("something ' 1=1") 273 assert_equal "#{ActiveRecord::Base.connection.quoted_string_prefix}'something; select table'", ActiveRecord::Base.sanitize("something; select table") 271 274 end 272 275 273 276 def test_count