Skip to content

Commit e4fb299

Browse files
committed
Fix test when Rails may not be defined:
- Fix rails#54579 - I don't think it's worth moving that test to the railties suite, it's simple enough that we can stub a constant. - Worth to note: Reproducing the problem is dependent on the gem you have globally installed. But if you have never installed railties, and you run this test without activating the bundler spec (.e.g `ruby -I"lib:test test_file.rb`), this would cause the problem.
1 parent 00cc4ff commit e4fb299

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

activerecord/test/cases/adapters/sqlite3/dbconsole_test.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ def test_sqlite3_db_absolute_path
4343
def test_sqlite3_db_with_defined_rails_root
4444
config = make_db_config(adapter: "sqlite3", database: "config/db.sqlite3")
4545

46-
Rails.define_singleton_method(:root, &method(:root))
46+
root = method(:root)
47+
mod = Module.new { define_singleton_method(:root, &root) }
4748

48-
assert_find_cmd_and_exec_called_with(["sqlite3", Rails.root.join("config/db.sqlite3").to_s]) do
49-
SQLite3Adapter.dbconsole(config)
49+
stub_const(Object, :Rails, mod, exists: defined?(Rails)) do
50+
assert_find_cmd_and_exec_called_with(["sqlite3", Rails.root.join("config/db.sqlite3").to_s]) do
51+
SQLite3Adapter.dbconsole(config)
52+
end
5053
end
51-
ensure
52-
Rails.singleton_class.remove_method(:root)
5354
end
5455

5556
def test_sqlite3_can_use_alternative_cli

0 commit comments

Comments
 (0)