From 2db8514d218068cae7b37b7939ed3ba812407105 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 25 Apr 2016 07:54:56 +0900 Subject: [PATCH] Treat blank comments as no comment for indexes Follow up of 1683410. Signed-off-by: Jeremy Daer --- .../postgresql/schema_statements.rb | 2 +- .../connection_adapters/postgresql_adapter.rb | 4 ---- activerecord/test/cases/comment_test.rb | 11 ++++++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 074ebb90a5..6318b1c65a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -217,7 +217,7 @@ def indexes(table_name, name = nil) ] end - IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment) + IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment.presence) end.compact end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 39a2cbbda7..bab80a8890 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -168,10 +168,6 @@ def supports_comments? true end - def supports_comments_in_create? - false - end - def supports_savepoints? true end diff --git a/activerecord/test/cases/comment_test.rb b/activerecord/test/cases/comment_test.rb index 37d951ad88..839fdbe578 100644 --- a/activerecord/test/cases/comment_test.rb +++ b/activerecord/test/cases/comment_test.rb @@ -5,7 +5,6 @@ class CommentTest < ActiveRecord::TestCase include SchemaDumpingHelper - self.use_transactional_tests = false if current_adapter?(:Mysql2Adapter) class Commented < ActiveRecord::Base self.table_name = 'commenteds' @@ -29,6 +28,10 @@ class BlankComment < ActiveRecord::Base t.string :empty_comment, comment: '' t.string :nil_comment, comment: nil t.string :absent_comment + t.index :space_comment, comment: ' ' + t.index :empty_comment, comment: '' + t.index :nil_comment, comment: nil + t.index :absent_comment end Commented.reset_column_information @@ -54,6 +57,12 @@ def test_blank_columns_created_in_block end end + def test_blank_indexes_created_in_block + @connection.indexes('blank_comments').each do |index| + assert_nil index.comment + end + end + def test_add_column_with_comment_later @connection.add_column :commenteds, :rating, :integer, comment: 'I am running out of imagination' Commented.reset_column_information