Giter Club home page Giter Club logo

Comments (8)

desoleary avatar desoleary commented on June 11, 2024 2
Audited::Audit.audited_classes.each do |audited_class|
      audited_class.auditing_enabled = false # or `true` to enable
    end

works for me now

from audited.

enriquez avatar enriquez commented on June 11, 2024

One approached I've experimented with:

Audit.audited_classes.each do |audited_class|
  audited_class.disable_auditing
end

Audit.audited_classes.each do |audited_class|
  audited_class.enable_auditing
end

The problem then becomes WHEN to do this. If cache_classes is false, then doing this in the environment.rb or development.rb won't work because the classes aren't loaded yet for Audit.audited_classes to give us an accurate list.

from audited.

Frost avatar Frost commented on June 11, 2024

Here is another solution to this:

module CollectiveIdea::Acts::Audited::InstanceMethods
  private
    def write_audit(attrs)
      self.audits.create attrs if auditing_enabled && Audit.auditing_enabled?
    end
end

class Audit
  @@auditing_enabled = true
  def self.auditing_enabled?
    @@auditing_enabled
  end

  def self.disable_auditing
    @@auditing_enabled = false
  end

  def self.enable_auditing
    @@auditing_enabled = true
  end
end

This way you will be able to do Audit.disable_auditing, and it will globally disable creation of any Audit objects until you do Audit.enable_auditing again

I'll take no responsibility for what comes out of this though, and it was a five minute fix. It seems to work for me. Good luck.

from audited.

aaronrenner avatar aaronrenner commented on June 11, 2024

This would be a nice feature and would really help speed up testing.

from audited.

dougc84 avatar dougc84 commented on June 11, 2024

@Frost I took your idea and modified it slightly for my use case. I like what you came up with, but it needed some modification for version 3.0.

Gist is here: https://gist.github.com/4392334

from audited.

ares avatar ares commented on June 11, 2024

It seems the label 2.0.x is no longer valid https://github.com/collectiveidea/audited/blob/master/lib/audited/auditor.rb#L82 :-) Is there any chance for this feature to get in so can avoid hacking Audited gem internals in rake tasks where we don't won't it to audit changes?

from audited.

laserlemon avatar laserlemon commented on June 11, 2024

Thank you @desoleary. Looks like that solves/closes this issue! 👏

from audited.

lacco avatar lacco commented on June 11, 2024

Looks like that this issue has been finally solved in #426 . Great!

from audited.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.