acts_as_replaceable 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.load.size > 1
55
- raise "#{records.count} Duplicate #{self.class.model_name.pluralize} Present in Database:\n #{self.inspect} == #{records.inspect}"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_replaceable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: