Skip to content

Commit ecfdc84

Browse files
committed
Merge pull request rails#9853 from wangjohn/adding_bang_to_raise_method
Adding a bang to method name of raise_on_type_mismatch.
2 parents 34d9aed + 53b76c1 commit ecfdc84

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

activerecord/lib/active_record/associations/association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def foreign_key_present?
203203
# Raises ActiveRecord::AssociationTypeMismatch unless +record+ is of
204204
# the kind of the class of the associated objects. Meant to be used as
205205
# a sanity check when you are about to assign an associated record.
206-
def raise_on_type_mismatch(record)
206+
def raise_on_type_mismatch!(record)
207207
unless record.is_a?(reflection.klass) || record.is_a?(reflection.class_name.constantize)
208208
message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})"
209209
raise ActiveRecord::AssociationTypeMismatch, message

activerecord/lib/active_record/associations/belongs_to_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def handle_dependency
88
end
99

1010
def replace(record)
11-
raise_on_type_mismatch(record) if record
11+
raise_on_type_mismatch!(record) if record
1212

1313
update_counters(record)
1414
replace_keys(record)

activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def inverse_reflection_for(record)
2222
reflection.polymorphic_inverse_of(record.class)
2323
end
2424

25-
def raise_on_type_mismatch(record)
25+
def raise_on_type_mismatch!(record)
2626
# A polymorphic association cannot have a type mismatch, by definition
2727
end
2828

activerecord/lib/active_record/associations/collection_association.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def distinct
318318
# Replace this collection with +other_array+. This will perform a diff
319319
# and delete/add only records that have changed.
320320
def replace(other_array)
321-
other_array.each { |val| raise_on_type_mismatch(val) }
321+
other_array.each { |val| raise_on_type_mismatch!(val) }
322322
original_target = load_target.dup
323323

324324
if owner.new_record?
@@ -465,7 +465,7 @@ def create_scope
465465

466466
def delete_or_destroy(records, method)
467467
records = records.flatten
468-
records.each { |record| raise_on_type_mismatch(record) }
468+
records.each { |record| raise_on_type_mismatch!(record) }
469469
existing_records = records.reject { |r| r.new_record? }
470470

471471
if existing_records.empty?
@@ -506,7 +506,7 @@ def concat_records(records)
506506
result = true
507507

508508
records.flatten.each do |record|
509-
raise_on_type_mismatch(record)
509+
raise_on_type_mismatch!(record)
510510
add_to_target(record) do |rec|
511511
result &&= insert_record(rec) unless owner.new_record?
512512
end

activerecord/lib/active_record/associations/has_many_through_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def size
2929
def concat(*records)
3030
unless owner.new_record?
3131
records.flatten.each do |record|
32-
raise_on_type_mismatch(record)
32+
raise_on_type_mismatch!(record)
3333
record.save! if record.new_record?
3434
end
3535
end

activerecord/lib/active_record/associations/has_one_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def handle_dependency
2222
end
2323

2424
def replace(record, save = true)
25-
raise_on_type_mismatch(record) if record
25+
raise_on_type_mismatch!(record) if record
2626
load_target
2727

2828
# If target and record are nil, or target is equal to record,

0 commit comments

Comments
 (0)