|
108 | 108 | expect(handler_1).not_to have_received(:call) |
109 | 109 | expect(handler_2).not_to have_received(:call) |
110 | 110 | end |
| 111 | + |
| 112 | + it "preserves the locale" do |
| 113 | + I18n.enforce_available_locales = false |
| 114 | + |
| 115 | + ActiveRecord::Base.transaction do |
| 116 | + expect(I18n.locale).not_to eq(:de) |
| 117 | + I18n.with_locale(:de) { example_class.new.after_commit { handler.call(I18n.locale) } } |
| 118 | + expect(handler).not_to have_received(:call) |
| 119 | + end |
| 120 | + expect(handler).to have_received(:call).with(:de) |
| 121 | + |
| 122 | + I18n.enforce_available_locales = true |
| 123 | + end |
111 | 124 | end |
112 | 125 |
|
113 | 126 | context "without transaction" do |
|
291 | 304 | end |
292 | 305 | expect(handler).not_to have_received(:call) |
293 | 306 | end |
| 307 | + |
| 308 | + it "preserves the locale" do |
| 309 | + I18n.enforce_available_locales = false |
| 310 | + |
| 311 | + ActiveRecord::Base.transaction do |
| 312 | + expect(I18n.locale).not_to eq(:de) |
| 313 | + I18n.with_locale(:de) { example_class.new.before_commit { handler.call(I18n.locale) } } |
| 314 | + expect(handler).not_to have_received(:call) |
| 315 | + end |
| 316 | + expect(handler).to have_received(:call).with(:de) |
| 317 | + |
| 318 | + I18n.enforce_available_locales = true |
| 319 | + end |
294 | 320 | end |
295 | 321 |
|
296 | 322 | context "without transaction" do |
|
439 | 465 | end |
440 | 466 | expect(handler).not_to have_received(:call) |
441 | 467 | end |
| 468 | + |
| 469 | + it "preserves the locale" do |
| 470 | + I18n.enforce_available_locales = false |
| 471 | + |
| 472 | + ActiveRecord::Base.transaction do |
| 473 | + expect(I18n.locale).not_to eq(:de) |
| 474 | + I18n.with_locale(:de) { example_class.new.after_rollback { handler.call(I18n.locale) } } |
| 475 | + expect(handler).not_to have_received(:call) |
| 476 | + raise ActiveRecord::Rollback |
| 477 | + end |
| 478 | + expect(handler).to have_received(:call).with(:de) |
| 479 | + |
| 480 | + I18n.enforce_available_locales = true |
| 481 | + end |
442 | 482 | end |
443 | 483 |
|
444 | 484 | context "without transaction" do |
|
0 commit comments