aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/fixtures_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-26 12:42:28 +0900
committerGitHub <noreply@github.com>2018-01-26 12:42:28 +0900
commit8baca31dbe522cb407f0b3b8c8d3d4a6804e5aed (patch)
tree71408d810bd7b9dc6770f3eea70122d46c2a2bfe /activerecord/test/cases/fixtures_test.rb
parent301cd91c0d1bfb67344a963e0859e214753fcbfe (diff)
downloadrails-8baca31dbe522cb407f0b3b8c8d3d4a6804e5aed.tar.gz
rails-8baca31dbe522cb407f0b3b8c8d3d4a6804e5aed.tar.bz2
rails-8baca31dbe522cb407f0b3b8c8d3d4a6804e5aed.zip
Bring back ability to insert zero value on primary key for fixtures (#31795)
Since #29504, mysql2 adapter lost ability to insert zero value on primary key due to enforce `NO_AUTO_VALUE_ON_ZERO` disabled. That is for using `DEFAULT` on auto increment column, but we can use `NULL` instead in that case.
Diffstat (limited to 'activerecord/test/cases/fixtures_test.rb')
-rw-r--r--activerecord/test/cases/fixtures_test.rb31
1 files changed, 11 insertions, 20 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index baa5e5df34..34aaadcf7c 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -121,7 +121,7 @@ class FixturesTest < ActiveRecord::TestCase
conn = ActiveRecord::Base.connection
mysql_margin = 2
packet_size = 1024
- bytes_needed_to_have_a_1024_bytes_fixture = 855
+ bytes_needed_to_have_a_1024_bytes_fixture = 858
fixtures = {
"traffic_lights" => [
{ "location" => "US", "state" => ["NY"], "long_state" => ["a" * bytes_needed_to_have_a_1024_bytes_fixture] },
@@ -199,26 +199,17 @@ class FixturesTest < ActiveRecord::TestCase
end
end
- def test_no_auto_value_on_zero_is_disabled
- skip unless current_adapter?(:Mysql2Adapter)
-
- begin
- fixtures = [
- { "name" => "first", "wheels_count" => 2 },
- { "name" => "second", "wheels_count" => 3 }
- ]
- subscriber = InsertQuerySubscriber.new
- subscription = ActiveSupport::Notifications.subscribe("sql.active_record", subscriber)
-
- assert_nothing_raised do
- ActiveRecord::Base.connection.insert_fixtures_set("aircraft" => fixtures)
- end
-
- expected_sql = "INSERT INTO `aircraft` (`id`, `name`, `wheels_count`) VALUES (DEFAULT, 'first', 2), (DEFAULT, 'second', 3);\n"
- assert_equal expected_sql, subscriber.events.first
- ensure
- ActiveSupport::Notifications.unsubscribe(subscription)
+ def test_auto_value_on_primary_key
+ fixtures = [
+ { "name" => "first", "wheels_count" => 2 },
+ { "name" => "second", "wheels_count" => 3 }
+ ]
+ conn = ActiveRecord::Base.connection
+ assert_nothing_raised do
+ conn.insert_fixtures_set({ "aircraft" => fixtures }, ["aircraft"])
end
+ result = conn.select_all("SELECT name, wheels_count FROM aircraft ORDER BY id")
+ assert_equal fixtures, result.to_a
end
def test_deprecated_insert_fixtures