Return value of block from PaperTrail.request
.. making it easier to use at the call site.
This commit is contained in:
parent
dda90107df
commit
4520a2741d
|
@ -11,7 +11,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- None
|
- [#1074](https://github.com/airblade/paper_trail/pull/1074)
|
||||||
|
`PaperTrail.request do ... end` now returns the value the given block.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,8 @@ module PaperTrail
|
||||||
# word "request" right there in your application code will remind you that
|
# word "request" right there in your application code will remind you that
|
||||||
# these variables only affect the current request, not all threads.
|
# these variables only affect the current request, not all threads.
|
||||||
#
|
#
|
||||||
# Given a block, temporarily sets the given `options` and execute the block.
|
# Given a block, temporarily sets the given `options`, executes the block,
|
||||||
|
# and returns the value of the block.
|
||||||
#
|
#
|
||||||
# Without a block, this currently just returns `PaperTrail::Request`.
|
# Without a block, this currently just returns `PaperTrail::Request`.
|
||||||
# However, please do not use `PaperTrail::Request` directly. Currently,
|
# However, please do not use `PaperTrail::Request` directly. Currently,
|
||||||
|
@ -135,7 +136,6 @@ module PaperTrail
|
||||||
Request
|
Request
|
||||||
else
|
else
|
||||||
Request.with(options, &block)
|
Request.with(options, &block)
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
RSpec.describe PaperTrail do
|
RSpec.describe PaperTrail do
|
||||||
|
describe ".request" do
|
||||||
|
it "returns the value returned by the block" do
|
||||||
|
expect(described_class.request(whodunnit: "abe lincoln") { "A test" }).to eq("A test")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#config", versioning: true do
|
describe "#config", versioning: true do
|
||||||
it "allows for config values to be set" do
|
it "allows for config values to be set" do
|
||||||
expect(described_class.config.enabled).to eq(true)
|
expect(described_class.config.enabled).to eq(true)
|
||||||
|
|
Loading…
Reference in New Issue