aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/fixtures_test.rb
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2018-01-23 14:21:58 -0500
committerEdouard CHIN <edouard.chin@shopify.com>2018-01-23 14:21:58 -0500
commit1d04baafa6e79ec8892f9159784617dca8deea1e (patch)
tree673668afeeaacd9b0c4e46b3afcc687a127e029d /activerecord/test/cases/fixtures_test.rb
parent9a5b1fad630e4d35b64bb62b92c00e6cc79046d4 (diff)
downloadrails-1d04baafa6e79ec8892f9159784617dca8deea1e.tar.gz
rails-1d04baafa6e79ec8892f9159784617dca8deea1e.tar.bz2
rails-1d04baafa6e79ec8892f9159784617dca8deea1e.zip
Allow a 2 bytes margin:
- mysql will add a 2 bytes margin to the statement, so given a `max_allowed_packet` set to 1024 bytes, a 1024 bytes fixtures will no be inserted (mysql will throw an error) - Preventing this by decreasing the max_allowed_packet by 2 bytes when doing the comparison with the actual statement size
Diffstat (limited to 'activerecord/test/cases/fixtures_test.rb')
-rw-r--r--activerecord/test/cases/fixtures_test.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index 13034eef22..de5c96daaa 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -119,17 +119,19 @@ class FixturesTest < ActiveRecord::TestCase
if current_adapter?(:Mysql2Adapter)
def test_insert_fixtures_set_raises_an_error_when_max_allowed_packet_is_smaller_than_fixtures_set_size
conn = ActiveRecord::Base.connection
+ mysql_margin = 2
packet_size = 1024
+ bytes_needed_to_have_a_1024_bytes_fixture = 855
fixtures = {
"traffic_lights" => [
- { "location" => "US", "state" => ["NY"], "long_state" => ["a" * packet_size] },
+ { "location" => "US", "state" => ["NY"], "long_state" => ["a" * bytes_needed_to_have_a_1024_bytes_fixture] },
]
}
- conn.stubs(:max_allowed_packet).returns(packet_size)
+ conn.stubs(:max_allowed_packet).returns(packet_size - mysql_margin)
error = assert_raises(ActiveRecord::ActiveRecordError) { conn.insert_fixtures_set(fixtures) }
- assert_match(/Fixtures set is too large/, error.message)
+ assert_match(/Fixtures set is too large #{packet_size}\./, error.message)
end
def test_insert_fixture_set_when_max_allowed_packet_is_bigger_than_fixtures_set_size