soft_deletion 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- Cm�tFI�v�o]`vF�xu�S�v]m1QL���f&]qfn��@iC��e�0�z����z��}��L4K�햡1O�=�@Ī��Iq��!I�(6Hj<+n�s<�@>�m��!�UX{z<�/���9�f��C�T� %O�����uN?j����ΕM��D�i�$��>�pɶ�ĎinN%�[�j�B���S��EA���~�$n��J��T��,�T<��V�^�*��t�
1
+ ���͛H�S'U̬������r/1��SF��(|
2
+ ������\7��E:]�IcS:E\I�[șA�.E��4ά���T��ÏL��0i��Y1�x��-D/I
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soft_deletion (0.4.2)
4
+ soft_deletion (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,7 +33,12 @@ module SoftDeletion
33
33
 
34
34
  def nullify_dependencies
35
35
  dependencies.each do |dependency|
36
- dependency.update_attribute(association.options[:foreign_key], nil)
36
+ foreign_key = if association.respond_to?(:foreign_key) # rails 3+
37
+ association.foreign_key
38
+ else # rails 2
39
+ association.options[:foreign_key] || "#{record.class.name.underscore}_id"
40
+ end
41
+ dependency.update_attribute(foreign_key, nil)
37
42
  end
38
43
  end
39
44
 
@@ -1,3 +1,3 @@
1
1
  module SoftDeletion
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -242,6 +242,18 @@ describe SoftDeletion do
242
242
  forum.category_id.should be_nil
243
243
  end
244
244
  end
245
+
246
+ context "a soft-deleted has-many category that nullifies forum references on delete without foreign_key" do
247
+ it "should nullify those references" do
248
+ organization = Organization.create!
249
+ forum = organization.forums.create!
250
+ organization.soft_delete!
251
+
252
+ forum.reload
253
+ forum.should_not be_deleted
254
+ forum.organization_id.should be_nil
255
+ end
256
+ end
245
257
  end
246
258
 
247
259
  context "without deleted_at column" do
data/spec/spec_helper.rb CHANGED
@@ -43,6 +43,7 @@ ActiveRecord::Schema.verbose = false
43
43
  ActiveRecord::Schema.define(:version => 1) do
44
44
  create_table :forums do |t|
45
45
  t.integer :category_id
46
+ t.integer :organization_id
46
47
  t.timestamp :deleted_at
47
48
  end
48
49
 
@@ -87,6 +88,14 @@ class Category < ActiveRecord::Base
87
88
  has_many :forums, :dependent => :destroy
88
89
  end
89
90
 
91
+ class Organization < ActiveRecord::Base
92
+ silent_set_table_name 'categories'
93
+ has_soft_deletion
94
+
95
+ has_many :forums, :dependent => :nullify
96
+ end
97
+
98
+
90
99
  # No association
91
100
  class NACategory < ActiveRecord::Base
92
101
  silent_set_table_name 'categories'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soft_deletion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  segments:
83
83
  - 0
84
- hash: -2568323612092411395
84
+ hash: 673516693853522626
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: -2568323612092411395
93
+ hash: 673516693853522626
94
94
  requirements: []
95
95
  rubyforge_project:
96
96
  rubygems_version: 1.8.25
metadata.gz.sig CHANGED
Binary file