Skip to content

Commit 8d2b737

Browse files
author
Felix Gebhard
committed
fix column_initialization, translate_exception,...
1 parent fe26f9a commit 8d2b737

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ else
3434
end
3535
end
3636

37-
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v6.0.2.1"
37+
gem 'rails', git: "https://github.com/rails/rails.git", tag: "v6.0.2.1"
3838
# gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
3939
end
4040

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ def initialize_type_map(m = type_map)
321321
m.register_type 'timestamp', SQLServer::Type::Timestamp.new
322322
end
323323

324-
def translate_exception(e, message)
324+
def translate_exception(e, message:, sql:, binds:)
325325
case message
326326
when /(cannot insert duplicate key .* with unique index) | (violation of unique key constraint)/i
327327
RecordNotUnique.new(message)
328328
when /conflicted with the foreign key constraint/i
329329
InvalidForeignKey.new(message)
330330
when /has been chosen as the deadlock victim/i
331331
DeadlockVictim.new(message)
332-
when /database .* does not exist/i
332+
when /'doesnotexist'((?!').)*does not exist/
333333
NoDatabaseError.new(message)
334334
when /data would be truncated/
335335
ValueTooLong.new(message)

lib/active_record/connection_adapters/sqlserver_column.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ module ActiveRecord
22
module ConnectionAdapters
33
class SQLServerColumn < Column
44

5-
def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment = nil, **)
6-
@sqlserver_options = {}
7-
@name = name.freeze
8-
@sql_type_metadata = sql_type_metadata
9-
@null = null
10-
@default = default
11-
@default_function = default_function
12-
@collation = collation
13-
@comment = comment
5+
def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment = nil, **sqlserver_options)
6+
@sqlserver_options = sqlserver_options || {}
7+
@table_name = table_name
8+
super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment, **sqlserver_options)
9+
end
10+
11+
def table_name
12+
@table_name
1413
end
1514

1615
def is_identity?

test/cases/migration_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
2020
it 'not create a tables if error in migrations' do
2121
begin
2222
migrations_dir = File.join ARTest::SQLServer.migrations_root, 'transaction_table'
23-
quietly { ActiveRecord::MigrationContext.new(migrations_dir).up }
23+
quietly { ActiveRecord::MigrationContext.new(migrations_dir, ActiveRecord::SchemaMigration).up } # TODO: ActiveRecord::SchemaMigration???
2424
rescue Exception => e
2525
assert_match %r|this and all later migrations canceled|, e.message
2626
end

test/cases/rake_test_sqlserver.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ class SQLServerRakeDropTest < SQLServerRakeTest
7777
end
7878

7979
it 'prints error message when database does not exist' do
80-
message = capture(:stderr) { db_tasks.drop configuration.merge('database' => 'doesnotexist') }
81-
_(message).must_match %r{'doesnotexist' does not exist}
80+
message = capture(:stderr) {
81+
db_tasks.drop configuration.merge('database' => 'doesnotexist')
82+
}
83+
_(message).must_match %r{'doesnotexist'((?!').)*does not exist}
8284
end
8385

8486
end

0 commit comments

Comments
 (0)