immortal 0.1.0 → 0.1.1
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 +4 -0
- data/immortal.gemspec +1 -1
- data/lib/immortal.rb +11 -0
- data/spec/immortal_spec.rb +12 -0
- data/spec/spec_helper.rb +31 -0
- metadata +4 -4
data/README.md
CHANGED
data/immortal.gemspec
CHANGED
@@ -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.
|
6
|
+
s.version = '0.1.1'
|
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"]
|
data/lib/immortal.rb
CHANGED
@@ -44,6 +44,17 @@ module Immortal
|
|
44
44
|
unscoped.mortal_delete_all
|
45
45
|
end
|
46
46
|
|
47
|
+
# In has_many :through => join_model we have to explicitly add
|
48
|
+
# the 'not deleted' scope, otherwise it will take all the rows
|
49
|
+
# from the join model
|
50
|
+
def has_many(association_id, options = {}, &extension)
|
51
|
+
if options.key?(:through)
|
52
|
+
conditions = "#{options[:through].to_s.pluralize}.deleted IS NULL OR #{options[:through].to_s.pluralize}.deleted = ?"
|
53
|
+
options[:conditions] = ["(" + [options[:conditions], conditions].compact.join(") AND (") + ")", false]
|
54
|
+
end
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
47
58
|
end
|
48
59
|
|
49
60
|
module InstanceMethods
|
data/spec/immortal_spec.rb
CHANGED
@@ -177,4 +177,16 @@ describe Immortal do
|
|
177
177
|
ImmortalModel.count.should == 2
|
178
178
|
end
|
179
179
|
|
180
|
+
it "should consider an Many-to-many association with through as deleted when the join is deleted." do
|
181
|
+
@n = ImmortalNode.create! :title => 'testing association'
|
182
|
+
@join = ImmortalJoin.create! :immortal_model => @m, :immortal_node => @n
|
183
|
+
|
184
|
+
@m.immortal_nodes.count.should == 1
|
185
|
+
@n.immortal_models.count.should == 1
|
186
|
+
|
187
|
+
@join.destroy
|
188
|
+
|
189
|
+
@m.immortal_nodes.count.should == 0
|
190
|
+
@n.immortal_models.count.should == 0
|
191
|
+
end
|
180
192
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rspec'
|
|
3
3
|
require 'lib/immortal'
|
4
4
|
require 'active_record'
|
5
5
|
require 'sqlite3'
|
6
|
+
require 'logger'
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
8
9
|
config.before(:each) do
|
@@ -15,6 +16,7 @@ end
|
|
15
16
|
|
16
17
|
|
17
18
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
19
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
|
18
20
|
|
19
21
|
old_stdout = $stdout
|
20
22
|
$stdout = StringIO.new
|
@@ -27,6 +29,18 @@ begin
|
|
27
29
|
t.boolean :deleted, :default => false
|
28
30
|
t.timestamps
|
29
31
|
end
|
32
|
+
create_table :immortal_joins do |t|
|
33
|
+
t.integer :immortal_model_id
|
34
|
+
t.integer :immortal_node_id
|
35
|
+
t.boolean :deleted, :default => false
|
36
|
+
t.timestamps
|
37
|
+
end
|
38
|
+
create_table :immortal_nodes do |t|
|
39
|
+
t.string :title
|
40
|
+
t.integer :value
|
41
|
+
t.boolean :deleted, :default => false
|
42
|
+
t.timestamps
|
43
|
+
end
|
30
44
|
end
|
31
45
|
ensure
|
32
46
|
$stdout = old_stdout
|
@@ -35,6 +49,9 @@ end
|
|
35
49
|
class ImmortalModel < ActiveRecord::Base
|
36
50
|
include Immortal
|
37
51
|
|
52
|
+
has_many :immortal_nodes, :through => :immortal_joins
|
53
|
+
has_many :immortal_joins
|
54
|
+
|
38
55
|
attr_accessor :before_d, :after_d, :before_u, :after_u
|
39
56
|
|
40
57
|
before_destroy :set_before
|
@@ -60,3 +77,17 @@ class ImmortalModel < ActiveRecord::Base
|
|
60
77
|
end
|
61
78
|
|
62
79
|
end
|
80
|
+
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
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-
|
19
|
+
date: 2010-12-30 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|