poly_belongs_to 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poly_belongs_to/core.rb +3 -2
- data/lib/poly_belongs_to/version.rb +1 -1
- data/test/core_test.rb +7 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +4991 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a53c3f855e9a344cb3468020ebaf699c0fe2ae
|
4
|
+
data.tar.gz: 32ce6b0c07b5382f12216ae9232d7001808c946b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 185a86732e0ea8695e0923e0bcd3487e4813863662bd9af4a5a570f01db4c4d0d402e15d55ae00e26fd14493d2b29c7757575b4684e70f496966d9047574409e
|
7
|
+
data.tar.gz: 38dc9004c75149c1376f5c73d98708971632914cc8d4b7f01acc3910cb40451e675ecbeccae97f41c9799c944b34009cefae5283f742cca47bd3e0b6ec5e0db9
|
data/lib/poly_belongs_to/core.rb
CHANGED
@@ -50,9 +50,10 @@ module PolyBelongsTo
|
|
50
50
|
def self.pbt_orphans
|
51
51
|
return nil unless self.pbts.present?
|
52
52
|
if self.poly?
|
53
|
-
# self.where(["#{self.pbt_id_sym} NOT IN (?) AND #{self.pbt_type_sym} = (?)", type.constantize.pluck(:id), type])
|
54
53
|
accumalitive = nil
|
55
|
-
self.pluck(self.pbt_type_sym).uniq.delete_if {|i|
|
54
|
+
self.pluck(self.pbt_type_sym).uniq.delete_if {|i|
|
55
|
+
begin !i.constantize.respond_to?(:pluck) rescue true end
|
56
|
+
}.each do |type|
|
56
57
|
arel_part = self.arel_table[self.pbt_id_sym].not_in(type.constantize.pluck(:id)).and(self.arel_table[self.pbt_type_sym].eq(type))
|
57
58
|
accumalitive = accumalitive.present? ? accumalitive.or(arel_part) : arel_part
|
58
59
|
end
|
data/test/core_test.rb
CHANGED
@@ -237,5 +237,12 @@ class CoreTest < ActiveSupport::TestCase
|
|
237
237
|
User.create()
|
238
238
|
User.pbt_orphans.must_be_nil
|
239
239
|
end
|
240
|
+
|
241
|
+
it "#pbt_orphans ignores mislabled record types" do
|
242
|
+
Squishy.create(Squishy.pbt_id_sym => 12345, Squishy.pbt_type_sym => "Object")
|
243
|
+
Squishy.create(Squishy.pbt_id_sym => 12345, Squishy.pbt_type_sym => "Class")
|
244
|
+
Squishy.create(Squishy.pbt_id_sym => 12345, Squishy.pbt_type_sym => "Squishable")
|
245
|
+
Squishy.pbt_orphans.must_be :empty?
|
246
|
+
end
|
240
247
|
end
|
241
248
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|