Ticket #5896: uniq_with_adapters.diff
| File uniq_with_adapters.diff, 7.5 kB (added by me@julik.nl, 2 years ago) |
|---|
-
test/fixtures/developer.rb
old new 10 10 end 11 11 end 12 12 13 require 'ipaddr' 14 15 # Convert the integer form of an IP to string 16 def inet_ntoa(n) 17 n.nil? ? nil : ([n].pack("N").unpack("C*").join ".") 18 end 19 13 20 class Developer < ActiveRecord::Base 14 21 has_and_belongs_to_many :projects do 15 22 def find_most_recent … … 33 40 34 41 validates_inclusion_of :salary, :in => 50000..200000 35 42 validates_length_of :name, :within => 3..20 43 44 def machine_ip 45 inet_ntoa(read_attribute(:machine_ip)) 46 end 47 48 def machine_ip=(n) 49 write_attribute(:machine_ip, IPAddr.new(n).to_i) 50 end 36 51 end 37 52 38 53 DeveloperSalary = Struct.new(:amount) -
test/fixtures/developers.yml
old new 2 2 id: 1 3 3 name: David 4 4 salary: 80000 5 machine_ip: 1179946852 5 6 6 7 jamis: 7 8 id: 2 8 9 name: Jamis 9 10 salary: 150000 11 machine_ip: 1179946854 10 12 11 13 <% for digit in 3..10 %> 12 14 dev_<%= digit %>: -
test/fixtures/db_definitions/frontbase.sql
old new 49 49 salary integer DEFAULT 70000, 50 50 created_at timestamp, 51 51 updated_at timestamp, 52 machine_ip integer default 0, 52 53 PRIMARY KEY (id) 53 54 ); 54 55 SET UNIQUE FOR developers(id); -
test/fixtures/db_definitions/openbase.sql
old new 41 41 name char(100), 42 42 salary integer DEFAULT 70000, 43 43 created_at datetime, 44 updated_at datetime 44 updated_at datetime, 45 machine_ip integer default 0 45 46 ) 46 47 go 47 48 CREATE PRIMARY KEY developers (id) -
test/fixtures/db_definitions/sqlite.sql
old new 40 40 'name' TEXT DEFAULT NULL, 41 41 'salary' INTEGER DEFAULT 70000, 42 42 'created_at' DATETIME DEFAULT NULL, 43 'updated_at' DATETIME DEFAULT NULL 43 'updated_at' DATETIME DEFAULT NULL, 44 `machine_ip` INTEGER DEFAULT NULL 44 45 ); 45 46 46 47 CREATE TABLE 'projects' ( -
test/fixtures/db_definitions/mysql.sql
old new 45 45 `salary` int(11) default 70000, 46 46 `created_at` datetime default NULL, 47 47 `updated_at` datetime default NULL, 48 `machine_ip` int(10) default NULL, 48 49 PRIMARY KEY (`id`) 49 50 ) TYPE=InnoDB; 50 51 -
test/fixtures/db_definitions/oracle.sql
old new 69 69 salary integer default 70000, 70 70 created_at timestamp default null, 71 71 updated_at timestamp default null, 72 machine_ip integer default 0, 72 73 primary key (id) 73 74 ); 74 75 create sequence developers_seq minvalue 10000; -
test/fixtures/db_definitions/db2.sql
old new 58 58 developer_id INT NOT NULL, 59 59 project_id INT NOT NULL, 60 60 joined_on DATE DEFAULT NULL, 61 access_level SMALLINT DEFAULT 1 61 access_level SMALLINT DEFAULT 1, 62 machine_ip INT DEFAULT NULL 62 63 ); 63 64 64 65 CREATE TABLE orders ( -
test/fixtures/db_definitions/sqlserver.sql
old new 39 39 name varchar(100) default NULL, 40 40 salary int default 70000, 41 41 created_at datetime default NULL, 42 updated_at datetime default NULL 42 updated_at datetime default NULL, 43 machine_ip int default 0 43 44 ); 44 45 45 46 CREATE TABLE projects ( -
test/fixtures/db_definitions/firebird.sql
old new 54 54 salary INTEGER DEFAULT 70000, 55 55 created_at TIMESTAMP, 56 56 updated_at TIMESTAMP, 57 machine_ip INTEGER DEFAULT 0 57 58 PRIMARY KEY (id) 58 59 ); 59 60 CREATE GENERATOR developers_seq; -
test/fixtures/db_definitions/sybase.sql
old new 40 40 name varchar(100) NULL, 41 41 salary int default 70000, 42 42 created_at datetime NULL, 43 updated_at datetime NULL 43 updated_at datetime NULL, 44 machine_ip int default 0 44 45 ) 45 46 46 47 CREATE TABLE projects ( -
test/fixtures/db_definitions/postgresql.sql
old new 38 38 salary integer DEFAULT 70000, 39 39 created_at timestamp, 40 40 updated_at timestamp, 41 machine_ip integer default 0, 41 42 PRIMARY KEY (id) 42 43 ); 43 44 SELECT setval('developers_id_seq', 100); -
test/validations_test.rb
old new 266 266 t2.title = "Now Im really also unique" 267 267 assert t2.save, "Should now save t2 as unique" 268 268 end 269 270 def test_validate_uniqueness_with_custom_accessors 271 david = Developer.find(1) 272 jamis = Developer.find(2) 273 274 assert_equal "70.84.143.100", david.machine_ip 275 assert_equal "70.84.143.102", jamis.machine_ip 276 277 jamis.machine_ip = "70.84.143.100" 278 assert jamis.valid? 279 Developer.validates_uniqueness_of(:machine_ip) 280 assert !jamis.valid?, "The integer value should be used for validation" 281 end 269 282 270 283 def test_validate_uniqueness_with_scope 271 284 Reply.validates_uniqueness_of(:content, :scope => "parent_id") -
lib/active_record/validations.rb
old new 526 526 validates_each(attr_names,configuration) do |record, attr_name, value| 527 527 if value.nil? || (configuration[:case_sensitive] || !columns_hash[attr_name.to_s].text?) 528 528 condition_sql = "#{record.class.table_name}.#{attr_name} #{attribute_condition(value)}" 529 condition_params = [ value]529 condition_params = [record.send(:read_attribute, attr_name)] 530 530 else 531 531 condition_sql = "UPPER(#{record.class.table_name}.#{attr_name}) #{attribute_condition(value)}" 532 condition_params = [ value.upcase]532 condition_params = [record.send(:read_attribute, attr_name).upcase] 533 533 end 534 534 if scope = configuration[:scope] 535 535 Array(scope).map do |scope_item|