aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-01-02 09:12:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-01-02 09:12:11 +0900
commit0dec2b5aa367d4f858e7878f1f5d1fcda2dd37de (patch)
treea0e4dd5e9549c6ca4ede2e9d723449e60ef17d59 /activerecord
parent3d5db4920a3d5fb0bdd4a912fd5e29eec12ef02e (diff)
downloadrails-0dec2b5aa367d4f858e7878f1f5d1fcda2dd37de.tar.gz
rails-0dec2b5aa367d4f858e7878f1f5d1fcda2dd37de.tar.bz2
rails-0dec2b5aa367d4f858e7878f1f5d1fcda2dd37de.zip
Add assertions for `ActiveRecord::Base.current_role`
Since the `current_role` is public API.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb b/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb
index 0b3fb82e12..865aacc1b5 100644
--- a/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb
@@ -108,6 +108,7 @@ module ActiveRecord
ActiveRecord::Base.connected_to(role: :reading) do
@ro_handler = ActiveRecord::Base.connection_handler
assert_equal ActiveRecord::Base.connection_handler, ActiveRecord::Base.connection_handlers[:reading]
+ assert_equal :reading, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :reading)
assert_not ActiveRecord::Base.connected_to?(role: :writing)
end
@@ -115,6 +116,7 @@ module ActiveRecord
ActiveRecord::Base.connected_to(role: :writing) do
assert_equal ActiveRecord::Base.connection_handler, ActiveRecord::Base.connection_handlers[:writing]
assert_not_equal @ro_handler, ActiveRecord::Base.connection_handler
+ assert_equal :writing, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :writing)
assert_not ActiveRecord::Base.connected_to?(role: :reading)
end
@@ -129,6 +131,7 @@ module ActiveRecord
previous_url, ENV["DATABASE_URL"] = ENV["DATABASE_URL"], "postgres://localhost/foo"
ActiveRecord::Base.connected_to(database: { writing: "postgres://localhost/bar" }) do
+ assert_equal :writing, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :writing)
handler = ActiveRecord::Base.connection_handler
@@ -148,6 +151,7 @@ module ActiveRecord
config = { adapter: "sqlite3", database: "db/readonly.sqlite3" }
ActiveRecord::Base.connected_to(database: { writing: config }) do
+ assert_equal :writing, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :writing)
handler = ActiveRecord::Base.connection_handler
@@ -187,6 +191,7 @@ module ActiveRecord
@prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config
ActiveRecord::Base.connected_to(database: :readonly) do
+ assert_equal :readonly, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :readonly)
handler = ActiveRecord::Base.connection_handler
@@ -211,6 +216,7 @@ module ActiveRecord
assert_equal 1, ActiveRecord::Base.connection_handlers.size
assert_equal ActiveRecord::Base.connection_handler, ActiveRecord::Base.connection_handlers[:writing]
+ assert_equal :writing, ActiveRecord::Base.current_role
assert ActiveRecord::Base.connected_to?(role: :writing)
ensure
ActiveRecord::Base.configurations = @prev_configs