I want to have ability to use single writable connection in test environment even within with_readonly blocks.
Problem
I prefer to use Rails use_transactional_tests as it greatly speed ups tests and I don't need to worry about data cleanup.
However, it doesn't work with switch_point gem as queries run within with_readonly blocks doesn't see test data as it exists only within transactions that won't be commited.
See #4 for details.
Environment
switch_point 0.8.0
rails 5.2.3
rspec 3.9.0
rspec-rails-4.0.1
Configuration:
RSpec.configure do |config|
config.use_transactional_fixtures = true
end
SwitchPoint.configure do |config|
config.auto_writable = true
raksul_config = {
readonly: :"#{Rails.env}_readonly",
writable: :"#{Rails.env}"
}
config.define_switch_point :raksul, raksul_config
end
SwitchPoint::writable!(:raksul)
Workaround
Don't declare readonly database in test environment:
SwitchPoint.configure do |config|
config.auto_writable = true
raksul_config = {
- readonly: :"#{Rails.env}_readonly",
+ readonly: (:"#{Rails.env}_readonly" unless Rails.env.test?),
writable: :"#{Rails.env}"
- }
+ }.compact
config.define_switch_point :raksul, raksul_config
end
SwitchPoint::writable!(:raksul)
Is there any better solution?
I want to have ability to use single writable connection in test environment even within
with_readonlyblocks.Problem
I prefer to use Rails
use_transactional_testsas it greatly speed ups tests and I don't need to worry about data cleanup.However, it doesn't work with
switch_pointgem as queries run withinwith_readonlyblocks doesn't see test data as it exists only within transactions that won't be commited.See #4 for details.
Environment
switch_point 0.8.0
rails 5.2.3
rspec 3.9.0
rspec-rails-4.0.1
Configuration:
Workaround
Don't declare readonly database in test environment:
SwitchPoint.configure do |config| config.auto_writable = true raksul_config = { - readonly: :"#{Rails.env}_readonly", + readonly: (:"#{Rails.env}_readonly" unless Rails.env.test?), writable: :"#{Rails.env}" - } + }.compact config.define_switch_point :raksul, raksul_config end SwitchPoint::writable!(:raksul)Is there any better solution?