audited 4.4.1 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of audited might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 434d39dd10ca63069df2c4e65405957c0e54a9f7
4
- data.tar.gz: d37dfb095ff87cb661b16c9f87d5fb4c3f4485db
3
+ metadata.gz: 4e4cd2ba4231df555461162a9ab0b41db0952828
4
+ data.tar.gz: c3bed2498a2c13bb5f3e7c27367114ca200cc3c8
5
5
  SHA512:
6
- metadata.gz: 8a9265e62d4bed636d199a933237c04b5cfb2c5c66d258e907ee6d916235d89f3e12773422308ea778dc4c0c9fde46bd898b84abbd2b4b9fd329a9df9b4d8695
7
- data.tar.gz: 28175be667b62bac2db50fe0bb5abde722dca710186e34ac92ffa1cba32bf44a428b69a8bf69f6811ab6f68bf211076a081b03dc842cc18803c13d4f688677e8
6
+ metadata.gz: 1249f2af82d7c2633ab5b9d40dfa598c4c4ce6f21d9a817ab1bc82791521a01bf6e95a43b1e1627b65cc1fb5558860acac964acee1ec9f72b85958d13cd2ebf1
7
+ data.tar.gz: 5c33514373b367cd52042e471b79f46adbd72c8ce7f759948d2e087a525833c985cd5a601d37319997f201fcb6a5c4ff6b3bd64ce2a1deca294ba5d80833ef21
@@ -18,6 +18,26 @@ Fixed
18
18
 
19
19
  - None
20
20
 
21
+ ## 4.5.0 (2017-05-22)
22
+
23
+ Breaking changes
24
+
25
+ - None
26
+
27
+ Added
28
+
29
+ - Support for `user_id` column to be a `uuid` type
30
+ [#333](https://github.com/collectiveidea/audited/pull/333)
31
+
32
+ Fixed
33
+
34
+ - Fix retrieval of user from controller when populated in before callbacks
35
+ [#336](https://github.com/collectiveidea/audited/issues/336)
36
+ - Fix column type check in serializer for Oracle DB adapter
37
+ [#335](https://github.com/collectiveidea/audited/pull/335)
38
+ - Fix `non_audited_columns` to allow symbol names
39
+ [#351](https://github.com/collectiveidea/audited/pull/351)
40
+
21
41
  ## 4.4.1 (2017-03-29)
22
42
 
23
43
  Fixed
data/README.md CHANGED
@@ -27,7 +27,7 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
27
27
  Add the gem to your Gemfile:
28
28
 
29
29
  ```ruby
30
- gem "audited", "~> 4.4"
30
+ gem "audited", "~> 4.5"
31
31
  ```
32
32
 
33
33
  Then, from your Rails app directory, create the `audits` table:
@@ -37,7 +37,7 @@ $ rails generate audited:install
37
37
  $ rake db:migrate
38
38
  ```
39
39
 
40
- If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with its JSON column types.
40
+ If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with its JSON column types. If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use `rails generate audited:install --audited-user-id-column-type uuid` to customize the `audits` table `user_id` column type.
41
41
 
42
42
  #### Upgrading
43
43
 
@@ -170,6 +170,8 @@ end
170
170
  post.audits.last.user # => #<User id: 1>
171
171
  ```
172
172
 
173
+ The standard Audited install assumes your User model has an integer primary key type. If this isn't true (e.g. you're using UUID primary keys), you'll need to create a migration to update the `audits` table `user_id` column type. (See Installation above for generator flags if you'd like to regenerate the install migration.)
174
+
173
175
  #### Custom Auditor
174
176
 
175
177
  You might need to use a custom auditor from time to time. It can be done by simply passing in a string:
@@ -16,7 +16,7 @@ module Audited
16
16
  class YAMLIfTextColumnType
17
17
  class << self
18
18
  def load(obj)
19
- if Audited.audit_class.columns_hash["audited_changes"].sql_type == "text"
19
+ if Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
20
20
  ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
21
21
  else
22
22
  obj
@@ -24,7 +24,7 @@ module Audited
24
24
  end
25
25
 
26
26
  def dump(obj)
27
- if Audited.audit_class.columns_hash["audited_changes"].sql_type == "text"
27
+ if Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
28
28
  ActiveRecord::Coders::YAMLColumn.new(Object).dump(obj)
29
29
  else
30
30
  obj
@@ -158,7 +158,7 @@ module Audited
158
158
 
159
159
  def set_audit_user
160
160
  self.user ||= ::Audited.store[:audited_user] # from .as_user
161
- self.user ||= ::Audited.store[:current_user] # from Sweeper
161
+ self.user ||= ::Audited.store[:current_user].try!(:call) # from Sweeper
162
162
  nil # prevent stopping callback chains
163
163
  end
164
164
 
@@ -129,7 +129,7 @@ module Audited
129
129
 
130
130
  # List of attributes that are audited.
131
131
  def audited_attributes
132
- attributes.except(*non_audited_columns)
132
+ attributes.except(*non_audited_columns.map(&:to_s))
133
133
  end
134
134
 
135
135
  def non_audited_columns
@@ -251,7 +251,7 @@ module Audited
251
251
  module AuditedClassMethods
252
252
  # Returns an array of columns that are audited. See non_audited_columns
253
253
  def audited_columns
254
- columns.select {|c| !non_audited_columns.include?(c.name) }
254
+ columns.reject { |c| non_audited_columns.map(&:to_s).include?(c.name) }
255
255
  end
256
256
 
257
257
  def non_audited_columns
@@ -18,7 +18,7 @@ module Audited
18
18
  end
19
19
 
20
20
  def current_user
21
- controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true)
21
+ lambda { controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true) }
22
22
  end
