Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request store uses Fiber so our test should too #1471

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions spec/paper_trail/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading