acts_as_replaceable 1.1.0 → 1.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.
@@ -1,4 +1,7 @@
|
|
1
1
|
module ActsAsReplaceable
|
2
|
+
class RecordNotUnique < Exception
|
3
|
+
end
|
4
|
+
|
2
5
|
module ActMethod
|
3
6
|
# If any before_save methods change the attributes,
|
4
7
|
# acts_as_replaceable will not function correctly.
|
@@ -51,8 +54,8 @@ module ActsAsReplaceable
|
|
51
54
|
|
52
55
|
def find_duplicate
|
53
56
|
records = self.class.where(match_conditions).where(insensitive_match_conditions)
|
54
|
-
if records.
|
55
|
-
raise "#{records.
|
57
|
+
if records.length > 1
|
58
|
+
raise RecordNotUnique, "#{records.length} duplicate #{self.class.model_name.human.pluralize} present in database"
|
56
59
|
end
|
57
60
|
|
58
61
|
return records.first
|
@@ -61,9 +64,8 @@ module ActsAsReplaceable
|
|
61
64
|
def replace(other)
|
62
65
|
return unless other
|
63
66
|
inherit_attributes(other)
|
67
|
+
@new_record = false
|
64
68
|
@has_been_replaced = true
|
65
|
-
define_singleton_method(:new_record?) { false }
|
66
|
-
define_singleton_method(:persisted?) { true }
|
67
69
|
@has_not_changed = !mark_changes(other)
|
68
70
|
end
|
69
71
|
|