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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a15819e53f8f962178a7dd8157bd12b81a5fcfb2
4
- data.tar.gz: 938d92a2b99ef933513433446e36df470a8511ee
3
+ metadata.gz: 85a53c3f855e9a344cb3468020ebaf699c0fe2ae
4
+ data.tar.gz: 32ce6b0c07b5382f12216ae9232d7001808c946b
5
5
  SHA512:
6
- metadata.gz: f14d4ac30c9bfb4644c155ab3d7d8a4665be9861733e4e2802a0215843d9d23e9bcb064db6a15be9a153a5872c6625d89efee6410197ea774a89cf0d3d0ed389
7
- data.tar.gz: 9611c73889a26589ec4080953c1e2698143d472d75b6dcfc486de33d2838312c326027682f941d1ef9b5a649ea30e4b9c002bb8c8f3efba95f8cb5edcf2180b1
6
+ metadata.gz: 185a86732e0ea8695e0923e0bcd3487e4813863662bd9af4a5a570f01db4c4d0d402e15d55ae00e26fd14493d2b29c7757575b4684e70f496966d9047574409e
7
+ data.tar.gz: 38dc9004c75149c1376f5c73d98708971632914cc8d4b7f01acc3910cb40451e675ecbeccae97f41c9799c944b34009cefae5283f742cca47bd3e0b6ec5e0db9
@@ -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| !i.constantize.respond_to?(:pluck)}.each do |type|
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
@@ -1,4 +1,4 @@
1
1
  module PolyBelongsTo
2
2
  # VERSION follows symantic versioning rules
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  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
Binary file