diff --git a/spec/paper_trail/request_spec.rb b/spec/paper_trail/request_spec.rb index 5e2dae54..44c42ccf 100644 --- a/spec/paper_trail/request_spec.rb +++ b/spec/paper_trail/request_spec.rb @@ -117,18 +117,34 @@ module PaperTrail expect(described_class.enabled_for_model?(Widget)).to eq true end - it "sets options only for the current thread" do - described_class.whodunnit = "some_whodunnit" - described_class.enabled_for_model(Widget, true) - - described_class.with(whodunnit: "foo", enabled_for_Widget: false) do - expect(described_class.whodunnit).to eq("foo") - expect(described_class.enabled_for_model?(Widget)).to eq false - Thread.new { expect(described_class.whodunnit).to be_nil }.join - Thread.new { expect(described_class.enabled_for_model?(Widget)).to eq true }.join + if RequestStore.scope == Fiber + it "sets options only for the current Fiber" do + described_class.whodunnit = "some_whodunnit" + described_class.enabled_for_model(Widget, true) + + described_class.with(whodunnit: "foo", enabled_for_Widget: false) do + expect(described_class.whodunnit).to eq("foo") + expect(described_class.enabled_for_model?(Widget)).to eq false + Fiber.new(storage: nil) { expect(described_class.whodunnit).to be_nil }.resume + Fiber.new(storage: nil) { expect(described_class.enabled_for_model?(Widget)).to eq true }.resume + end + expect(described_class.whodunnit).to eq "some_whodunnit" + expect(described_class.enabled_for_model?(Widget)).to eq true + end + else + it "sets options only for the current thread" do + described_class.whodunnit = "some_whodunnit" + described_class.enabled_for_model(Widget, true) + + described_class.with(whodunnit: "foo", enabled_for_Widget: false) do + expect(described_class.whodunnit).to eq("foo") + expect(described_class.enabled_for_model?(Widget)).to eq false + Thread.new { expect(described_class.whodunnit).to be_nil }.join + Thread.new { expect(described_class.enabled_for_model?(Widget)).to eq true }.join + end + expect(described_class.whodunnit).to eq "some_whodunnit" + expect(described_class.enabled_for_model?(Widget)).to eq true end - expect(described_class.whodunnit).to eq "some_whodunnit" - expect(described_class.enabled_for_model?(Widget)).to eq true end end