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

Allowing using symbol keys in non_audited_columns #351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'pg', '~> 0.18'
end
end

4 changes: 2 additions & 2 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def revision_at(date_or_time)

# List of attributes that are audited.
def audited_attributes
attributes.except(*non_audited_columns)
attributes.except(*non_audited_columns.map(&:to_s))
end

def non_audited_columns
Expand Down Expand Up @@ -251,7 +251,7 @@ def auditing_enabled=(val)
module AuditedClassMethods
# Returns an array of columns that are audited. See non_audited_columns
def audited_columns
columns.select {|c| !non_audited_columns.include?(c.name) }
columns.reject { |c| non_audited_columns.map(&:to_s).include?(c.name) }
end

def non_audited_columns
Expand Down
4 changes: 3 additions & 1 deletion spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class Secret2 < ::ActiveRecord::Base
end

it "should not save non-audited columns" do
expect(create_user.audits.first.audited_changes.keys.any? { |col| ['created_at', 'updated_at', 'password'].include?( col ) }).to eq(false)
Models::ActiveRecord::User.non_audited_columns = (Models::ActiveRecord::User.non_audited_columns << :favourite_device)

expect(create_user.audits.first.audited_changes.keys.any? { |col| ['favourite_device', 'created_at', 'updated_at', 'password'].include?( col ) }).to eq(false)
end

it "should not save other columns than specified in 'only' option" do
Expand Down
2 changes: 1 addition & 1 deletion spec/audited_spec_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module AuditedSpecHelpers

def create_user(attrs = {})
Models::ActiveRecord::User.create({name: 'Brandon', username: 'brandon', password: 'password'}.merge(attrs))
Models::ActiveRecord::User.create({name: 'Brandon', username: 'brandon', password: 'password', favourite_device: 'Android Phone'}.merge(attrs))
end

def build_user(attrs = {})
Expand Down
1 change: 1 addition & 0 deletions spec/support/active_record/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
t.column :logins, :integer, default: 0
t.column :created_at, :datetime
t.column :updated_at, :datetime
t.column :favourite_device, :string
end

create_table :companies do |t|
Expand Down