immortal 1.0.2 → 1.0.3

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
@@ -41,6 +41,7 @@ If you want to improve immortal
41
41
 
42
42
  ## CHANGELOG
43
43
 
44
+ - 1.0.3 Added back feature where using immortal finders doesn't unscope association scopes.
44
45
  - 1.0.2 Added with/only_deleted singular association readers (see specs)
45
46
  - 1.0.1 Made compatible with Rails 3.1.X
46
47
  - 1.0.0 Changed the API, made it compatible with Rails 3.1, removed
@@ -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 = '1.0.2'
6
+ s.version = '1.0.3'
7
7
  s.authors = ["Jordi Romero", "Saimon Moore"]
8
8
  s.email = ["jordi@jrom.net", "saimon@saimonmoore.net"]
9
9
  s.homepage = "http://github.com/teambox/immortal"
@@ -42,8 +42,24 @@ module Immortal
42
42
  end
43
43
 
44
44
  def without_default_scope
45
- with_exclusive_scope do
46
- yield
45
+ new_scope = self.unscoped
46
+ our_scope = self.current_scope || self.unscoped
47
+
48
+ non_immortal_constraints = our_scope.arel.constraints.select do |constraint|
49
+ !constraint.to_sql.include?('deleted')
50
+ end
51
+
52
+ non_immortal_constraints_sql = non_immortal_constraints.to_a.map do |constraint|
53
+ constraint.to_sql
54
+ end.join(' AND ')
55
+
56
+ new_scope = new_scope.merge(our_scope.except(:where))
57
+ new_scope = new_scope.where(non_immortal_constraints_sql)
58
+
59
+ unscoped do
60
+ with_scope(new_scope) do
61
+ yield
62
+ end
47
63
  end
48
64
  end
49
65
 
@@ -247,4 +247,39 @@ describe Immortal do
247
247
  node.target.should be_nil
248
248
  end
249
249
 
250
+ it "should not unscope associations when using with_deleted scope" do
251
+ m1 = ImmortalModel.create! :title => 'previously created model'
252
+ n1 = ImmortalNode.create! :title => 'previously created association'
253
+ j1 = ImmortalJoin.create! :immortal_model => m1, :immortal_node => n1
254
+
255
+ @n = ImmortalNode.create! :title => 'testing association'
256
+ @join = ImmortalJoin.create! :immortal_model => @m, :immortal_node => @n
257
+
258
+ @join.destroy
259
+
260
+ @m.nodes.count.should == 0
261
+ @n.joins.count.should == 0
262
+
263
+ @m.nodes.count_with_deleted.should == 1
264
+ @n.joins.count_with_deleted.should == 1
265
+ end
266
+
267
+ it "should not unscope associations when using only_deleted scope" do
268
+ m1 = ImmortalModel.create! :title => 'previously created model'
269
+ n1 = ImmortalNode.create! :title => 'previously created association'
270
+ j1 = ImmortalJoin.create! :immortal_model => m1, :immortal_node => n1
271
+
272
+ @n = ImmortalNode.create! :title => 'testing association'
273
+ @join = ImmortalJoin.create! :immortal_model => @m, :immortal_node => @n
274
+
275
+ @join.destroy
276
+
277
+ @m.nodes.count.should == 0
278
+ @n.joins.count.should == 0
279
+
280
+ @m.nodes.count_only_deleted
281
+ @m.nodes.count_only_deleted.should == 1
282
+ @n.joins.count_only_deleted.should == 1
283
+ end
284
+
250
285
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immortal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2011-10-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &70147088431320 !ruby/object:Gem::Requirement
17
+ requirement: &70129308919760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70147088431320
25
+ version_requirements: *70129308919760
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70147088430840 !ruby/object:Gem::Requirement
28
+ requirement: &70129308919280 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70147088430840
36
+ version_requirements: *70129308919280
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- requirement: &70147088430460 !ruby/object:Gem::Requirement
39
+ requirement: &70129308918900 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70147088430460
47
+ version_requirements: *70129308918900
48
48
  description: Typical paranoid gem built for Rails 3 and with the minimum code needed
49
49
  to satisfy acts_as_paranoid's API
50
50
  email: