Ticket #7085: schema_dumper.diff
| File schema_dumper.diff, 5.1 kB (added by ben, 2 years ago) |
|---|
-
activesupport/test/inflector_test.rb
old new 141 141 "Person" => "personid", 142 142 "MyApplication::Billing::Account" => "accountid" 143 143 } 144 145 TableNameToPrimaryKeyWithUnderscore = { 146 'people' => 'person_id' 147 } 144 148 149 TableNameToPrimaryKeyWithoutUnderscore = { 150 'people' => 'personid' 151 } 152 145 153 ClassNameToTableName = { 146 154 "PrimarySpokesman" => "primary_spokesmen", 147 155 "NodeChild" => "node_children" … … 265 273 assert_equal(foreign_key, Inflector.foreign_key(klass, false)) 266 274 end 267 275 end 276 277 def test_primary_key 278 TableNameToPrimaryKeyWithUnderscore.each do |table, primary_key| 279 assert_equal(primary_key, Inflector.primary_key(table)) 280 end 281 282 TableNameToPrimaryKeyWithoutUnderscore.each do |table, primary_key| 283 assert_equal(primary_key, Inflector.primary_key(table, false)) 284 end 285 end 268 286 269 287 def test_tableize 270 288 ClassNameToTableName.each do |class_name, table_name| -
activesupport/lib/active_support/inflector.rb
old new 234 234 def foreign_key(class_name, separate_class_name_and_id_with_underscore = true) 235 235 underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id") 236 236 end 237 238 def primary_key(table_name, separate_class_name_and_id_with_underscore = true) 239 singularize(table_name) + (separate_class_name_and_id_with_underscore ? "_id" : "id") 240 end 237 241 238 242 # Constantize tries to find a declared constant with the name specified 239 243 # in the string. It raises a NameError when the name is not in CamelCase -
activerecord/test/schema_dumper_test.rb
old new 96 96 output = stream.string 97 97 assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output 98 98 end 99 100 def test_tablename_primary_key 101 ActiveRecord::Base.primary_key_prefix_type = :table_name 102 output = standard_dump 103 assert_no_match %r{create_table "prefixes", :id => false}, output 104 assert_match %r{create_table "prefixes", :primary_key => "prefixid"}, output 105 ActiveRecord::Base.primary_key_prefix_type = nil 106 end 107 108 def test_tablename_with_underscore_primary_key 109 ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore 110 output = standard_dump 111 assert_no_match %r{create_table "underscored_prefixes", :id => false}, output 112 assert_match %r{create_table "underscored_prefixes", :primary_key => "underscored_prefix_id"}, output 113 ActiveRecord::Base.primary_key_prefix_type = nil 114 end 99 115 end 100 116 101 117 end -
activerecord/test/fixtures/db_definitions/mysql.sql
old new 226 226 `my_house_population` decimal(2), 227 227 `decimal_number_with_default` decimal(3,2) DEFAULT 2.78 228 228 ) TYPE=InnoDB; 229 230 CREATE TABLE `prefixes` ( 231 `prefixid` int(11) NOT NULL auto_increment, 232 `name` VARCHAR(255) NOT NULL, 233 PRIMARY KEY (`prefixid`) 234 ) TYPE=InnoDB; 235 236 CREATE TABLE `underscored_prefixes` ( 237 `underscored_prefix_id` int(11) NOT NULL auto_increment, 238 `name` VARCHAR(255) NOT NULL, 239 PRIMARY KEY (`underscored_prefix_id`) 240 ) TYPE=InnoDB; -
activerecord/test/fixtures/db_definitions/mysql.drop.sql
old new 29 29 DROP TABLE keyboards; 30 30 DROP TABLE legacy_things; 31 31 DROP TABLE numeric_data; 32 DROP TABLE prefixes; 33 DROP TABLE underscored_prefixes; -
activerecord/lib/active_record/schema_dumper.rb
old new 72 72 if @connection.respond_to?(:pk_and_sequence_for) 73 73 pk, pk_seq = @connection.pk_and_sequence_for(table) 74 74 end 75 pk ||= 'id' 75 pk ||= 76 case ActiveRecord::Base.primary_key_prefix_type 77 when :table_name 78 Inflector.primary_key(table, false) 79 when :table_name_with_underscore 80 Inflector.primary_key(table) 81 else 82 "id" 83 end 76 84 77 85 tbl.print " create_table #{table.inspect}" 78 86 if columns.detect { |c| c.name == pk }