From 76c1528c5fd372af080081873b1ba02582c51f25 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Mon, 15 Apr 2019 19:40:38 +0530 Subject: Remove `required: true` from the model generator template `belongs_to` association have `required: true` by default https://github.com/rails/rails/pull/18937 onwards so we don't need it in the generator template. We still need the code for required in the command line generator as it adds `null: false` in the migration. --- railties/test/generators/model_generator_test.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index c97cd17ec6..1b86e509ee 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -414,23 +414,12 @@ class ModelGeneratorTest < Rails::Generators::TestCase end end - def test_required_belongs_to_adds_required_association - run_generator ["account", "supplier:references{required}"] - - expected_file = <<~FILE - class Account < ApplicationRecord - belongs_to :supplier, required: true - end - FILE - assert_file "app/models/account.rb", expected_file - end - def test_required_polymorphic_belongs_to_generages_correct_model run_generator ["account", "supplier:references{required,polymorphic}"] expected_file = <<~FILE class Account < ApplicationRecord - belongs_to :supplier, polymorphic: true, required: true + belongs_to :supplier, polymorphic: true end FILE assert_file "app/models/account.rb", expected_file @@ -441,7 +430,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase expected_file = <<~FILE class Account < ApplicationRecord - belongs_to :supplier, polymorphic: true, required: true + belongs_to :supplier, polymorphic: true end FILE assert_file "app/models/account.rb", expected_file -- cgit v1.2.3