Skip to content

Fix for the Rails test schema including decimal greater than 38 precision #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "support/core_ext/query_cache"
require "support/minitest_sqlserver"
require "support/test_in_memory_oltp"
require "support/table_definition_sqlserver"
require "cases/helper"
require "support/load_schema_sqlserver"
require "support/coerceable_test_sqlserver"
Expand Down
24 changes: 24 additions & 0 deletions test/support/table_definition_sqlserver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
module SQLServer
class TableDefinition < ::ActiveRecord::ConnectionAdapters::TableDefinition
# SQL Server supports precision of 38 for decimal columns. In Rails the test schema includes a column
# with a precision of 55. This is a problem for SQL Server 2008. This method will override the default
# decimal method to limit the precision to 38 for the :atoms_in_universe column.
# See https://github.com/rails/rails/pull/51826/files#diff-2a57b61bbf9ee2c23938fc571d403799f68b4b530d65e2cde219a429bbf10af5L876
def decimal(*names, **options)
throw "This 'decimal' method should only be used in a test environment." unless defined?(ActiveSupport::TestCase)

names.each do |name|
options_for_name = options.dup
options_for_name[:precision] = 38 if name == :atoms_in_universe && options_for_name[:precision].to_i == 55

column(name, :decimal, **options_for_name)
end
end
end
end
end
end
Loading