Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove automatic Sweeper install #370

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,24 @@ end

### Current User Tracking

If you're using Audited in a Rails application, all audited changes made within a request will automatically be attributed to the current user. By default, Audited uses the `current_user` method in your controller.
If you're using Audited in a Rails application, add around callback for actions you want to track changes in.
All audited changes made within a request will automatically be attributed to the current user. By default, Audited uses the `current_user` method in your controller.

```ruby
class PostsController < ApplicationController
around_action Audited::Sweeper.new

def create
current_user # => #<User name: "Steve">
@post = Post.create(params[:post])
@post.audits.last.user # => #<User name: "Steve">
end
end

# or enable this callback for all controllers:
class ApplicationController < ActionController::Base
around_action Audited::Sweeper.new
end
```

To use a method other than `current_user`, put the following in an initializer:
Expand Down
9 changes: 0 additions & 9 deletions lib/audited/sweeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,3 @@ def controller=(value)
end
end
end

ActiveSupport.on_load(:action_controller) do
if defined?(ActionController::Base)
ActionController::Base.around_action Audited::Sweeper.new
end
if defined?(ActionController::API)
ActionController::API.around_action Audited::Sweeper.new
end
end
1 change: 1 addition & 0 deletions spec/audited/sweeper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "spec_helper"

class AuditsController < ActionController::Base
around_action Audited::Sweeper.new
before_action :populate_user

attr_reader :company
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'audited'
require 'audited_spec_helpers'
require 'support/active_record/models'
load "audited/sweeper.rb" # force to reload sweeper

SPEC_ROOT = Pathname.new(File.expand_path('../', __FILE__))

Expand Down