mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Simplifying the RSpec helper code, adding better spec coverage for it
This commit is contained in:
parent
272203db2b
commit
642c296aa3
4 changed files with 62 additions and 58 deletions
|
@ -1,4 +1,4 @@
|
||||||
if defined?(RSpec)
|
if defined? RSpec
|
||||||
require File.expand_path('../rspec/extensions', __FILE__)
|
require File.expand_path('../rspec/extensions', __FILE__)
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
@ -7,6 +7,7 @@ if defined?(RSpec)
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
::PaperTrail.enabled = false
|
::PaperTrail.enabled = false
|
||||||
::PaperTrail.whodunnit = nil
|
::PaperTrail.whodunnit = nil
|
||||||
|
::PaperTrail.controller_info = {} if defined?(::Rails) && defined?(::RSpec::Rails)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, versioning: true) do
|
config.before(:each, versioning: true) do
|
||||||
|
@ -18,20 +19,4 @@ if defined?(RSpec)
|
||||||
# check to see if the model has `has_paper_trail` declared on it
|
# check to see if the model has `has_paper_trail` declared on it
|
||||||
match { |actual| actual.kind_of?(::PaperTrail::Model::InstanceMethods) }
|
match { |actual| actual.kind_of?(::PaperTrail::Model::InstanceMethods) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# The `Rails` helper also sets the `controller_info` config variable in a `before_filter`...
|
|
||||||
if defined?(::Rails) && defined?(RSpec::Rails)
|
|
||||||
module RSpec
|
|
||||||
module Rails
|
|
||||||
class Railtie < ::Rails::Railtie
|
|
||||||
initializer 'paper_trail.rspec_extensions' do
|
|
||||||
RSpec.configure do |config|
|
|
||||||
config.before(:each) { ::PaperTrail.controller_info = {} }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe PaperTrail::Version do
|
|
||||||
context 'default' do
|
|
||||||
it 'should have versioning off by default' do
|
|
||||||
::PaperTrail.enabled?.should_not be_true
|
|
||||||
end
|
|
||||||
it 'should turn versioning on in a with_versioning block' do
|
|
||||||
::PaperTrail.enabled?.should be_false
|
|
||||||
with_versioning do
|
|
||||||
::PaperTrail.enabled?.should be_true
|
|
||||||
end
|
|
||||||
::PaperTrail.enabled?.should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'versioning: true', versioning: true do
|
|
||||||
it 'should have versioning on by default' do
|
|
||||||
::PaperTrail.enabled?.should be_true
|
|
||||||
end
|
|
||||||
it 'should keep versioning on after a with_versioning block' do
|
|
||||||
::PaperTrail.enabled?.should be_true
|
|
||||||
with_versioning do
|
|
||||||
::PaperTrail.enabled?.should be_true
|
|
||||||
end
|
|
||||||
::PaperTrail.enabled?.should be_true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe Widget do
|
|
||||||
it { should be_versioned }
|
|
||||||
|
|
||||||
context 'be_versioned matcher', versioning: true do
|
|
||||||
it 'should respond to be_versioned' do
|
|
||||||
widget = Widget.create name: 'Bob', an_integer: 1
|
|
||||||
widget.should be_versioned
|
|
||||||
widget.versions.size.should == 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
13
spec/models/widget_spec.rb
Normal file
13
spec/models/widget_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Widget do
|
||||||
|
it { should be_versioned }
|
||||||
|
|
||||||
|
context 'be_versioned matcher', versioning: true do
|
||||||
|
it 'should respond to be_versioned' do
|
||||||
|
widget = Widget.create name: 'Bob', an_integer: 1
|
||||||
|
widget.should be_versioned
|
||||||
|
widget.versions.size.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
47
spec/paper_trail_spec.rb
Normal file
47
spec/paper_trail_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "PaperTrail RSpec Helper" do
|
||||||
|
describe :enabled do
|
||||||
|
context 'default' 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
|
||||||
|
::PaperTrail.should_not be_enabled
|
||||||
|
with_versioning do
|
||||||
|
::PaperTrail.should be_enabled
|
||||||
|
end
|
||||||
|
::PaperTrail.should_not be_enabled
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'versioning: true', versioning: true do
|
||||||
|
it 'should have versioning on by default' do
|
||||||
|
::PaperTrail.should be_enabled
|
||||||
|
end
|
||||||
|
it 'should keep versioning on after a with_versioning block' do
|
||||||
|
::PaperTrail.should be_enabled
|
||||||
|
with_versioning do
|
||||||
|
::PaperTrail.should be_enabled
|
||||||
|
end
|
||||||
|
::PaperTrail.should be_enabled
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe :whodunnit do
|
||||||
|
before(:all) { ::PaperTrail.whodunnit = 'foobar' }
|
||||||
|
|
||||||
|
it "should get set to `nil` by default" do
|
||||||
|
::PaperTrail.whodunnit.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe :controller_info do
|
||||||
|
before(:all) { ::PaperTrail.controller_info = {:foo => 'bar'} }
|
||||||
|
|
||||||
|
it "should get set to an empty hash before each test" do
|
||||||
|
::PaperTrail.controller_info.should == {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue