audited 3.0.0.rc1 → 3.0.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -174,14 +174,22 @@ company.associated_audits.last.auditable # => #<User name: "Steve Richert">
174
174
 
175
175
  ## Gotchas
176
176
 
177
- ### ActiveRecord Accessible Attributes
177
+ ### Accessible Attributes
178
178
 
179
- If your model calls `attr_accessible` after `audited`, you'll need to set the `:protect => false` option. By default, Audited uses `attr_protected` to prevent malicious users from dissociating your audits, but Rails doesn't allow both `attr_protected` and `attr_accessible`.
179
+ Audited assumes you are using `attr_accessible`, however, if you are using `attr_protected` or just going at it unprotected you will have to set the `:allow_mass_assignment => true` option.
180
+
181
+ If using `attr_protected` be sure to add `audit_ids` to the list of protected attributes to prevent data loss.
182
+
183
+ ```ruby
184
+ class User < ActiveRecord::Base
185
+ audited :allow_mass_assignment => true
186
+ end
187
+ ```
180
188
 
181
189
  ```ruby
182
190
  class User < ActiveRecord::Base
183
- audited :protect => false
184
- attr_accessible :name
191
+ audited :allow_mass_assignment => true
192
+ attr_protected :logins, :audit_ids
185
193
  end
186
194
  ```
187
195
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'audited-activerecord'
5
- gem.version = '3.0.0.rc1'
5
+ gem.version = '3.0.0.rc2'
6
6
 
7
7
  gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
8
8
  gem.email = 'info@collectiveidea.com'
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'audited-mongo_mapper'
5
- gem.version = '3.0.0.rc1'
5
+ gem.version = '3.0.0.rc2'
6
6
 
7
7
  gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
8
8
  gem.email = 'info@collectiveidea.com'
data/audited.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'audited'
5
- gem.version = '3.0.0.rc1'
5
+ gem.version = '3.0.0.rc2'
6
6
 
7
7
  gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
8
8
  gem.email = 'info@collectiveidea.com'
@@ -47,8 +47,6 @@ module Audited
47
47
  # don't allow multiple calls
48
48
  return if self.included_modules.include?(Audited::Auditor::AuditedInstanceMethods)
49
49
 
50
- options = { :protect => accessible_attributes.blank? }.merge(options)
51
-
52
50
  class_attribute :non_audited_columns, :instance_writer => false
53
51
  class_attribute :auditing_enabled, :instance_writer => false
54
52
  class_attribute :audit_associated_with, :instance_writer => false
@@ -68,12 +66,11 @@ module Audited
68
66
  end
69
67
 
70
68
  attr_accessor :audit_comment
71
- unless accessible_attributes.blank? || options[:protect]
69
+ unless options[:allow_mass_assignment]
72
70
  attr_accessible :audit_comment
73
71
  end
74
72
 
75
73
  has_many :audits, :as => :auditable, :class_name => Audited.audit_class.name
76
- attr_protected :audit_ids if options[:protect]
77
74
  Audited.audit_class.audited_class_names << self.to_s
78
75
 
79
76
  after_create :audit_create if !options[:on] || (options[:on] && options[:on].include?(:create))
@@ -157,6 +154,7 @@ module Audited
157
154
  revision.send :instance_variable_set, '@persisted', !self.destroyed?
158
155
  revision.send :instance_variable_set, '@readonly', false
159
156
  revision.send :instance_variable_set, '@destroyed', false
157
+ revision.send :instance_variable_set, '@_destroyed', false
160
158
  revision.send :instance_variable_set, '@marked_for_destruction', false
161
159
  Audited.audit_class.assign_revision_attributes(revision, attributes)
162
160
 
@@ -4,7 +4,7 @@ require File.expand_path('../schema', __FILE__)
4
4
  module Models
5
5
  module ActiveRecord
6
6
  class User < ::ActiveRecord::Base
7
- audited :except => :password
7
+ audited :allow_mass_assignment => true, :except => :password
8
8
 
9
9
  attr_protected :logins
10
10
 
@@ -18,13 +18,13 @@ module Models
18
18
  audited :comment_required => true
19
19
  end
20
20
 
21
- class UnprotectedUser < ::ActiveRecord::Base
21
+ class AccessibleAfterDeclarationUser < ::ActiveRecord::Base
22
22
  self.table_name = :users
23
- audited :protect => false
23
+ audited
24
24
  attr_accessible :name, :username, :password
25
25
  end
26
26
 
27
- class AccessibleUser < ::ActiveRecord::Base
27
+ class AccessibleBeforeDeclarationUser < ::ActiveRecord::Base
28
28
  self.table_name = :users
29
29
  attr_accessible :name, :username, :password # declare attr_accessible before calling aaa
30
30
  audited
@@ -32,7 +32,7 @@ module Models
32
32
 
33
33
  class NoAttributeProtectionUser < ::ActiveRecord::Base
34
34
  self.table_name = :users
35
- audited
35
+ audited :allow_mass_assignment => true
36
36
  end
37
37
 
38
38
  class UserWithAfterAudit < ::ActiveRecord::Base
@@ -15,7 +15,7 @@ module Models
15
15
  key :logins, Integer, :default => 0
16
16
  timestamps!
17
17
 
18
- audited :except => :password
18
+ audited :allow_mass_assignment => true, :except => :password
19
19
 
20
20
  attr_protected :logins
21
21
 
@@ -38,7 +38,7 @@ module Models
38
38
  audited :comment_required => true
39
39
  end
40
40
 
41
- class UnprotectedUser
41
+ class AccessibleAfterDeclarationUser
42
42
  include ::MongoMapper::Document
43
43
 
44
44
  key :name, String
@@ -49,11 +49,11 @@ module Models
49
49
  key :logins, Integer, :default => 0
50
50
  timestamps!
51
51
 
52
- audited :protect => false
52
+ audited
53
53
  attr_accessible :name, :username, :password
54
54
  end
55
55
 
56
- class AccessibleUser
56
+ class AccessibleBeforeDeclarationUser
57
57
  include ::MongoMapper::Document
58
58
 
59
59
  key :name, String
@@ -79,7 +79,7 @@ module Models
79
79
  key :logins, Integer, :default => 0
80
80
  timestamps!
81
81
 
82
- audited
82
+ audited :allow_mass_assignment => true
83
83
  end
84
84
 
85
85
  class UserWithAfterAudit
@@ -170,5 +170,41 @@ module Models
170
170
 
171
171
  audited :on => [:create, :update]
172
172
  end
173
+
174
+ class RichObjectUser
175
+ include ::MongoMapper::Document
176
+
177
+ class Name
178
+ attr_accessor :first_name, :last_name
179
+
180
+ def self.from_mongo(value)
181
+ case value
182
+ when String then new(*value.split)
183
+ when self then value
184
+ end
185
+ end
186
+
187
+ def self.to_mongo(value)
188
+ case value
189
+ when String then value
190
+ when self then value.to_s
191
+ end
192
+ end
193
+
194
+ def initialize(first_name, last_name)
195
+ self.first_name, self.last_name = first_name, last_name
196
+ end
197
+
198
+ def to_s
199
+ [first_name, last_name].compact.join(' ')
200
+ end
201
+ end
202
+
203
+ key :name, Name
204
+
205
+ attr_accessible :name
206
+
207
+ audited
208
+ end
173
209
  end
174
210
  end
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: 3.0.0.rc1
4
+ version: 3.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-04-25 00:00:00.000000000 Z
17
+ date: 2012-07-09 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -189,6 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
189
  - - ! '>='
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
+ segments:
193
+ - 0
194
+ hash: 1912523767266881932
192
195
  required_rubygems_version: !ruby/object:Gem::Requirement
193
196
  none: false
194
197
  requirements:
@@ -197,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
200
  version: 1.3.1
198
201
  requirements: []
199
202
  rubyforge_project:
200
- rubygems_version: 1.8.21
203
+ rubygems_version: 1.8.24
201
204
  signing_key:
202
205
  specification_version: 3
203
206
  summary: Log all changes to your models