diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2019-01-30 18:21:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 18:21:16 -0500 |
commit | 0a9bb48f83e287e8a9ca5c74eec4e7f926de5a46 (patch) | |
tree | a967d0611a817c22146e579a4c1465e0ad69732b /activerecord/test/cases | |
parent | e01e64628d237ca3be2210b1b0caeee99f2fb09d (diff) | |
parent | ab952b19496c9569059f2dbb2b1dacaf44e618a8 (diff) | |
download | rails-0a9bb48f83e287e8a9ca5c74eec4e7f926de5a46.tar.gz rails-0a9bb48f83e287e8a9ca5c74eec4e7f926de5a46.tar.bz2 rails-0a9bb48f83e287e8a9ca5c74eec4e7f926de5a46.zip |
Merge pull request #35108 from jhawthorn/db-selection-timestamp-after
Write update_last_write_timestamp after request
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/database_selector_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/activerecord/test/cases/database_selector_test.rb b/activerecord/test/cases/database_selector_test.rb index f961fa754b..6142e223ce 100644 --- a/activerecord/test/cases/database_selector_test.rb +++ b/activerecord/test/cases/database_selector_test.rb @@ -58,6 +58,43 @@ module ActiveRecord assert called end + def test_write_to_primary + resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver.new(@session) + + # Session should start empty + assert_nil @session_store[:last_write] + + called = false + resolver.write do + assert ActiveRecord::Base.connected_to?(role: :writing) + called = true + end + assert called + + # and be populated by the last write time + assert @session_store[:last_write] + end + + def test_write_to_primary_with_exception + resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver.new(@session) + + # Session should start empty + assert_nil @session_store[:last_write] + + called = false + assert_raises(ActiveRecord::RecordNotFound) do + resolver.write do + assert ActiveRecord::Base.connected_to?(role: :writing) + called = true + raise ActiveRecord::RecordNotFound + end + end + assert called + + # and be populated by the last write time + assert @session_store[:last_write] + end + def test_the_middleware_chooses_writing_role_with_POST_request middleware = ActiveRecord::Middleware::DatabaseSelector.new(lambda { |env| assert ActiveRecord::Base.connected_to?(role: :writing) |