Skip to content

Commit 7d786ea

Browse files
authored
Merge pull request rails#54581 from Edouard-chin/ec-rails-const
Fix test when Rails may not be defined:
2 parents 324fccf + e4fb299 commit 7d786ea

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)