diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2013-06-21 20:59:04 +0530 |
---|---|---|
committer | Neeraj Singh <neerajdotname@gmail.com> | 2013-06-21 23:27:28 +0530 |
commit | 6741a0a18761ca9cbbdaeefe70f4d53d68fdf1b5 (patch) | |
tree | 375a468d351565f68f5b5b3584c350e27519f0fc | |
parent | c5fc38d2fdd180d26ebda7c24e8fb3dc1eec17fd (diff) | |
download | rails-6741a0a18761ca9cbbdaeefe70f4d53d68fdf1b5.tar.gz rails-6741a0a18761ca9cbbdaeefe70f4d53d68fdf1b5.tar.bz2 rails-6741a0a18761ca9cbbdaeefe70f4d53d68fdf1b5.zip |
fix bad test by making number that fits for integer
PR https://github.com/rails/rails/pull/10566 had to be reverted
because after applying the fix test
"test_raise_record_not_found_error_when_invalid_ids_are_passed"
started failing.
In this test invalid_id is being assigned a really large number
which was causing following failure when PR #10566 was applied.
```
RangeError: bignum too big to convert into `long long'
SELECT `interests`.* FROM `interests`
WHERE `interests`.`man_id` = ? AND `interests`.`id` = ?
LIMIT 1 [["man_id", 970345987], ["id", 2394823094892348920348523452345]]
```
This test is not failing in master because when test code
`man.interests.find(invalid_id)` is executed then interests
are fully loaded in memory and no database query is executed.
After PR #10566 was merged then test code
`man.interests.find(invalid_id)` started executing sql query
and hence the error.
In case someone is wondering why the second part of query is not
failing, then that's because the actual query does not require
any variable substituation where the number is large. In that
case the sql generate is following.
```
SELECT `interests`.* FROM `interests`
WHERE `interests`.`man_id` = ? AND `interests`.`id`
IN (8432342, 2390102913, 2453245234523452) [["man_id", 970345987]]
```
-rw-r--r-- | activerecord/test/cases/associations/inverse_associations_test.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index b1f0be3204..d961ceca1d 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -402,9 +402,13 @@ class InverseHasManyTests < ActiveRecord::TestCase end def test_raise_record_not_found_error_when_invalid_ids_are_passed + # delete all interest records to ensure that hard coded invalid_id(s) + # are indeed invalid. + Interest.delete_all + man = Man.create! - invalid_id = 2394823094892348920348523452345 + invalid_id = 245324523 assert_raise(ActiveRecord::RecordNotFound) { man.interests.find(invalid_id) } invalid_ids = [8432342, 2390102913, 2453245234523452] |