23
23
 
24
24
  def remote_ip
@@ -1,3 +1,3 @@
1
1
  module Audited
2
- VERSION = "4.4.1"
2
+ VERSION = "4.5.0"
3
3
  end
@@ -13,6 +13,7 @@ module Audited
13
13
  extend Audited::Generators::Migration
14
14
 
15
15
  class_option :audited_changes_column_type, type: :string, default: "text", required: false
16
+ class_option :audited_user_id_column_type, type: :string, default: "integer", required: false
16
17
 
17
18
  source_root File.expand_path("../templates", __FILE__)
18
19
 
@@ -5,7 +5,7 @@ class <%= migration_class_name %> < <%= migration_parent %>
5
5
  t.column :auditable_type, :string
6
6
  t.column :associated_id, :integer
7
7
  t.column :associated_type, :string
8
- t.column :user_id, :integer
8
+ t.column :user_id, :<%= options[:audited_user_id_column_type] %>
9
9
  t.column :user_type, :string
10
10
  t.column :username, :string
11
11
  t.column :action, :string
@@ -36,7 +36,9 @@ describe Audited::Auditor do
36
36
  end
37
37
 
38
38
  it "should not save non-audited columns" do
39
- expect(create_user.audits.first.audited_changes.keys.any? { |col| ['created_at', 'updated_at', 'password'].include?( col ) }).to eq(false)
39
+ Models::ActiveRecord::User.non_audited_columns = (Models::ActiveRecord::User.non_audited_columns << :favourite_device)
40
+
41
+ expect(create_user.audits.first.audited_changes.keys.any? { |col| ['favourite_device', 'created_at', 'updated_at', 'password'].include?( col ) }).to eq(false)
40
42
  end
41
43
 
42
44
  it "should not save other columns than specified in 'only' option" do
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  class AuditsController < ActionController::Base
4
+ before_action :populate_user
5
+
4
6
  attr_reader :company
5
7
 
6
8
  def create
@@ -17,6 +19,8 @@ class AuditsController < ActionController::Base
17
19
 
18
20
  attr_accessor :current_user
19
21
  attr_accessor :custom_user
22
+
23
+ def populate_user; end
20
24
  end
21
25
 
22
26
  describe AuditsController do
@@ -69,6 +73,18 @@ describe AuditsController do
69
73
  expect(controller.company.audits.last.request_uuid).to eq("abc123")
70
74
  end
71
75
 
76
+ it "should call current_user after controller callbacks" do
77
+ expect(controller).to receive(:populate_user) do
78
+ controller.send(:current_user=, user)
79
+ end
80
+
81
+ expect {
82
+ post :create
83
+ }.to change( Audited::Audit, :count )
84
+
85
+ expect(controller.company.audits.last.user).to eq(user)
86
+ end
87
+
72
88
  end
73
89
 
74
90
  describe "PUT update" do
@@ -1,7 +1,7 @@
1
1
  module AuditedSpecHelpers
2
2
 
3
3
  def create_user(attrs = {})
4
- Models::ActiveRecord::User.create({name: 'Brandon', username: 'brandon', password: 'password'}.merge(attrs))
4
+ Models::ActiveRecord::User.create({name: 'Brandon', username: 'brandon', password: 'password', favourite_device: 'Android Phone'}.merge(attrs))
5
5
  end
6
6
 
7
7
  def build_user(attrs = {})
@@ -39,6 +39,7 @@ ActiveRecord::Schema.define do
39
39
  t.column :logins, :integer, default: 0
40
40
  t.column :created_at, :datetime
41
41
  t.column :updated_at, :datetime
42
+ t.column :favourite_device, :string
42
43
  end
43
44
 
44
45
  create_table :companies do |t|
@@ -34,6 +34,24 @@ class InstallGeneratorTest < Rails::Generators::TestCase
34
34
  end
35
35
  end
36
36
 
37
+ test "generate migration with 'string' type for user_id column" do
38
+ run_generator %w(--audited-user-id-column-type string)
39
+
40
+ assert_migration "db/migrate/install_audited.rb" do |content|
41
+ assert_includes(content, 'class InstallAudited')
42
+ assert_includes(content, 't.column :user_id, :string')
43
+ end
44
+ end
45
+
46
+ test "generate migration with 'uuid' type for user_id column" do
47
+ run_generator %w(--audited-user-id-column-type uuid)
48
+
49
+ assert_migration "db/migrate/install_audited.rb" do |content|
50
+ assert_includes(content, 'class InstallAudited')
51
+ assert_includes(content, 't.column :user_id, :uuid')
52
+ end
53
+ end
54
+
37
55
  test "generate migration with correct AR migration parent" do
38
56
  run_generator
39
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audited
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-03-29 00:00:00.000000000 Z
16
+ date: 2017-05-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord