Skip to content

Commit 1a619a6

Browse files
committed
Columns with multi-line defaults work correctly.
1 parent b316f53 commit 1a619a6

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
MASTER
33

4+
* Columns with multi-line defaults work correctly. [bfabry]
45

56

67
* 2.2.22 * (October 15th, 2009)

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ def column_definitions(table_name)
10821082
when nil, '(null)', '(NULL)'
10831083
nil
10841084
else
1085-
match_data = ci[:default_value].match(/\A\(+N?'?(.*?)'?\)+\Z/)
1085+
match_data = ci[:default_value].match(/\A\(+N?'?(.*?)'?\)+\Z/m)
10861086
match_data ? match_data[1] : nil
10871087
end
10881088
ci[:null] = ci[:is_nullable].to_i == 1 ; ci.delete(:is_nullable)

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ class SqlServerEdgeSchema < ActiveRecord::Base; end;
55

66
class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
77

8+
should 'cope with multi line defaults' do
9+
default = StringDefault.new
10+
assert_equal "Some long default with a\nnew line.", default.string_with_multiline_default
11+
end
12+
813
should 'default strings before save' do
914
default = StringDefault.new
1015
assert_equal nil, default.string_with_null_default

test/schema/sqlserver_specific_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
t.column :string_with_pretend_null_three, :string, :default => 'NULL'
1818
t.column :string_with_pretend_null_four, :string, :default => '(NULL)'
1919
t.column :string_with_pretend_paren_three, :string, :default => '(3)'
20+
t.column :string_with_multiline_default, :string, :default => "Some long default with a\nnew line."
2021
end
2122

2223
create_table :sql_server_chronics, :force => true do |t|

0 commit comments

Comments
 (0)