michelson / espinita

Audit activerecord models like a boss (and works with rails 4!)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

auditable :only breaks when table doesn't exist

jkz opened this issue · comments

I have an auditable User model and I want to hide passwords and tokens.

class User < ActiveRecord::Base
    auditable only: [:name, :email, :role]
end

Now when I ran rake db:schema:load to set up a new environment, I got the following error.

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist

I drilled down the stack trace to this line:
https://github.com/continuum/espinita/blob/master/lib/espinita/auditor_behavior.rb#L29

Where I found the culprit self.column_names.

I fixed my case by adding a check:

class User < ActiveRecord::Base
    auditable only: [:name, :email, :role] if table_exists?
end

Would it be an idea to fail gracefully in the library?