From c03c519db0f5bcbb9f1151db5774921ea9bd3a22 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Fri, 20 Apr 2018 20:12:24 -0400 Subject: Relax assertions in connection config tests At the moment these two ActiveRecord tests pass with `rake test:sqlite3`, but fail with `ARCONN=sqlite3 bin/test`. `Rails.root` is defined when running `bin/test`, but not when running the rake task. When `Rails.root` is defined, `config[:database]` will look something like `vagrant/rails/activerecord/db/primary.sqlite3` instead of just `db/primary.sqlite3`. (See https://github.com/rails/rails/blob/00caf95e14b90782ab17fbd6d2b930844df99980/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L27) Relaxing `assert_equal` to `assert_match` will allow these tests to pass regardless of how they are run. I do have a question why we need both ways to run tests. I have been using `bin/test` lately, but I see from #32426 that this is not the preferred method. --- .../test/cases/connection_adapters/connection_handler_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index 57b3a5844e..b8e623f17b 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -89,7 +89,7 @@ module ActiveRecord ActiveRecord::Base.establish_connection - assert_equal "db/primary.sqlite3", ActiveRecord::Base.connection.pool.spec.config[:database] + assert_match "db/primary.sqlite3", ActiveRecord::Base.connection.pool.spec.config[:database] ensure ActiveRecord::Base.configurations = @prev_configs ENV["RAILS_ENV"] = previous_env @@ -112,7 +112,7 @@ module ActiveRecord ActiveRecord::Base.establish_connection - assert_equal "db/primary.sqlite3", ActiveRecord::Base.connection.pool.spec.config[:database] + assert_match "db/primary.sqlite3", ActiveRecord::Base.connection.pool.spec.config[:database] ensure ActiveRecord::Base.configurations = @prev_configs ENV["RAILS_ENV"] = previous_env -- cgit v1.2.3