Improve the PaperTrail.config method so it both returns and yields the PaperTrail::Config instance when appropriate
Also, alias it to the PaperTrail.configure method
This commit is contained in:
parent
a453811226
commit
3da1f104c1
|
@ -44,6 +44,8 @@ If you depend on the `RSpec` or `Cucumber` helpers, you will need to [manually l
|
|||
the gem is used with `Rails`.
|
||||
- Methods handling serialized attributes should fallback to the currently set Serializer instead of always falling back
|
||||
to `PaperTrail::Serializers::YAML`.
|
||||
- Both `PaperTrail.config` and `PaperTrail.configure` are now identical, and will both return the `PaperTrail::Config`
|
||||
instance and also yield it if a block is provided.
|
||||
|
||||
## 3.0.6
|
||||
|
||||
|
|
|
@ -126,10 +126,12 @@ module PaperTrail
|
|||
# Returns PaperTrail's configuration object.
|
||||
def self.config
|
||||
@@config ||= PaperTrail::Config.instance
|
||||
yield @@config if block_given?
|
||||
@@config
|
||||
end
|
||||
|
||||
def self.configure
|
||||
yield config
|
||||
class << self
|
||||
alias_method :configure, :config
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe PaperTrail, :type => :module, :versioning => true do
|
||||
describe '#config' do
|
||||
it { is_expected.to respond_to(:config) }
|
||||
|
||||
it "should allow for config values to be set" do
|
||||
expect(subject.config.enabled).to eq(true)
|
||||
subject.config.enabled = false
|
||||
expect(subject.config.enabled).to eq(false)
|
||||
end
|
||||
|
||||
it "should accept blocks and yield the config instance" do
|
||||
expect(subject.config.enabled).to eq(true)
|
||||
subject.config { |c| c.enabled = false }
|
||||
expect(subject.config.enabled).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#configure' do
|
||||
it { is_expected.to respond_to(:configure) }
|
||||
|
||||
it "should be an alias for the `config` method" do
|
||||
expect(subject.method(:configure)).to eq(subject.method(:config))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue