Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #9853 from wangjohn/adding_bang_to_raise_method

Adding a bang to method name of raise_on_type_mismatch.
  • Loading branch information...
commit ecfdc842a58816540e7c96a913f95a0d94be7ca7 2 parents 34d9aed + 53b76c1
@rafaelfranca rafaelfranca authored
View
2  activerecord/lib/active_record/associations/association.rb
@@ -203,7 +203,7 @@ def foreign_key_present?
# Raises ActiveRecord::AssociationTypeMismatch unless +record+ is of
# the kind of the class of the associated objects. Meant to be used as
# a sanity check when you are about to assign an associated record.
- def raise_on_type_mismatch(record)
+ def raise_on_type_mismatch!(record)
unless record.is_a?(reflection.klass) || record.is_a?(reflection.class_name.constantize)
message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})"
raise ActiveRecord::AssociationTypeMismatch, message
View
2  activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -8,7 +8,7 @@ def handle_dependency
end
def replace(record)
- raise_on_type_mismatch(record) if record
+ raise_on_type_mismatch!(record) if record
update_counters(record)
replace_keys(record)
View
2  activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
@@ -22,7 +22,7 @@ def inverse_reflection_for(record)
reflection.polymorphic_inverse_of(record.class)
end
- def raise_on_type_mismatch(record)
+ def raise_on_type_mismatch!(record)
# A polymorphic association cannot have a type mismatch, by definition
end
View
6 activerecord/lib/active_record/associations/collection_association.rb
@@ -318,7 +318,7 @@ def distinct
# Replace this collection with +other_array+. This will perform a diff
# and delete/add only records that have changed.
def replace(other_array)
- other_array.each { |val| raise_on_type_mismatch(val) }
+ other_array.each { |val| raise_on_type_mismatch!(val) }
original_target = load_target.dup
if owner.new_record?
@@ -465,7 +465,7 @@ def create_scope
def delete_or_destroy(records, method)
records = records.flatten
- records.each { |record| raise_on_type_mismatch(record) }
+ records.each { |record| raise_on_type_mismatch!(record) }
existing_records = records.reject { |r| r.new_record? }
if existing_records.empty?
@@ -506,7 +506,7 @@ def concat_records(records)
result = true
records.flatten.each do |record|
- raise_on_type_mismatch(record)
+ raise_on_type_mismatch!(record)
add_to_target(record) do |rec|
result &&= insert_record(rec) unless owner.new_record?
end
View
2  activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -29,7 +29,7 @@ def size
def concat(*records)
unless owner.new_record?
records.flatten.each do |record|
- raise_on_type_mismatch(record)
+ raise_on_type_mismatch!(record)
record.save! if record.new_record?
end
end
View
2  activerecord/lib/active_record/associations/has_one_association.rb
@@ -22,7 +22,7 @@ def handle_dependency
end
def replace(record, save = true)
- raise_on_type_mismatch(record) if record
+ raise_on_type_mismatch!(record) if record
load_target
# If target and record are nil, or target is equal to record,
Please sign in to comment.
Something went wrong with that request. Please try again.