1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #30274 from bogdanvlviv/dry-in-generators-tests

Move common tests to `SharedGeneratorTests`
This commit is contained in:
Rafael França 2017-08-17 15:20:41 -04:00 committed by GitHub
commit 46a366e7f2
5 changed files with 118 additions and 200 deletions

View file

@ -2,8 +2,10 @@
log/*.log
pkg/
<% if with_dummy_app? -%>
<% if sqlite3? -%>
<%= dummy_path %>/db/*.sqlite3
<%= dummy_path %>/db/*.sqlite3-journal
<% end -%>
<%= dummy_path %>/log/*.log
<% unless options[:skip_yarn] -%>
<%= dummy_path %>/node_modules/

View file

@ -17,6 +17,7 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
Rails::TestUnitReporter.executable = 'bin/test'
<% end -%>
<% unless options[:skip_active_record] -%>
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
@ -24,3 +25,4 @@ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
ActiveSupport::TestCase.fixtures :all
end
<% end -%>

View file

@ -381,31 +381,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_generator_without_skips
run_generator
assert_file "config/application.rb", /\s+require\s+["']rails\/all["']/
assert_file "config/environments/development.rb" do |content|
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
end
assert_file "config/environments/test.rb" do |content|
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
assert_match(/^ config\.read_encrypted_secrets = true/, content)
end
end
def test_default_frameworks_are_required_when_others_are_removed
run_generator [destination_root, "--skip-active-record", "--skip-action-mailer", "--skip-action-cable", "--skip-sprockets", "--skip-test"]
assert_file "config/application.rb", /require\s+["']rails["']/
assert_file "config/application.rb", /require\s+["']active_model\/railtie["']/
assert_file "config/application.rb", /require\s+["']active_job\/railtie["']/
assert_file "config/application.rb", /require\s+["']action_controller\/railtie["']/
assert_file "config/application.rb", /require\s+["']action_view\/railtie["']/
assert_file "config/application.rb", /require\s+["']active_storage\/engine["']/
end
def test_generator_defaults_to_puma_version
run_generator [destination_root]
assert_gem "puma", "'~> 3.7'"
@ -419,39 +394,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_no_directory "db/"
assert_no_file "config/database.yml"
assert_no_file "app/models/application_record.rb"
assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
assert_file "test/test_helper.rb" do |helper_content|
assert_no_match(/fixtures :all/, helper_content)
end
assert_file "bin/setup" do |setup_content|
assert_no_match(/db:setup/, setup_content)
end
assert_file "bin/update" do |update_content|
assert_no_match(/db:migrate/, update_content)
end
end
def test_generator_if_skip_action_mailer_is_given
run_generator [destination_root, "--skip-action-mailer"]
assert_file "config/application.rb", /#\s+require\s+["']action_mailer\/railtie["']/
assert_file "config/environments/development.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "config/environments/test.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_no_directory "app/mailers"
assert_no_directory "test/mailers"
end
def test_generator_has_assets_gems
run_generator
@ -459,43 +401,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_gem "uglifier"
end
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
assert_no_file "config/initializers/assets.rb"
assert_file "config/application.rb", /#\s+require\s+["']sprockets\/railtie["']/
assert_file "Gemfile" do |content|
assert_no_match(/sass-rails/, content)
assert_no_match(/uglifier/, content)
assert_no_match(/coffee-rails/, content)
end
assert_file "config/environments/development.rb" do |content|
assert_no_match(/config\.assets\.debug/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_no_match(/config\.assets\.digest/, content)
assert_no_match(/config\.assets\.js_compressor/, content)
assert_no_match(/config\.assets\.css_compressor/, content)
assert_no_match(/config\.assets\.compile/, content)
end
end
def test_generator_if_skip_action_cable_is_given
run_generator [destination_root, "--skip-action-cable"]
assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/
assert_no_file "config/cable.yml"
assert_no_file "app/assets/javascripts/cable.js"
assert_no_directory "app/assets/javascripts/channels"
assert_no_directory "app/channels"
assert_file "Gemfile" do |content|
assert_no_match(/redis/, content)
end
end
def test_action_cable_redis_gems
run_generator
assert_file "Gemfile", /^# gem 'redis'/
@ -770,30 +675,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_gitignore_when_sqlite3
run_generator
assert_file ".gitignore" do |content|
assert_match(/sqlite3/, content)
end
end
def test_gitignore_when_no_active_record
run_generator [destination_root, "--skip-active-record"]
assert_file ".gitignore" do |content|
assert_no_match(/sqlite/i, content)
end
end
def test_gitignore_when_non_sqlite3_db
run_generator([destination_root, "-d", "mysql"])
assert_file ".gitignore" do |content|
assert_no_match(/sqlite/i, content)
end
end
def test_inclusion_of_ruby_version
run_generator

View file

@ -129,31 +129,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
def test_generating_adds_dummy_app_without_sprockets
run_generator [destination_root, "--skip-sprockets"]
assert_no_file "test/dummy/config/initializers/assets.rb"
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']sprockets\/railtie["']/
assert_file "Gemfile" do |content|
assert_no_match(/sass-rails/, content)
assert_no_match(/uglifier/, content)
assert_no_match(/coffee-rails/, content)
end
assert_file "test/dummy/config/environments/development.rb" do |content|
assert_no_match(/config\.assets\.debug/, content)
end
assert_file "test/dummy/config/environments/production.rb" do |content|
assert_no_match(/config\.assets\.digest/, content)
assert_no_match(/config\.assets\.js_compressor/, content)
assert_no_match(/config\.assets\.css_compressor/, content)
assert_no_match(/config\.assets\.compile/, content)
end
end
def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
run_generator [destination_root, "-T", "--mountable", "--dummy-path", "my_dummy_app"]
assert_file "Rakefile", /APP_RAKEFILE/
@ -202,69 +177,13 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
def test_app_generator_without_skips
run_generator
assert_file "test/dummy/config/application.rb", /\s+require\s+["']rails\/all["']/
assert_file "test/dummy/config/environments/development.rb" do |content|
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
end
assert_file "test/dummy/config/environments/test.rb" do |content|
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
end
assert_file "test/dummy/config/environments/production.rb" do |content|
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
assert_match(/^ config\.read_encrypted_secrets = true/, content)
end
end
def test_default_frameworks_are_required_when_others_are_removed
run_generator [destination_root, "--skip-active-record", "--skip-action-mailer", "--skip-action-cable", "--skip-sprockets"]
assert_file "test/dummy/config/application.rb", /require\s+["']rails["']/
assert_file "test/dummy/config/application.rb", /require\s+["']active_model\/railtie["']/
assert_file "test/dummy/config/application.rb", /require\s+["']active_job\/railtie["']/
assert_file "test/dummy/config/application.rb", /require\s+["']action_controller\/railtie["']/
assert_file "test/dummy/config/application.rb", /require\s+["']action_view\/railtie["']/
end
def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
end
def test_ensure_that_skip_active_record_option_is_passed_to_app_generator
run_generator [destination_root, "--skip_active_record"]
assert_no_file "test/dummy/config/database.yml"
assert_file "test/test_helper.rb" do |contents|
assert_no_match(/ActiveRecord/, contents)
end
end
def test_action_mailer_is_removed_from_frameworks_if_skip_action_mailer_is_given
run_generator [destination_root, "--skip-action-mailer"]
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']action_mailer\/railtie["']/
assert_file "test/dummy/config/environments/development.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "test/dummy/config/environments/test.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "test/dummy/config/environments/production.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_no_directory "test/dummy/app/mailers"
end
def test_action_cable_is_removed_from_frameworks_if_skip_action_cable_is_given
run_generator [destination_root, "--skip-action-cable"]
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']action_cable\/engine["']/
assert_no_file "test/dummy/config/cable.yml"
assert_no_file "test/dummy/app/assets/javascripts/cable.js"
assert_no_directory "test/dummy/app/channels"
assert_file "Gemfile" do |content|
assert_no_match(/redis/, content)
end
end
def test_ensure_that_database_option_is_passed_to_app_generator
run_generator [destination_root, "--database", "postgresql"]
assert_file "test/dummy/config/database.yml", /postgres/

View file

@ -128,6 +128,120 @@ module SharedGeneratorTests
assert_no_file("app/models/concerns/.keep")
end
def test_default_frameworks_are_required_when_others_are_removed
run_generator [destination_root, "--skip-active-record", "--skip-action-mailer", "--skip-action-cable", "--skip-sprockets"]
assert_file "#{application_path}/config/application.rb", /require\s+["']rails["']/
assert_file "#{application_path}/config/application.rb", /require\s+["']active_model\/railtie["']/
assert_file "#{application_path}/config/application.rb", /require\s+["']active_job\/railtie["']/
assert_file "#{application_path}/config/application.rb", /require\s+["']action_controller\/railtie["']/
assert_file "#{application_path}/config/application.rb", /require\s+["']action_view\/railtie["']/
assert_file "#{application_path}/config/application.rb", /require\s+["']active_storage\/engine["']/
end
def test_generator_without_skips
run_generator
assert_file "#{application_path}/config/application.rb", /\s+require\s+["']rails\/all["']/
assert_file "#{application_path}/config/environments/development.rb" do |content|
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
end
assert_file "#{application_path}/config/environments/test.rb" do |content|
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
end
assert_file "#{application_path}/config/environments/production.rb" do |content|
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
assert_match(/^ config\.read_encrypted_secrets = true/, content)
end
end
def test_gitignore_when_sqlite3
run_generator
assert_file ".gitignore" do |content|
assert_match(/sqlite3/, content)
end
end
def test_gitignore_when_non_sqlite3_db
run_generator([destination_root, "-d", "mysql"])
assert_file ".gitignore" do |content|
assert_no_match(/sqlite/i, content)
end
end
def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_no_directory "#{application_path}/db/"
assert_no_file "#{application_path}/config/database.yml"
assert_no_file "#{application_path}/app/models/application_record.rb"
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
assert_file "test/test_helper.rb" do |helper_content|
assert_no_match(/fixtures :all/, helper_content)
end
assert_file "#{application_path}/bin/setup" do |setup_content|
assert_no_match(/db:setup/, setup_content)
end
assert_file "#{application_path}/bin/update" do |update_content|
assert_no_match(/db:migrate/, update_content)
end
assert_file ".gitignore" do |content|
assert_no_match(/sqlite/i, content)
end
end
def test_generator_if_skip_action_mailer_is_given
run_generator [destination_root, "--skip-action-mailer"]
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailer\/railtie["']/
assert_file "#{application_path}/config/environments/development.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "#{application_path}/config/environments/test.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "#{application_path}/config/environments/production.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_no_directory "#{application_path}/app/mailers"
assert_no_directory "#{application_path}/test/mailers"
end
def test_generator_if_skip_action_cable_is_given
run_generator [destination_root, "--skip-action-cable"]
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_cable\/engine["']/
assert_no_file "#{application_path}/config/cable.yml"
assert_no_file "#{application_path}/app/assets/javascripts/cable.js"
assert_no_directory "#{application_path}/app/assets/javascripts/channels"
assert_no_directory "#{application_path}/app/channels"
assert_file "Gemfile" do |content|
assert_no_match(/redis/, content)
end
end
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
assert_no_file "#{application_path}/config/initializers/assets.rb"
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']sprockets\/railtie["']/
assert_file "Gemfile" do |content|
assert_no_match(/sass-rails/, content)
assert_no_match(/uglifier/, content)
assert_no_match(/coffee-rails/, content)
end
assert_file "#{application_path}/config/environments/development.rb" do |content|
assert_no_match(/config\.assets\.debug/, content)
end
assert_file "#{application_path}/config/environments/production.rb" do |content|
assert_no_match(/config\.assets\.digest/, content)
assert_no_match(/config\.assets\.js_compressor/, content)
assert_no_match(/config\.assets\.css_compressor/, content)
assert_no_match(/config\.assets\.compile/, content)
end
end
def test_generator_for_yarn
run_generator
assert_file "#{application_path}/package.json", /dependencies/