|
| 1 | +require 'bundler/inline' |
| 2 | + |
| 3 | +gemfile do |
| 4 | + source 'https://rubygems.org' |
| 5 | + gem 'rails', '~> 7.1.0' |
| 6 | + # gem 'activerecord-sqlserver-adapter', '~> 7.1.11' |
| 7 | + |
| 8 | + gem 'activerecord-sqlserver-adapter', path: "." |
| 9 | + # |
| 10 | + gem 'tiny_tds' |
| 11 | + |
| 12 | + gem "pry" |
| 13 | +end |
| 14 | + |
| 15 | +require 'active_record' |
| 16 | + |
| 17 | +# Configure database connection |
| 18 | +ActiveRecord::Base.establish_connection( |
| 19 | + adapter: 'sqlserver', |
| 20 | + host: 'sqlserver', # Replace with your SQL Server host |
| 21 | + database: 'activerecord_unittest', # Replace with your database |
| 22 | + username: 'rails', # Replace with your username |
| 23 | + password: '' # Replace with your password |
| 24 | +) |
| 25 | + |
| 26 | +# This should trigger the bug |
| 27 | +begin |
| 28 | + puts "Attempting to call use_database as first operation..." |
| 29 | + ActiveRecord::Base.connection.use_database('activerecord_unittest') |
| 30 | + puts "Success: No error occurred" |
| 31 | +rescue NoMethodError => e |
| 32 | + puts "BUG REPRODUCED: #{e.message}" |
| 33 | + puts "Error class: #{e.class}" |
| 34 | + puts "Backtrace:" |
| 35 | + puts e.backtrace.first(10) |
| 36 | +end |
| 37 | + |
| 38 | +# Workaround: Force connection establishment first |
| 39 | +# begin |
| 40 | +# puts "\nTesting workaround - establishing connection first..." |
| 41 | +# ActiveRecord::Base.connection.execute('SELECT 1') # calling something like ActiveRecord::Base.connection.raw_connection _also_ works |
| 42 | +# ActiveRecord::Base.connection.use_database('activerecord_unittest') |
| 43 | +# puts "Workaround successful" |
| 44 | +# rescue => e |
| 45 | +# puts "Workaround failed: #{e.message}" |
| 46 | +# end |
0 commit comments