immortal 0.1.3 → 0.1.4

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.
@@ -17,10 +17,12 @@ GEM
17
17
  arel (~> 2.0.2)
18
18
  tzinfo (~> 0.3.23)
19
19
  activesupport (3.0.3)
20
- arel (2.0.6)
20
+ arel (2.0.7)
21
21
  builder (2.1.2)
22
+ columnize (0.3.2)
22
23
  diff-lcs (1.1.2)
23
24
  i18n (0.5.0)
25
+ linecache (0.43)
24
26
  rspec (2.3.0)
25
27
  rspec-core (~> 2.3.0)
26
28
  rspec-expectations (~> 2.3.0)
@@ -29,14 +31,19 @@ GEM
29
31
  rspec-expectations (2.3.0)
30
32
  diff-lcs (~> 1.1.2)
31
33
  rspec-mocks (2.3.0)
34
+ ruby-debug (0.10.4)
35
+ columnize (>= 0.1)
36
+ ruby-debug-base (~> 0.10.4.0)
37
+ ruby-debug-base (0.10.4)
38
+ linecache (>= 0.3)
32
39
  sqlite3-ruby (1.3.2)
33
- tzinfo (0.3.23)
40
+ tzinfo (0.3.24)
34
41
 
35
42
  PLATFORMS
36
43
  ruby
37
44
 
38
45
  DEPENDENCIES
39
- activerecord (~> 3.0.3)
40
46
  immortal!
41
47
  rspec (~> 2.3.0)
48
+ ruby-debug (~> 0.10.4)
42
49
  sqlite3-ruby (~> 1.3.2)
data/README.md CHANGED
@@ -44,6 +44,9 @@ If you want to improve immortal
44
44
 
45
45
  ## CHANGELOG
46
46
 
47
+ - 0.1.4 fix bug where ALL records of any dependent associations were
48
+ immortally deleted if assocation has :dependant => :delete_all option
49
+ set
47
50
  - 0.1.3 fix bug where join model is not immortal
48
51
  - 0.1.2 fix loading issue when the `deleted` column doesn't exist (or even the table)
49
52
  - 0.1.1 fix behavior with `has_many :through` associations
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "immortal"
6
- s.version = '0.1.3'
6
+ s.version = '0.1.4'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Jordi Romero", "Saimon Moore"]
9
9
  s.email = ["jordi@jrom.net", "saimon@saimonmoore.net"]
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'activerecord', '~> 3.0.3'
20
20
  s.add_development_dependency 'rspec', '~> 2.3.0'
21
21
  s.add_development_dependency 'sqlite3-ruby', '~> 1.3.2'
22
+ s.add_development_dependency 'ruby-debug', '~> 0.10.4'
22
23
  end
@@ -36,12 +36,12 @@ module Immortal
36
36
  only_deleted.find(*args)
37
37
  end
38
38
 
39
- def immortal_delete_all(*args)
40
- unscoped.update_all :deleted => true
39
+ def immortal_delete_all(conditions = nil)
40
+ unscoped.update_all({:deleted => 1}, conditions)
41
41
  end
42
42
 
43
43
  def delete_all!(*args)
44
- unscoped.mortal_delete_all
44
+ unscoped.mortal_delete_all(*args)
45
45
  end
46
46
 
47
47
  # In has_many :through => join_model we have to explicitly add
@@ -66,17 +66,17 @@ module Immortal
66
66
  end
67
67
  end
68
68
 
69
- def immortal_destroy(*args)
69
+ def immortal_destroy
70
70
  run_callbacks :destroy do
71
- destroy_without_callbacks(*args)
71
+ destroy_without_callbacks
72
72
  end
73
73
  end
74
74
 
75
- def destroy!(*args)
75
+ def destroy!
76
76
  mortal_destroy
77
77
  end
78
78
 
79
- def destroy_without_callbacks(*args)
79
+ def destroy_without_callbacks
80
80
  self.class.unscoped.update_all({ :deleted => true }, "id = #{self.id}")
81
81
  reload
82
82
  freeze
@@ -189,4 +189,20 @@ describe Immortal do
189
189
  @m.immortal_nodes.count.should == 0
190
190
  @n.immortal_models.count.should == 0
191
191
  end
192
+
193
+ it "should only immortally delete scoped associations, NOT ALL RECORDS" do
194
+ n1 = ImmortalNode.create! :title => 'testing association 1'
195
+ j1 = ImmortalJoin.create! :immortal_model => @m, :immortal_node => n1
196
+
197
+ n2 = ImmortalNode.create! :title => 'testing association 2'
198
+ j2 = ImmortalJoin.create! :immortal_model => @m, :immortal_node => n2
199
+
200
+ n3 = ImmortalNode.create! :title => 'testing association 3'
201
+ j3 = ImmortalJoin.create! :immortal_node => n3
202
+
203
+ @m.destroy
204
+
205
+ [n1,n2,j1,j2].all? {|r| r.reload.deleted?}.should be_true
206
+ [n3,j3].all? {|r| !r.reload.deleted?}.should be_true
207
+ end
192
208
  end
@@ -46,11 +46,25 @@ ensure
46
46
  $stdout = old_stdout
47
47
  end
48
48
 
49
- class ImmortalModel < ActiveRecord::Base
49
+ class ImmortalJoin < ActiveRecord::Base
50
+ include Immortal
51
+
52
+ belongs_to :immortal_model
53
+ belongs_to :immortal_node
54
+ end
55
+
56
+ class ImmortalNode < ActiveRecord::Base
50
57
  include Immortal
51
58
 
52
- has_many :immortal_nodes, :through => :immortal_joins
53
59
  has_many :immortal_joins
60
+ has_many :immortal_models, :through => :immortal_joins
61
+ end
62
+
63
+ class ImmortalModel < ActiveRecord::Base
64
+ include Immortal
65
+
66
+ has_many :immortal_nodes, :through => :immortal_joins, :dependent => :destroy
67
+ has_many :immortal_joins, :dependent => :delete_all
54
68
 
55
69
  attr_accessor :before_d, :after_d, :before_u, :after_u
56
70
 
@@ -78,16 +92,3 @@ class ImmortalModel < ActiveRecord::Base
78
92
 
79
93
  end
80
94
 
81
- class ImmortalJoin < ActiveRecord::Base
82
- include Immortal
83
-
84
- belongs_to :immortal_model
85
- belongs_to :immortal_node
86
- end
87
-
88
- class ImmortalNode < ActiveRecord::Base
89
- include Immortal
90
-
91
- has_many :immortal_joins
92
- has_many :immortal_models, :through => :immortal_joins
93
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immortal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jordi Romero
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-30 00:00:00 +01:00
19
+ date: 2011-01-19 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,22 @@ dependencies:
67
67
  version: 1.3.2
68
68
  type: :development
69
69
  version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: ruby-debug
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 63
79
+ segments:
80
+ - 0
81
+ - 10
82
+ - 4
83
+ version: 0.10.4
84
+ type: :development
85
+ version_requirements: *id004
70
86
  description: Typical paranoid gem built for Rails 3 and with the minimum code needed to satisfy acts_as_paranoid's API
71
87
  email:
72
88
  - jordi@jrom.net