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 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.0'
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
- class_inheritable_reader :audited_collections
11
- write_inheritable_attribute :audited_collections, {}
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
- after_destroy :collection_audit_destroy
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.primary_key_name
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 => ['association = ?', options[:for].to_s]
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(read_inheritable_attribute(:audited_collections)[key] ||= {})
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 :parent_record_id => fk_val,
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
- :association => mappings[fk][:name].to_s,
174
- :child_audit => opts[:child_audit]
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
- :association => association,
23
+ :audited_association => audited_association,
24
24
  :current => true
25
25
  ).update_all :current => false
26
26
  self.current = true
@@ -1,3 +1,3 @@
1
1
  module ActsAsAuditedCollection
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -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 :association
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.association.should == 'test_children'
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.association.should == 'other_test_children'
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
@@ -47,7 +47,7 @@ ActiveRecord::Schema.define(:version => 0) do
47
47
  t.references :user, :polymorphic => {}
48
48
  t.references :child_audit
49
49
  t.string :action
50
- t.string :association
50
+ t.string :audited_association
51
51
  t.boolean :current
52
52
  t.datetime :created_at
53
53
  end
@@ -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
- load(File.join(plugin_spec_dir, "db", "schema.rb"))
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
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-09-26 00:00:00 Z
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: 7
70
+ hash: 3
71
71
  segments:
72
72
  - 3
73
- - 0
74
- version: "3.0"
73
+ - 2
74
+ version: "3.2"
75
75
  requirement: *id004
76
76
  type: :development
77
77
  - !ruby/object:Gem::Dependency