diff --git a/lib/paper_trail/frameworks/rspec.rb b/lib/paper_trail/frameworks/rspec.rb index dc0d0213..a3a17e87 100644 --- a/lib/paper_trail/frameworks/rspec.rb +++ b/lib/paper_trail/frameworks/rspec.rb @@ -1,4 +1,4 @@ -if defined?(RSpec) +if defined? RSpec require File.expand_path('../rspec/extensions', __FILE__) RSpec.configure do |config| @@ -7,6 +7,7 @@ if defined?(RSpec) config.before(:each) do ::PaperTrail.enabled = false ::PaperTrail.whodunnit = nil + ::PaperTrail.controller_info = {} if defined?(::Rails) && defined?(::RSpec::Rails) end 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 match { |actual| actual.kind_of?(::PaperTrail::Model::InstanceMethods) } 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 diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb deleted file mode 100644 index 3dc6473c..00000000 --- a/spec/models/version_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb new file mode 100644 index 00000000..2a91018d --- /dev/null +++ b/spec/models/widget_spec.rb @@ -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 diff --git a/spec/paper_trail_spec.rb b/spec/paper_trail_spec.rb new file mode 100644 index 00000000..ffb5b701 --- /dev/null +++ b/spec/paper_trail_spec.rb @@ -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