lib/audited/sweeper.rb in audited-3.0.0 vs lib/audited/sweeper.rb in audited-4.0.0.rc1

- old
+ new

@@ -1,11 +1,13 @@ +require "rails/observers/activerecord/active_record" +require "rails/observers/action_controller/caching" + module Audited - class Sweeper < ActiveModel::Observer + class Sweeper < ActionController::Caching::Sweeper observe Audited.audit_class attr_accessor :controller - def before(controller) self.controller = controller true end @@ -33,13 +35,30 @@ klass.send(:define_method, callback_meth) do observer.update(:before_create, self) end klass.send(:before_create, callback_meth) end + + def controller + ::Audited.store[:current_controller] + end + + def controller=(value) + ::Audited.store[:current_controller] = value + end end end if defined?(ActionController) and defined?(ActionController::Base) + # Create dynamic subclass of Audited::Sweeper otherwise rspec will + # fail with both ActiveRecord and MongoMapper tests as there will be + # around_filter collision + sweeper_class = Class.new(Audited::Sweeper) do + def self.name + "#{Audited.audit_class}::Sweeper" + end + end + ActionController::Base.class_eval do - around_filter Audited::Sweeper.instance + around_filter sweeper_class.instance end end