diff options
Diffstat (limited to 'railties/test/generators/plugin_generator_test.rb')
-rw-r--r-- | railties/test/generators/plugin_generator_test.rb | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index e8372dea47..cf581ce891 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -97,23 +97,44 @@ class PluginGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "-T", "--full"] assert_no_directory "test/integration/" - assert_no_file "test" + assert_no_directory "test" assert_file "Rakefile" do |contents| assert_no_match(/APP_RAKEFILE/, contents) end + assert_file "bin/rails" do |contents| + assert_no_match(/APP_PATH/, contents) + end end - def test_generating_adds_dummy_app_in_full_mode_without_sprockets - run_generator [destination_root, "-S", "--full"] + 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/production.rb" do |contents| - assert_no_match(/config\.assets/, contents) + 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/ + assert_file "bin/rails", /APP_PATH/ end def test_generating_adds_dummy_app_without_javascript_and_assets_deps @@ -134,8 +155,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_ensure_that_test_dummy_can_be_generated_from_a_template FileUtils.cd(Rails.root) run_generator([destination_root, "-m", "lib/create_test_dummy_template.rb", "--skip-test"]) - assert_file "spec/dummy" - assert_no_file "test" + assert_directory "spec/dummy" + assert_no_directory "test" end def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode @@ -169,9 +190,19 @@ class PluginGeneratorTest < Rails::Generators::TestCase 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["']/ @@ -197,6 +228,18 @@ class PluginGeneratorTest < Rails::Generators::TestCase 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 @@ -255,7 +298,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--full", "--skip_active_record"] FileUtils.cd destination_root quietly { system "bundle install" } - assert_match(/1 runs, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`) + # FIXME: Active Storage will provoke a test error without ActiveRecord (fix by allowing to skip active storage) + assert_match(/1 runs, 0 assertions, 0 failures, 1 errors/, `bundle exec rake test 2>&1`) end def test_ensure_that_migration_tasks_work_with_mountable_option @@ -458,10 +502,9 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_creating_dummy_without_tests_but_with_dummy_path run_generator [destination_root, "--dummy_path", "spec/dummy", "--skip-test"] - assert_file "spec/dummy" - assert_file "spec/dummy/config/application.rb" - assert_no_file "test" - assert_no_file "test/test_helper.rb" + assert_directory "spec/dummy" + assert_file "spec/dummy/config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + assert_no_directory "test" assert_file ".gitignore" do |contents| assert_match(/spec\/dummy/, contents) end @@ -491,7 +534,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_file "test/dummy/public/robots.txt" assert_no_file "test/dummy/README.md" assert_no_directory "test/dummy/lib/tasks" - assert_no_directory "test/dummy/doc" assert_no_directory "test/dummy/test" assert_no_directory "test/dummy/vendor" assert_no_directory "test/dummy/.git" @@ -499,9 +541,9 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_skipping_test_files run_generator [destination_root, "--skip-test"] - assert_no_file "test" + assert_no_directory "test" assert_file ".gitignore" do |contents| - assert_no_match(/test\dummy/, contents) + assert_no_match(/test\/dummy/, contents) end end |