paranoid 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
5
5
  :build:
@@ -2,3 +2,4 @@ require 'active_record'
2
2
  require 'paranoid/base'
3
3
  require 'paranoid/paranoid_methods'
4
4
  require 'paranoid/relation'
5
+ require 'paranoid/join_association'
@@ -0,0 +1,24 @@
1
+ module Paranoid
2
+ module JoinAssociation
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method_chain :association_join, :paranoid
7
+ end
8
+
9
+ # Overrides ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation#association_join
10
+ # adding paranoid conditions when necessary
11
+ def association_join_with_paranoid
12
+ return @join if @join
13
+ result = association_join_without_paranoid
14
+ if reflection.klass.paranoid?
15
+ aliased_table = Arel::Table.new(table_name, :as => @aliased_table_name, :engine => arel_engine)
16
+ pb = ActiveRecord::PredicateBuilder.new(arel_engine)
17
+ result.concat(pb.build_from_hash(reflection.klass.paranoid_condition, aliased_table))
18
+ end
19
+ result
20
+ end
21
+ end
22
+ end
23
+
24
+ ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.class_eval { include Paranoid::JoinAssociation }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paranoid}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Genord II"]
12
- s.date = %q{2010-02-19}
12
+ s.date = %q{2010-02-22}
13
13
  s.description = %q{}
14
14
  s.email = %q{github@xspond.com}
15
15
  s.extra_rdoc_files = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "init.rb",
24
24
  "lib/paranoid.rb",
25
25
  "lib/paranoid/base.rb",
26
+ "lib/paranoid/join_association.rb",
26
27
  "lib/paranoid/paranoid_methods.rb",
27
28
  "lib/paranoid/relation.rb",
28
29
  "paranoid.gemspec",
@@ -139,4 +139,57 @@ describe Paranoid do
139
139
  Ninja.with_destroyed_only.count.should == 1
140
140
  end
141
141
  end
142
+
143
+ describe 'has_many association' do
144
+ before(:each) do
145
+ Android.delete_all
146
+ Dent.delete_all
147
+
148
+ @r2d2 = Android.create(:name => 'R2D2')
149
+ @dents = Dent.create([
150
+ {:android => @r2d2, :description => 'Hit by debris'},
151
+ {:android => @r2d2, :description => 'Dropped while loading into X-Wing'},
152
+ {:android => @r2d2, :description => 'Blaster hit'}
153
+ ])
154
+
155
+ @dents[2].destroy
156
+ end
157
+
158
+ it 'should hide the soft deleted dent' do
159
+ @r2d2.dents.to_a.should == @dents[0,2]
160
+ end
161
+
162
+ it 'should show all dents with_destroyed' do
163
+ @r2d2.dents.with_destroyed.to_a.should == @dents
164
+ end
165
+
166
+ it 'should show only soft deleted with destroyed_only' do
167
+ @r2d2.dents.with_destroyed_only.to_a.should == [@dents[2]]
168
+ end
169
+
170
+ it 'should show the correct counts' do
171
+ @r2d2.dents.size.should == 2
172
+ @r2d2.dents.with_destroyed.size.should == 3
173
+ @r2d2.dents.with_destroyed_only.size.should == 1
174
+ end
175
+
176
+ it 'should load correctly through an eager load' do
177
+ @r2d2 = Android.eager_load(:dents).first
178
+ @r2d2.dents.loaded?.should be_true
179
+ @r2d2.dents.size.should == 2
180
+ @r2d2.dents.to_a.should == @dents[0,2]
181
+ end
182
+
183
+ it 'should load correctly through an include' do
184
+ @r2d2 = Android.includes(:dents).first
185
+ @r2d2.dents.loaded?.should be_true
186
+ @r2d2.dents.size.should == 2
187
+ @r2d2.dents.to_a.should == @dents[0,2]
188
+ end
189
+
190
+ it 'should work correctly for a include dependency' do
191
+ @nil = Android.includes(:dents).where('dents.description' => 'Blaster hit').first
192
+ @nil.should be_nil
193
+ end
194
+ end
142
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Genord II
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-19 00:00:00 -05:00
12
+ date: 2010-02-22 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,7 @@ files:
38
38
  - init.rb
39
39
  - lib/paranoid.rb
40
40
  - lib/paranoid/base.rb
41
+ - lib/paranoid/join_association.rb
41
42
  - lib/paranoid/paranoid_methods.rb
42
43
  - lib/paranoid/relation.rb
43
44
  - paranoid.gemspec