audited 4.2.0 → 4.4.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +21 -9
- data/Appraisals +11 -3
- data/CHANGELOG.md +190 -0
- data/Gemfile +1 -1
- data/README.md +76 -45
- data/Rakefile +3 -18
- data/gemfiles/rails40.gemfile +1 -1
- data/gemfiles/rails41.gemfile +1 -1
- data/gemfiles/rails42.gemfile +1 -1
- data/gemfiles/rails50.gemfile +7 -0
- data/gemfiles/rails51.gemfile +7 -0
- data/lib/audited/audit.rb +126 -56
- data/lib/audited/auditor.rb +87 -40
- data/lib/audited/rspec_matchers.rb +5 -1
- data/lib/audited/sweeper.rb +24 -44
- data/lib/audited/version.rb +1 -1
- data/lib/audited-rspec.rb +4 -0
- data/lib/audited.rb +16 -2
- data/lib/generators/audited/install_generator.rb +24 -0
- data/lib/generators/audited/migration.rb +15 -0
- data/lib/generators/audited/migration_helper.rb +9 -0
- data/lib/generators/audited/templates/add_association_to_audits.rb +11 -0
- data/lib/generators/audited/templates/add_comment_to_audits.rb +9 -0
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +10 -0
- data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +10 -0
- data/lib/generators/audited/templates/install.rb +30 -0
- data/lib/generators/audited/templates/rename_association_to_associated.rb +23 -0
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +9 -0
- data/lib/generators/audited/templates/rename_parent_to_association.rb +11 -0
- data/lib/generators/audited/upgrade_generator.rb +59 -0
- data/spec/audited/audit_spec.rb +246 -0
- data/spec/audited/auditor_spec.rb +648 -0
- data/spec/audited/sweeper_spec.rb +108 -0
- data/spec/audited_spec_helpers.rb +6 -22
- data/spec/rails_app/config/environments/test.rb +7 -4
- data/spec/rails_app/config/initializers/secret_token.rb +1 -1
- data/spec/rails_app/config/routes.rb +1 -4
- data/spec/spec_helper.rb +7 -9
- data/spec/support/active_record/models.rb +24 -13
- data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +12 -0
- data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +12 -0
- data/spec/support/active_record/schema.rb +37 -12
- data/test/db/version_1.rb +4 -4
- data/test/db/version_2.rb +4 -4
- data/test/db/version_3.rb +4 -4
- data/test/db/version_4.rb +4 -4
- data/test/db/version_5.rb +2 -2
- data/test/db/version_6.rb +2 -2
- data/test/install_generator_test.rb +31 -3
- data/test/upgrade_generator_test.rb +25 -10
- metadata +54 -84
- data/CHANGELOG +0 -34
- data/lib/audited/active_record/version.rb +0 -5
- data/lib/audited/mongo_mapper/version.rb +0 -5
- data/spec/support/mongo_mapper/connection.rb +0 -4
- data/spec/support/mongo_mapper/models.rb +0 -214
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
require 'audited/adapters/active_record'
|
|
4
3
|
require 'generators/audited/upgrade_generator'
|
|
5
4
|
|
|
6
5
|
class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
7
6
|
destination File.expand_path('../../tmp', __FILE__)
|
|
8
7
|
setup :prepare_destination
|
|
9
8
|
tests Audited::Generators::UpgradeGenerator
|
|
9
|
+
if Rails::VERSION::MAJOR == 4
|
|
10
|
+
self.use_transactional_fixtures = false
|
|
11
|
+
else
|
|
12
|
+
self.use_transactional_tests = false
|
|
13
|
+
end
|
|
10
14
|
|
|
11
15
|
test "should add 'comment' to audits table" do
|
|
12
16
|
load_schema 1
|
|
@@ -14,7 +18,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
14
18
|
run_generator %w(upgrade)
|
|
15
19
|
|
|
16
20
|
assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
|
|
17
|
-
assert_match
|
|
21
|
+
assert_match(/add_column :audits, :comment, :string/, content)
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
assert_migration "db/migrate/rename_changes_to_audited_changes.rb"
|
|
@@ -28,7 +32,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
28
32
|
assert_no_migration "db/migrate/add_comment_to_audits.rb"
|
|
29
33
|
|
|
30
34
|
assert_migration "db/migrate/rename_changes_to_audited_changes.rb" do |content|
|
|
31
|
-
assert_match
|
|
35
|
+
assert_match(/rename_column :audits, :changes, :audited_changes/, content)
|
|
32
36
|
end
|
|
33
37
|
end
|
|
34
38
|
|
|
@@ -38,7 +42,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
38
42
|
run_generator %w(upgrade)
|
|
39
43
|
|
|
40
44
|
assert_migration "db/migrate/add_remote_address_to_audits.rb" do |content|
|
|
41
|
-
assert_match
|
|
45
|
+
assert_match(/add_column :audits, :remote_address, :string/, content)
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
48
|
|
|
@@ -48,8 +52,8 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
48
52
|
run_generator %w(upgrade)
|
|
49
53
|
|
|
50
54
|
assert_migration "db/migrate/add_association_to_audits.rb" do |content|
|
|
51
|
-
assert_match
|
|
52
|
-
assert_match
|
|
55
|
+
assert_match(/add_column :audits, :association_id, :integer/, content)
|
|
56
|
+
assert_match(/add_column :audits, :association_type, :string/, content)
|
|
53
57
|
end
|
|
54
58
|
end
|
|
55
59
|
|
|
@@ -59,8 +63,8 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
59
63
|
run_generator %w(upgrade)
|
|
60
64
|
|
|
61
65
|
assert_migration "db/migrate/rename_association_to_associated.rb" do |content|
|
|
62
|
-
assert_match
|
|
63
|
-
assert_match
|
|
66
|
+
assert_match(/rename_column :audits, :association_id, :associated_id/, content)
|
|
67
|
+
assert_match(/rename_column :audits, :association_type, :associated_type/, content)
|
|
64
68
|
end
|
|
65
69
|
end
|
|
66
70
|
|
|
@@ -70,8 +74,19 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
|
70
74
|
run_generator %w(upgrade)
|
|
71
75
|
|
|
72
76
|
assert_migration "db/migrate/add_request_uuid_to_audits.rb" do |content|
|
|
73
|
-
assert_match
|
|
74
|
-
assert_match
|
|
77
|
+
assert_match(/add_column :audits, :request_uuid, :string/, content)
|
|
78
|
+
assert_match(/add_index :audits, :request_uuid/, content)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test "generate migration with correct AR migration parent" do
|
|
83
|
+
load_schema 1
|
|
84
|
+
|
|
85
|
+
run_generator %w(upgrade)
|
|
86
|
+
|
|
87
|
+
assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
|
|
88
|
+
parent = Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
|
|
89
|
+
assert_includes(content, "class AddCommentToAudits < #{parent}\n")
|
|
75
90
|
end
|
|
76
91
|
end
|
|
77
92
|
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: 4.
|
|
4
|
+
version: 4.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brandon Keepers
|
|
@@ -13,24 +13,30 @@ authors:
|
|
|
13
13
|
autorequire:
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
|
-
date:
|
|
16
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
|
17
17
|
dependencies:
|
|
18
18
|
- !ruby/object:Gem::Dependency
|
|
19
|
-
name:
|
|
19
|
+
name: activerecord
|
|
20
20
|
requirement: !ruby/object:Gem::Requirement
|
|
21
21
|
requirements:
|
|
22
|
-
- - "
|
|
22
|
+
- - ">="
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: 0
|
|
24
|
+
version: '4.0'
|
|
25
|
+
- - "<"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '5.1'
|
|
25
28
|
type: :runtime
|
|
26
29
|
prerelease: false
|
|
27
30
|
version_requirements: !ruby/object:Gem::Requirement
|
|
28
31
|
requirements:
|
|
29
|
-
- - "
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '4.0'
|
|
35
|
+
- - "<"
|
|
30
36
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
37
|
+
version: '5.1'
|
|
32
38
|
- !ruby/object:Gem::Dependency
|
|
33
|
-
name:
|
|
39
|
+
name: appraisal
|
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
|
35
41
|
requirements:
|
|
36
42
|
- - ">="
|
|
@@ -44,117 +50,81 @@ dependencies:
|
|
|
44
50
|
- !ruby/object:Gem::Version
|
|
45
51
|
version: '0'
|
|
46
52
|
- !ruby/object:Gem::Dependency
|
|
47
|
-
name:
|
|
53
|
+
name: rails
|
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
|
49
55
|
requirements:
|
|
50
|
-
- - "
|
|
51
|
-
- !ruby/object:Gem::Version
|
|
52
|
-
version: 1.0.0
|
|
53
|
-
type: :development
|
|
54
|
-
prerelease: false
|
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
-
requirements:
|
|
57
|
-
- - "~>"
|
|
56
|
+
- - ">="
|
|
58
57
|
- !ruby/object:Gem::Version
|
|
59
|
-
version:
|
|
60
|
-
-
|
|
61
|
-
name: mongo_mapper
|
|
62
|
-
requirement: !ruby/object:Gem::Requirement
|
|
63
|
-
requirements:
|
|
64
|
-
- - "~>"
|
|
58
|
+
version: '4.0'
|
|
59
|
+
- - "<"
|
|
65
60
|
- !ruby/object:Gem::Version
|
|
66
|
-
version:
|
|
61
|
+
version: '5.1'
|
|
67
62
|
type: :development
|
|
68
63
|
prerelease: false
|
|
69
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
70
65
|
requirements:
|
|
71
|
-
- - "
|
|
66
|
+
- - ">="
|
|
72
67
|
- !ruby/object:Gem::Version
|
|
73
|
-
version:
|
|
74
|
-
-
|
|
75
|
-
name: rails
|
|
76
|
-
requirement: !ruby/object:Gem::Requirement
|
|
77
|
-
requirements:
|
|
78
|
-
- - "~>"
|
|
68
|
+
version: '4.0'
|
|
69
|
+
- - "<"
|
|
79
70
|
- !ruby/object:Gem::Version
|
|
80
|
-
version:
|
|
81
|
-
type: :development
|
|
82
|
-
prerelease: false
|
|
83
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
84
|
-
requirements:
|
|
85
|
-
- - "~>"
|
|
86
|
-
- !ruby/object:Gem::Version
|
|
87
|
-
version: 4.2.0
|
|
71
|
+
version: '5.1'
|
|
88
72
|
- !ruby/object:Gem::Dependency
|
|
89
73
|
name: rspec-rails
|
|
90
74
|
requirement: !ruby/object:Gem::Requirement
|
|
91
75
|
requirements:
|
|
92
76
|
- - "~>"
|
|
93
77
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '3.
|
|
78
|
+
version: '3.5'
|
|
95
79
|
type: :development
|
|
96
80
|
prerelease: false
|
|
97
81
|
version_requirements: !ruby/object:Gem::Requirement
|
|
98
82
|
requirements:
|
|
99
83
|
- - "~>"
|
|
100
84
|
- !ruby/object:Gem::Version
|
|
101
|
-
version: '3.
|
|
85
|
+
version: '3.5'
|
|
102
86
|
- !ruby/object:Gem::Dependency
|
|
103
87
|
name: sqlite3
|
|
104
88
|
requirement: !ruby/object:Gem::Requirement
|
|
105
89
|
requirements:
|
|
106
90
|
- - "~>"
|
|
107
91
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '1.
|
|
92
|
+
version: '1.3'
|
|
109
93
|
type: :development
|
|
110
94
|
prerelease: false
|
|
111
95
|
version_requirements: !ruby/object:Gem::Requirement
|
|
112
96
|
requirements:
|
|
113
97
|
- - "~>"
|
|
114
98
|
- !ruby/object:Gem::Version
|
|
115
|
-
version: '1.
|
|
99
|
+
version: '1.3'
|
|
116
100
|
- !ruby/object:Gem::Dependency
|
|
117
101
|
name: mysql2
|
|
118
102
|
requirement: !ruby/object:Gem::Requirement
|
|
119
103
|
requirements:
|
|
120
104
|
- - "~>"
|
|
121
105
|
- !ruby/object:Gem::Version
|
|
122
|
-
version:
|
|
106
|
+
version: 0.3.20
|
|
123
107
|
type: :development
|
|
124
108
|
prerelease: false
|
|
125
109
|
version_requirements: !ruby/object:Gem::Requirement
|
|
126
110
|
requirements:
|
|
127
111
|
- - "~>"
|
|
128
112
|
- !ruby/object:Gem::Version
|
|
129
|
-
version:
|
|
113
|
+
version: 0.3.20
|
|
130
114
|
- !ruby/object:Gem::Dependency
|
|
131
115
|
name: pg
|
|
132
116
|
requirement: !ruby/object:Gem::Requirement
|
|
133
117
|
requirements:
|
|
134
118
|
- - "~>"
|
|
135
119
|
- !ruby/object:Gem::Version
|
|
136
|
-
version: '0.
|
|
137
|
-
type: :development
|
|
138
|
-
prerelease: false
|
|
139
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
140
|
-
requirements:
|
|
141
|
-
- - "~>"
|
|
142
|
-
- !ruby/object:Gem::Version
|
|
143
|
-
version: '0.17'
|
|
144
|
-
- !ruby/object:Gem::Dependency
|
|
145
|
-
name: bson_ext
|
|
146
|
-
requirement: !ruby/object:Gem::Requirement
|
|
147
|
-
requirements:
|
|
148
|
-
- - "~>"
|
|
149
|
-
- !ruby/object:Gem::Version
|
|
150
|
-
version: '1.6'
|
|
120
|
+
version: '0.18'
|
|
151
121
|
type: :development
|
|
152
122
|
prerelease: false
|
|
153
123
|
version_requirements: !ruby/object:Gem::Requirement
|
|
154
124
|
requirements:
|
|
155
125
|
- - "~>"
|
|
156
126
|
- !ruby/object:Gem::Version
|
|
157
|
-
version: '
|
|
127
|
+
version: '0.18'
|
|
158
128
|
description: Log all changes to your models
|
|
159
129
|
email: info@collectiveidea.com
|
|
160
130
|
executables: []
|
|
@@ -165,7 +135,7 @@ files:
|
|
|
165
135
|
- ".travis.yml"
|
|
166
136
|
- ".yardopts"
|
|
167
137
|
- Appraisals
|
|
168
|
-
- CHANGELOG
|
|
138
|
+
- CHANGELOG.md
|
|
169
139
|
- Gemfile
|
|
170
140
|
- LICENSE
|
|
171
141
|
- README.md
|
|
@@ -173,14 +143,30 @@ files:
|
|
|
173
143
|
- gemfiles/rails40.gemfile
|
|
174
144
|
- gemfiles/rails41.gemfile
|
|
175
145
|
- gemfiles/rails42.gemfile
|
|
146
|
+
- gemfiles/rails50.gemfile
|
|
147
|
+
- gemfiles/rails51.gemfile
|
|
148
|
+
- lib/audited-rspec.rb
|
|
176
149
|
- lib/audited.rb
|
|
177
|
-
- lib/audited/active_record/version.rb
|
|
178
150
|
- lib/audited/audit.rb
|
|
179
151
|
- lib/audited/auditor.rb
|
|
180
|
-
- lib/audited/mongo_mapper/version.rb
|
|
181
152
|
- lib/audited/rspec_matchers.rb
|
|
182
153
|
- lib/audited/sweeper.rb
|
|
183
154
|
- lib/audited/version.rb
|
|
155
|
+
- lib/generators/audited/install_generator.rb
|
|
156
|
+
- lib/generators/audited/migration.rb
|
|
157
|
+
- lib/generators/audited/migration_helper.rb
|
|
158
|
+
- lib/generators/audited/templates/add_association_to_audits.rb
|
|
159
|
+
- lib/generators/audited/templates/add_comment_to_audits.rb
|
|
160
|
+
- lib/generators/audited/templates/add_remote_address_to_audits.rb
|
|
161
|
+
- lib/generators/audited/templates/add_request_uuid_to_audits.rb
|
|
162
|
+
- lib/generators/audited/templates/install.rb
|
|
163
|
+
- lib/generators/audited/templates/rename_association_to_associated.rb
|
|
164
|
+
- lib/generators/audited/templates/rename_changes_to_audited_changes.rb
|
|
165
|
+
- lib/generators/audited/templates/rename_parent_to_association.rb
|
|
166
|
+
- lib/generators/audited/upgrade_generator.rb
|
|
167
|
+
- spec/audited/audit_spec.rb
|
|
168
|
+
- spec/audited/auditor_spec.rb
|
|
169
|
+
- spec/audited/sweeper_spec.rb
|
|
184
170
|
- spec/audited_spec_helpers.rb
|
|
185
171
|
- spec/rails_app/config/application.rb
|
|
186
172
|
- spec/rails_app/config/database.yml
|
|
@@ -194,9 +180,9 @@ files:
|
|
|
194
180
|
- spec/rails_app/config/routes.rb
|
|
195
181
|
- spec/spec_helper.rb
|
|
196
182
|
- spec/support/active_record/models.rb
|
|
183
|
+
- spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb
|
|
184
|
+
- spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb
|
|
197
185
|
- spec/support/active_record/schema.rb
|
|
198
|
-
- spec/support/mongo_mapper/connection.rb
|
|
199
|
-
- spec/support/mongo_mapper/models.rb
|
|
200
186
|
- test/db/version_1.rb
|
|
201
187
|
- test/db/version_2.rb
|
|
202
188
|
- test/db/version_3.rb
|
|
@@ -226,24 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
226
212
|
version: '0'
|
|
227
213
|
requirements: []
|
|
228
214
|
rubyforge_project:
|
|
229
|
-
rubygems_version: 2.
|
|
215
|
+
rubygems_version: 2.6.6
|
|
230
216
|
signing_key:
|
|
231
217
|
specification_version: 4
|
|
232
218
|
summary: Log all changes to your models
|
|
233
|
-
test_files:
|
|
234
|
-
- spec/audited_spec_helpers.rb
|
|
235
|
-
- spec/rails_app/config/application.rb
|
|
236
|
-
- spec/rails_app/config/database.yml
|
|
237
|
-
- spec/rails_app/config/environment.rb
|
|
238
|
-
- spec/rails_app/config/environments/development.rb
|
|
239
|
-
- spec/rails_app/config/environments/production.rb
|
|
240
|
-
- spec/rails_app/config/environments/test.rb
|
|
241
|
-
- spec/rails_app/config/initializers/backtrace_silencers.rb
|
|
242
|
-
- spec/rails_app/config/initializers/inflections.rb
|
|
243
|
-
- spec/rails_app/config/initializers/secret_token.rb
|
|
244
|
-
- spec/rails_app/config/routes.rb
|
|
245
|
-
- spec/spec_helper.rb
|
|
246
|
-
- spec/support/active_record/models.rb
|
|
247
|
-
- spec/support/active_record/schema.rb
|
|
248
|
-
- spec/support/mongo_mapper/connection.rb
|
|
249
|
-
- spec/support/mongo_mapper/models.rb
|
|
219
|
+
test_files: []
|
data/CHANGELOG
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
Audited ChangeLog
|
|
2
|
-
-------------------------------------------------------------------------------
|
|
3
|
-
* 2012-04-10 - Add Audit scopes for creates, updates and destroys [chriswfx]
|
|
4
|
-
* 2011-10-25 - Made ignored_attributes configurable [senny]
|
|
5
|
-
* 2011-09-09 - Rails 3.x support
|
|
6
|
-
Support for associated audits
|
|
7
|
-
Support for remote IP address storage
|
|
8
|
-
Plenty of bug fixes and refactoring
|
|
9
|
-
[kennethkalmer, ineu, PatrickMa, jrozner, dwarburton, bsiggelkow, dgm]
|
|
10
|
-
* 2009-01-27 - Store old and new values for updates, and store all attributes on destroy.
|
|
11
|
-
Refactored revisioning methods to work as expected
|
|
12
|
-
* 2008-10-10 - changed to make it work in development mode
|
|
13
|
-
* 2008-09-24 - Add ability to record parent record of the record being audited
|
|
14
|
-
[Kenneth Kalmer]
|
|
15
|
-
* 2008-04-19 - refactored to make compatible with dirty tracking in edge rails
|
|
16
|
-
and to stop storing both old and new values in a single audit
|
|
17
|
-
* 2008-04-18 - Fix NoMethodError when trying to access the :previous revision
|
|
18
|
-
on a model that doesn't have previous revisions [Alex Soto]
|
|
19
|
-
* 2008-03-21 - added #changed_attributes to get access to the changes before a
|
|
20
|
-
save [Chris Parker]
|
|
21
|
-
* 2007-12-16 - Added #revision_at for retrieving a revision from a specific
|
|
22
|
-
time [Jacob Atzen]
|
|
23
|
-
* 2007-12-16 - Fix error when getting revision from audit with no changes
|
|
24
|
-
[Geoffrey Wiseman]
|
|
25
|
-
* 2007-12-16 - Remove dependency on acts_as_list
|
|
26
|
-
* 2007-06-17 - Added support getting previous revisions
|
|
27
|
-
* 2006-11-17 - Replaced use of singleton User.current_user with cache sweeper
|
|
28
|
-
implementation for auditing the user that made the change
|
|
29
|
-
* 2006-11-17 - added migration generator
|
|
30
|
-
* 2006-08-14 - incorporated changes from Michael Schuerig to write_attribute
|
|
31
|
-
that saves the new value after every change and not just the
|
|
32
|
-
first, and performs proper type-casting before doing comparisons
|
|
33
|
-
* 2006-08-14 - The "changes" are now saved as a serialized hash
|
|
34
|
-
* 2006-07-21 - initial version
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
require 'cgi'
|
|
2
|
-
require 'mongo_mapper'
|
|
3
|
-
require File.expand_path('../connection', __FILE__)
|
|
4
|
-
|
|
5
|
-
module Models
|
|
6
|
-
module MongoMapper
|
|
7
|
-
class User
|
|
8
|
-
include ::MongoMapper::Document
|
|
9
|
-
|
|
10
|
-
key :name, String
|
|
11
|
-
key :username, String
|
|
12
|
-
key :password, String
|
|
13
|
-
key :activated, Boolean
|
|
14
|
-
key :suspended_at, Time
|
|
15
|
-
key :logins, Integer, :default => 0
|
|
16
|
-
timestamps!
|
|
17
|
-
|
|
18
|
-
audited :allow_mass_assignment => true, :except => :password
|
|
19
|
-
|
|
20
|
-
attr_protected :logins
|
|
21
|
-
|
|
22
|
-
def name=(val)
|
|
23
|
-
write_attribute(:name, CGI.escapeHTML(val))
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class CommentRequiredUser
|
|
28
|
-
include ::MongoMapper::Document
|
|
29
|
-
|
|
30
|
-
key :name, String
|
|
31
|
-
key :username, String
|
|
32
|
-
key :password, String
|
|
33
|
-
key :activated, Boolean
|
|
34
|
-
key :suspended_at, Time
|
|
35
|
-
key :logins, Integer, :default => 0
|
|
36
|
-
timestamps!
|
|
37
|
-
|
|
38
|
-
audited :comment_required => true
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class AccessibleAfterDeclarationUser
|
|
42
|
-
include ::MongoMapper::Document
|
|
43
|
-
|
|
44
|
-
key :name, String
|
|
45
|
-
key :username, String
|
|
46
|
-
key :password, String
|
|
47
|
-
key :activated, Boolean
|
|
48
|
-
key :suspended_at, Time
|
|
49
|
-
key :logins, Integer, :default => 0
|
|
50
|
-
timestamps!
|
|
51
|
-
|
|
52
|
-
audited
|
|
53
|
-
attr_accessible :name, :username, :password
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
class AccessibleBeforeDeclarationUser
|
|
57
|
-
include ::MongoMapper::Document
|
|
58
|
-
|
|
59
|
-
key :name, String
|
|
60
|
-
key :username, String
|
|
61
|
-
key :password, String
|
|
62
|
-
key :activated, Boolean
|
|
63
|
-
key :suspended_at, Time
|
|
64
|
-
key :logins, Integer, :default => 0
|
|
65
|
-
timestamps!
|
|
66
|
-
|
|
67
|
-
attr_accessible :name, :username, :password # declare attr_accessible before calling aaa
|
|
68
|
-
audited
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
class NoAttributeProtectionUser
|
|
72
|
-
include ::MongoMapper::Document
|
|
73
|
-
|
|
74
|
-
key :name, String
|
|
75
|
-
key :username, String
|
|
76
|
-
key :password, String
|
|
77
|
-
key :activated, Boolean
|
|
78
|
-
key :suspended_at, Time
|
|
79
|
-
key :logins, Integer, :default => 0
|
|
80
|
-
timestamps!
|
|
81
|
-
|
|
82
|
-
audited :allow_mass_assignment => true
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
class UserWithAfterAudit
|
|
86
|
-
include ::MongoMapper::Document
|
|
87
|
-
|
|
88
|
-
key :name, String
|
|
89
|
-
key :username, String
|
|
90
|
-
key :password, String
|
|
91
|
-
key :activated, Boolean
|
|
92
|
-
key :suspended_at, Time
|
|
93
|
-
key :logins, Integer, :default => 0
|
|
94
|
-
timestamps!
|
|
95
|
-
|
|
96
|
-
audited
|
|
97
|
-
attr_accessor :bogus_attr, :around_attr
|
|
98
|
-
|
|
99
|
-
def after_audit
|
|
100
|
-
self.bogus_attr = "do something"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def around_audit
|
|
104
|
-
self.around_attr = yield
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
class Company
|
|
109
|
-
include ::MongoMapper::Document
|
|
110
|
-
|
|
111
|
-
key :name, String
|
|
112
|
-
key :owner_id, ObjectId
|
|
113
|
-
|
|
114
|
-
audited
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
class Owner
|
|
118
|
-
include ::MongoMapper::Document
|
|
119
|
-
|
|
120
|
-
key :name, String
|
|
121
|
-
key :username, String
|
|
122
|
-
key :password, String
|
|
123
|
-
key :activated, Boolean
|
|
124
|
-
key :suspended_at, Time
|
|
125
|
-
key :logins, Integer, :default => 0
|
|
126
|
-
timestamps!
|
|
127
|
-
|
|
128
|
-
has_associated_audits
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
class OwnedCompany
|
|
132
|
-
include ::MongoMapper::Document
|
|
133
|
-
|
|
134
|
-
key :name, String
|
|
135
|
-
key :owner_id, ObjectId
|
|
136
|
-
|
|
137
|
-
belongs_to :owner, :class_name => "Owner"
|
|
138
|
-
attr_accessible :name, :owner # declare attr_accessible before calling aaa
|
|
139
|
-
audited :associated_with => :owner
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
class OnUpdateDestroy
|
|
143
|
-
include ::MongoMapper::Document
|
|
144
|
-
|
|
145
|
-
key :name, String
|
|
146
|
-
key :owner_id, ObjectId
|
|
147
|
-
|
|
148
|
-
audited :on => [:update, :destroy]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
class OnCreateDestroy
|
|
152
|
-
include ::MongoMapper::Document
|
|
153
|
-
|
|
154
|
-
key :name, String
|
|
155
|
-
key :owner_id, ObjectId
|
|
156
|
-
|
|
157
|
-
audited :on => [:create, :destroy]
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
class OnCreateDestroyExceptName
|
|
161
|
-
include ::MongoMapper::Document
|
|
162
|
-
|
|
163
|
-
key :name, String
|
|
164
|
-
key :owner_id, ObjectId
|
|
165
|
-
|
|
166
|
-
audited :except => :name, :on => [:create, :destroy]
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
class OnCreateUpdate
|
|
170
|
-
include ::MongoMapper::Document
|
|
171
|
-
|
|
172
|
-
key :name, String
|
|
173
|
-
key :owner_id, ObjectId
|
|
174
|
-
|
|
175
|
-
audited :on => [:create, :update]
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
class RichObjectUser
|
|
179
|
-
include ::MongoMapper::Document
|
|
180
|
-
|
|
181
|
-
class Name
|
|
182
|
-
attr_accessor :first_name, :last_name
|
|
183
|
-
|
|
184
|
-
def self.from_mongo(value)
|
|
185
|
-
case value
|
|
186
|
-
when String then new(*value.split)
|
|
187
|
-
when self then value
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def self.to_mongo(value)
|
|
192
|
-
case value
|
|
193
|
-
when String then value
|
|
194
|
-
when self then value.to_s
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def initialize(first_name, last_name)
|
|
199
|
-
self.first_name, self.last_name = first_name, last_name
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def to_s
|
|
203
|
-
[first_name, last_name].compact.join(' ')
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
key :name, Name
|
|
208
|
-
|
|
209
|
-
attr_accessible :name
|
|
210
|
-
|
|
211
|
-
audited
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
end
|