aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-12-10 06:21:55 -0500
committerGitHub <noreply@github.com>2016-12-10 06:21:55 -0500
commit753da21322a2701f8b2294da1c26df8a783436d5 (patch)
treef45d2818358562b4336d677e71541cc033411d73 /activerecord/test
parent2e8dad6318f06d2b41be3b3dd50b8bb112d2d200 (diff)
parent0da4a08bdfea28a0cc881ca5831aadfcf8a3b7eb (diff)
downloadrails-753da21322a2701f8b2294da1c26df8a783436d5.tar.gz
rails-753da21322a2701f8b2294da1c26df8a783436d5.tar.bz2
rails-753da21322a2701f8b2294da1c26df8a783436d5.zip
Merge pull request #25280 from kamipo/prevent_range_error_for_belongs_to_associations
Prevent `RangeError` for `belongs_to` associations
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 72f1b3b125..2b8d01743f 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -1072,6 +1072,20 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal 1, parent.reload.children_count
end
+ def test_belongs_to_with_out_of_range_value_assigning
+ model = Class.new(Comment) do
+ def self.name; "Temp"; end
+ validates :post, presence: true
+ end
+
+ comment = model.new
+ comment.post_id = 10_000_000_000
+
+ assert_nil comment.post
+ assert_not comment.valid?
+ assert_equal [{ error: :blank }], comment.errors.details[:post]
+ end
+
def test_polymorphic_with_custom_primary_key
toy = Toy.create!
sponsor = Sponsor.create!(sponsorable: toy)