Skip to content

Commit

Permalink
column default extraction should handle newlines.
Browse files Browse the repository at this point in the history
Fixes #7374
  • Loading branch information
tenderlove committed Aug 17, 2012
1 parent 8f4ee48 commit 3e8ab91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ def columns(table_name) #:nodoc:
case field["dflt_value"]
when /^null$/i
field["dflt_value"] = nil
when /^'(.*)'$/
when /^'(.*)'$/m
field["dflt_value"] = $1.gsub("''", "'")
when /^"(.*)"$/
when /^"(.*)"$/m
field["dflt_value"] = $1.gsub('""', '"')
end

Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/migration/column_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class ColumnAttributesTest < ActiveRecord::TestCase

self.use_transactional_fixtures = false

def test_add_column_newline_default
string = "foo\nbar"
add_column 'test_models', 'command', :string, :default => string
TestModel.reset_column_information

assert_equal string, TestModel.new.command
end

def test_add_remove_single_field_using_string_arguments
refute TestModel.column_methods_hash.key?(:last_name)

Expand Down

0 comments on commit 3e8ab91

Please sign in to comment.