acts_as_audited_collection 1.0.1 → 1.0.2
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 +8 -0
- data/acts_as_audited_collection.gemspec +1 -1
- data/lib/active_record/acts/audited_collection.rb +10 -9
- data/lib/acts_as_audited_collection/collection_audit.rb +1 -1
- data/lib/acts_as_audited_collection/version.rb +1 -1
- data/lib/generators/audited_collection_migration/audited_collection_migration_generator.rb +7 -0
- data/lib/generators/audited_collection_migration/templates/migration.rb +2 -1
- data/lib/generators/audited_collection_upgrade/templates/migration.rb +8 -0
- data/spec/acts_as_audited_collection_spec.rb +2 -2
- data/spec/db/schema.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +7 -7
data/README.md
CHANGED
|
@@ -37,6 +37,14 @@ Generating the migration
|
|
|
37
37
|
script/generate audited_collection_migration add_collection_audits_table
|
|
38
38
|
rake db:migrate
|
|
39
39
|
|
|
40
|
+
Upgrading
|
|
41
|
+
---------
|
|
42
|
+
|
|
43
|
+
Specify the version you're upgrading *from* as a parameter.
|
|
44
|
+
|
|
45
|
+
rails generate audited_collect_migration upgrade_collection_audits_table 0.4.0
|
|
46
|
+
rake db:migrate
|
|
47
|
+
|
|
40
48
|
Usage
|
|
41
49
|
=====
|
|
42
50
|
|
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
gem.add_development_dependency 'ruby-debug'
|
|
19
19
|
gem.add_development_dependency 'rake'
|
|
20
20
|
gem.add_development_dependency 'rspec'
|
|
21
|
-
gem.add_development_dependency 'rails', '~>3.
|
|
21
|
+
gem.add_development_dependency 'rails', '~>3.2'
|
|
22
22
|
gem.add_development_dependency 'sqlite3'
|
|
23
23
|
end
|
|
@@ -7,13 +7,13 @@ module ActiveRecord
|
|
|
7
7
|
# First time use in this class, we have some extra work to do.
|
|
8
8
|
send :include, InstanceMethods
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
class_attribute :audited_collections
|
|
11
|
+
send :audited_collections=, {}
|
|
12
12
|
attr_accessor :collection_audit_object_is_soft_deleted
|
|
13
13
|
|
|
14
14
|
after_create :collection_audit_create
|
|
15
15
|
before_update :collection_audit_update
|
|
16
|
-
|
|
16
|
+
before_destroy :collection_audit_destroy
|
|
17
17
|
|
|
18
18
|
has_many :child_collection_audits, :as => :child_record,
|
|
19
19
|
:class_name => 'CollectionAudit'
|
|
@@ -42,7 +42,7 @@ module ActiveRecord
|
|
|
42
42
|
|
|
43
43
|
# Try explicit first, then default
|
|
44
44
|
options[:foreign_key] ||= parent_association.options[:foreign_key]
|
|
45
|
-
options[:foreign_key] ||= parent_association.
|
|
45
|
+
options[:foreign_key] ||= parent_association.foreign_key
|
|
46
46
|
|
|
47
47
|
# TODO Remove this when polymorphic is supported.
|
|
48
48
|
if parent_association.options[:polymorphic]
|
|
@@ -68,12 +68,12 @@ module ActiveRecord
|
|
|
68
68
|
|
|
69
69
|
has_many :"#{options[:for]}_audits", :as => :parent_record,
|
|
70
70
|
:class_name => 'CollectionAudit',
|
|
71
|
-
:conditions => ['
|
|
71
|
+
:conditions => ['audited_association = ?', options[:for].to_s]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def define_acts_as_audited_collection(options)
|
|
75
75
|
key = "#{options[:parent_type]}##{options[:name]}"
|
|
76
|
-
yield(
|
|
76
|
+
yield(audited_collections[key] ||= {})
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def without_collection_audit
|
|
@@ -167,11 +167,12 @@ module ActiveRecord
|
|
|
167
167
|
(object_being_restored and opts[:action] != 'add') or
|
|
168
168
|
object_is_deleted
|
|
169
169
|
|
|
170
|
-
audit = child_collection_audits.create
|
|
170
|
+
audit = child_collection_audits.create({:parent_record_id => fk_val,
|
|
171
171
|
:parent_record_type => mappings[fk][:parent_type],
|
|
172
|
+
:audited_association => mappings[fk][:name].to_s,
|
|
172
173
|
:action => opts[:action],
|
|
173
|
-
:
|
|
174
|
-
:
|
|
174
|
+
:child_audit => opts[:child_audit]},
|
|
175
|
+
:without_protection => true)
|
|
175
176
|
|
|
176
177
|
if mappings[fk][:cascade]
|
|
177
178
|
parent = mappings[fk][:parent_type].constantize.send :find, fk_val
|
|
@@ -20,7 +20,7 @@ class CollectionAudit < ActiveRecord::Base
|
|
|
20
20
|
:parent_record_id => parent_record_id,
|
|
21
21
|
:child_record_type => child_record_type,
|
|
22
22
|
:child_record_id => child_record_id,
|
|
23
|
-
:
|
|
23
|
+
:audited_association => audited_association,
|
|
24
24
|
:current => true
|
|
25
25
|
).update_all :current => false
|
|
26
26
|
self.current = true
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Released under the MIT license. See the LICENSE file for details
|
|
2
2
|
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/migration'
|
|
5
|
+
require 'rails/generators/active_record/migration'
|
|
6
|
+
|
|
3
7
|
class AuditedCollectionMigrationGenerator < Rails::Generators::NamedBase
|
|
8
|
+
include Rails::Generators::Migration
|
|
9
|
+
extend ActiveRecord::Generators::Migration
|
|
10
|
+
|
|
4
11
|
source_root File.join(File.dirname(__FILE__), 'templates')
|
|
5
12
|
|
|
6
13
|
def manifest
|
|
@@ -6,7 +6,8 @@ class <%= class_name %> < ActiveRecord::Migration
|
|
|
6
6
|
t.references :user, :polymorphic => {}
|
|
7
7
|
t.references :child_audit
|
|
8
8
|
t.string :action
|
|
9
|
-
t.string :
|
|
9
|
+
t.string :audited_association
|
|
10
|
+
t.boolean :current
|
|
10
11
|
t.datetime :created_at
|
|
11
12
|
|
|
12
13
|
t.index [:parent_record_id, :parent_record_type], :name => 'parent_record_index'
|
|
@@ -16,9 +16,17 @@ class <%= class_name %> < ActiveRecord::Migration
|
|
|
16
16
|
set ca_old.current = false
|
|
17
17
|
}
|
|
18
18
|
<% end %>
|
|
19
|
+
|
|
20
|
+
<% if (from_version <=> [1,0,2]) < 0 %>
|
|
21
|
+
rename_column :collection_audits, :association, :audited_association
|
|
22
|
+
<% end %>
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def self.down
|
|
26
|
+
<% if (from_version <=> [1,0,2]) < 0 %>
|
|
27
|
+
rename_column :collection_audits, :audited_association, :association
|
|
28
|
+
<% end %>
|
|
29
|
+
|
|
22
30
|
<% if (from_version <=> [1,0,0]) < 0 %>
|
|
23
31
|
remove_index :collection_audits, :current
|
|
24
32
|
remove_column :collection_audits, :current
|
|
@@ -195,7 +195,7 @@ describe 'Acts as audited collection plugin' do
|
|
|
195
195
|
it 'saves the collection name with the audit entry' do
|
|
196
196
|
p = TestParent.create :name => 'test parent'
|
|
197
197
|
c = p.test_children.create :name => 'test child'
|
|
198
|
-
CollectionAudit.last.
|
|
198
|
+
CollectionAudit.last.audited_association.should == 'test_children'
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it 'makes the collection history available through the parent class' do
|
|
@@ -224,7 +224,7 @@ describe 'Acts as audited collection plugin' do
|
|
|
224
224
|
p.other_test_children_audits.last.child_record.should == c
|
|
225
225
|
p.other_test_children_audits.last.parent_record.should == p
|
|
226
226
|
p.other_test_children_audits.last.action.should == 'add'
|
|
227
|
-
p.other_test_children_audits.last.
|
|
227
|
+
p.other_test_children_audits.last.audited_association.should == 'other_test_children'
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
it 'correctly audits when a parent is reassociated through a secondary collection' do
|
data/spec/db/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -11,7 +11,7 @@ ActiveRecord::Base.send :extend, ActiveRecord::Acts::AuditedCollection::ClassMet
|
|
|
11
11
|
|
|
12
12
|
databases = YAML::load(IO.read(plugin_spec_dir + "/db/database.yml"))
|
|
13
13
|
ActiveRecord::Base.establish_connection(databases[ENV["DB"] || "sqlite3"])
|
|
14
|
-
|
|
14
|
+
require File.join(plugin_spec_dir, "db", "schema.rb")
|
|
15
15
|
|
|
16
16
|
require File.join(File.dirname(__FILE__), '..', 'init.rb')
|
|
17
17
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_audited_collection
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 19
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 1.0.
|
|
9
|
+
- 2
|
|
10
|
+
version: 1.0.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Shaun Mangelsdorf
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-
|
|
18
|
+
date: 2012-11-21 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
prerelease: false
|
|
@@ -67,11 +67,11 @@ dependencies:
|
|
|
67
67
|
requirements:
|
|
68
68
|
- - ~>
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
|
-
hash:
|
|
70
|
+
hash: 3
|
|
71
71
|
segments:
|
|
72
72
|
- 3
|
|
73
|
-
-
|
|
74
|
-
version: "3.
|
|
73
|
+
- 2
|
|
74
|
+
version: "3.2"
|
|
75
75
|
requirement: *id004
|
|
76
76
|
type: :development
|
|
77
77
|
- !ruby/object:Gem::Dependency
|