Skip to content

Commit b211d4f

Browse files
authored
Fix for the Rails test schema including decimal greater than 38 precision (#1181)
1 parent a3475a2 commit b211d4f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/cases/helper_sqlserver.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require "support/core_ext/query_cache"
88
require "support/minitest_sqlserver"
99
require "support/test_in_memory_oltp"
10+
require "support/table_definition_sqlserver"
1011
require "cases/helper"
1112
require "support/load_schema_sqlserver"
1213
require "support/coerceable_test_sqlserver"
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module ActiveRecord
4+
module ConnectionAdapters
5+
module SQLServer
6+
class TableDefinition < ::ActiveRecord::ConnectionAdapters::TableDefinition
7+
# SQL Server supports precision of 38 for decimal columns. In Rails the test schema includes a column
8+
# with a precision of 55. This is a problem for SQL Server 2008. This method will override the default
9+
# decimal method to limit the precision to 38 for the :atoms_in_universe column.
10+
# See https://github.com/rails/rails/pull/51826/files#diff-2a57b61bbf9ee2c23938fc571d403799f68b4b530d65e2cde219a429bbf10af5L876
11+
def decimal(*names, **options)
12+
throw "This 'decimal' method should only be used in a test environment." unless defined?(ActiveSupport::TestCase)
13+
14+
names.each do |name|
15+
options_for_name = options.dup
16+
options_for_name[:precision] = 38 if name == :atoms_in_universe && options_for_name[:precision].to_i == 55
17+
18+
column(name, :decimal, **options_for_name)
19+
end
20+
end
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)