mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
close #312; Fix RSpec 'with_versioning' class helper method
This commit is contained in:
parent
ed2e3d55e4
commit
52823d2fb2
5 changed files with 45 additions and 23 deletions
|
@ -11,6 +11,7 @@
|
|||
instead of `current_user` (if `current_user` is defined).
|
||||
- [#313](https://github.com/airblade/paper_trail/pull/313) - Make the `Rails::Controller` helper compatible with
|
||||
`ActionController::API` for compatibility with the [`rails-api`](https://github.com/rails-api/rails-api) gem.
|
||||
- [#312](https://github.com/airblade/paper_trail/issues/312) - Fix RSpec `with_versioning` class level helper method.
|
||||
- Deprecated `Model.paper_trail_on` and `Model.paper_trail_off` in favor of bang versions of the methods. Deprecation warning
|
||||
informs users that the non-bang versions of the methods will be removed in version `3.1.0`.
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require 'rspec/core'
|
||||
require 'rspec/matchers'
|
||||
require File.expand_path('../rspec/extensions', __FILE__)
|
||||
require 'paper_trail/frameworks/rspec/helpers'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include ::PaperTrail::RSpec::Extensions
|
||||
config.include ::PaperTrail::RSpec::Helpers::InstanceMethods
|
||||
config.extend ::PaperTrail::RSpec::Helpers::ClassMethods
|
||||
|
||||
config.before(:each) do
|
||||
::PaperTrail.enabled = false
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
module PaperTrail
|
||||
module RSpec
|
||||
module Extensions
|
||||
# :call-seq:
|
||||
# with_versioning
|
||||
#
|
||||
# enable versioning for specific blocks
|
||||
|
||||
def with_versioning
|
||||
was_enabled = ::PaperTrail.enabled?
|
||||
::PaperTrail.enabled = true
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
::PaperTrail.enabled = was_enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/paper_trail/frameworks/rspec/helpers.rb
Normal file
27
lib/paper_trail/frameworks/rspec/helpers.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module PaperTrail
|
||||
module RSpec
|
||||
module Helpers
|
||||
module InstanceMethods
|
||||
# enable versioning for specific blocks (at instance-level)
|
||||
def with_versioning
|
||||
was_enabled = ::PaperTrail.enabled?
|
||||
::PaperTrail.enabled = true
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
::PaperTrail.enabled = was_enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# enable versioning for specific blocks (at class-level)
|
||||
def with_versioning(&block)
|
||||
context 'with versioning', :versioning => true do
|
||||
class_exec(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ describe "PaperTrail RSpec Helper" do
|
|||
it 'should have versioning off by default' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
end
|
||||
it 'should turn versioning on in a with_versioning block' do
|
||||
it 'should turn versioning on in a `with_versioning` block' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
with_versioning do
|
||||
::PaperTrail.should be_enabled
|
||||
|
@ -27,6 +27,19 @@ describe "PaperTrail RSpec Helper" do
|
|||
end
|
||||
end
|
||||
|
||||
context '`with_versioning` block at class level' do
|
||||
it { ::PaperTrail.should_not be_enabled }
|
||||
|
||||
with_versioning do
|
||||
it 'should have versioning on by default' do
|
||||
::PaperTrail.should be_enabled
|
||||
end
|
||||
end
|
||||
it 'should not leak the `enabled?` state into successive tests' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
end
|
||||
end
|
||||
|
||||
describe :whodunnit do
|
||||
before(:all) { ::PaperTrail.whodunnit = 'foobar' }
|
||||
|
||||
|
|
Loading…
Reference in a new issue