Skip to content

Commit c278684

Browse files
committed
Assert exact file output for plugins too
In a [previous commit][1], the App Generator skeleton test was updated to verify the exact file output when generating a new application. This commit applies the same change to the Plugin Generator. At first, I was hesitant to add the list of dummy app files to the `default_files` for the Plugin Generator test, however it quickly became apparent that it was a good idea. Making this change exposed that recent file additions to the App Generator were added to the plugin's dummy app as well. Things like CI files, rubocop configuration, and a brakeman command should not be created for a dummy app, and are now properly excluded. Similar to the App Generator commit, this change also removes tests that are now redundant due to the skeleton test verifying the exact list of files generated. [1]: e5e4b80
1 parent e5e4b80 commit c278684

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

railties/lib/rails/generators/rails/plugin/plugin_generator.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ def test
112112
def generate_test_dummy(force = false)
113113
opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
114114
opts[:force] = force
115+
opts[:skip_brakeman] = true
115116
opts[:skip_bundle] = true
117+
opts[:skip_ci] = true
116118
opts[:skip_git] = true
117119
opts[:skip_hotwire] = true
120+
opts[:skip_rubocop] = true
118121
opts[:dummy_app] = true
119122

120123
invoke Rails::Generators::AppGenerator,
@@ -144,7 +147,7 @@ def test_dummy_sprocket_assets
144147
def test_dummy_clean
145148
inside dummy_path do
146149
remove_file ".ruby-version"
147-
remove_file "db/seeds.rb"
150+
remove_dir "db"
148151
remove_file "Gemfile"
149152
remove_file "lib/tasks"
150153
remove_file "public/robots.txt"

railties/test/generators/plugin_generator_test.rb

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,70 @@
77
require "rails/engine/updater"
88

99
DEFAULT_PLUGIN_FILES = %w(
10+
.git
1011
.gitignore
1112
Gemfile
12-
Rakefile
13+
MIT-LICENSE
1314
README.md
15+
Rakefile
16+
bin/test
1417
bukkits.gemspec
15-
MIT-LICENSE
16-
lib
1718
lib/bukkits.rb
18-
lib/tasks/bukkits_tasks.rake
19+
lib/bukkits/railtie.rb
1920
lib/bukkits/version.rb
21+
lib/tasks/bukkits_tasks.rake
2022
test/bukkits_test.rb
23+
test/dummy/Rakefile
24+
test/dummy/app/assets/images/.keep
25+
test/dummy/app/assets/stylesheets/application.css
26+
test/dummy/app/channels/application_cable/channel.rb
27+
test/dummy/app/channels/application_cable/connection.rb
28+
test/dummy/app/controllers/application_controller.rb
29+
test/dummy/app/controllers/concerns/.keep
30+
test/dummy/app/helpers/application_helper.rb
31+
test/dummy/app/jobs/application_job.rb
32+
test/dummy/app/mailers/application_mailer.rb
33+
test/dummy/app/models/application_record.rb
34+
test/dummy/app/models/concerns/.keep
35+
test/dummy/app/views/layouts/application.html.erb
36+
test/dummy/app/views/layouts/mailer.html.erb
37+
test/dummy/app/views/layouts/mailer.text.erb
38+
test/dummy/app/views/pwa/manifest.json.erb
39+
test/dummy/app/views/pwa/service-worker.js
40+
test/dummy/bin/rails
41+
test/dummy/bin/rake
42+
test/dummy/bin/setup
43+
test/dummy/config.ru
44+
test/dummy/config/application.rb
45+
test/dummy/config/boot.rb
46+
test/dummy/config/cable.yml
47+
test/dummy/config/database.yml
48+
test/dummy/config/environment.rb
49+
test/dummy/config/environments/development.rb
50+
test/dummy/config/environments/production.rb
51+
test/dummy/config/environments/test.rb
52+
test/dummy/config/initializers/content_security_policy.rb
53+
test/dummy/config/initializers/enable_yjit.rb
54+
test/dummy/config/initializers/filter_parameter_logging.rb
55+
test/dummy/config/initializers/inflections.rb
56+
test/dummy/config/initializers/permissions_policy.rb
57+
test/dummy/config/locales/en.yml
58+
test/dummy/config/puma.rb
59+
test/dummy/config/routes.rb
60+
test/dummy/config/storage.yml
61+
test/dummy/lib/assets/.keep
62+
test/dummy/log/.keep
63+
test/dummy/public/404.html
64+
test/dummy/public/422.html
65+
test/dummy/public/426.html
66+
test/dummy/public/500.html
67+
test/dummy/public/icon.png
68+
test/dummy/public/icon.svg
69+
test/dummy/storage/.keep
70+
test/dummy/tmp/.keep
71+
test/dummy/tmp/pids/.keep
72+
test/dummy/tmp/storage/.keep
2173
test/test_helper.rb
22-
test/dummy
2374
)
2475

2576
class PluginGeneratorTest < Rails::Generators::TestCase
@@ -68,8 +119,6 @@ def test_correct_file_in_lib_folder_of_camelcase_plugin_name
68119
def test_generating_without_options
69120
run_generator
70121
assert_file "README.md", /Bukkits/
71-
assert_no_file "config/routes.rb"
72-
assert_no_file "app/assets/config/bukkits_manifest.js"
73122
assert_file "test/test_helper.rb" do |content|
74123
assert_match(/require_relative.+test\/dummy\/config\/environment/, content)
75124
assert_match(/ActiveRecord::Migrator\.migrations_paths.+test\/dummy\/db\/migrate/, content)
@@ -83,13 +132,6 @@ def test_generating_without_options
83132
assert_match(/class BukkitsTest < ActiveSupport::TestCase/, content)
84133
assert_match(/assert Bukkits::VERSION/, content)
85134
end
86-
assert_file "bin/test"
87-
assert_no_file "bin/rails"
88-
end
89-
90-
def test_initializes_git_repo
91-
run_generator
92-
assert_directory ".git"
93135
end
94136

95137
def test_initializes_git_repo_with_main_branch_without_user_default
@@ -176,12 +218,6 @@ def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
176218
assert_file "bin/rails", /APP_PATH/
177219
end
178220

179-
def test_generating_adds_dummy_app_without_javascript_and_assets_deps
180-
run_generator
181-
182-
assert_file "test/dummy/app/assets/stylesheets/application.css"
183-
end
184-
185221
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
186222
FileUtils.cd(fixtures_root)
187223
assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]))
@@ -608,24 +644,6 @@ def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path
608644
end
609645
end
610646

611-
def test_unnecessary_files_are_not_generated_in_dummy_application
612-
run_generator
613-
assert_no_file "test/dummy/.gitignore"
614-
assert_no_file "test/dummy/.ruby-version"
615-
assert_no_file "test/dummy/db/seeds.rb"
616-
assert_no_file "test/dummy/Gemfile"
617-
assert_no_file "test/dummy/public/robots.txt"
618-
assert_no_file "test/dummy/README.md"
619-
assert_no_file "test/dummy/config/master.key"
620-
assert_no_file "test/dummy/config/credentials.yml.enc"
621-
assert_no_file "test/dummy/Dockerfile"
622-
assert_no_file "test/dummy/.dockerignore"
623-
assert_no_directory "test/dummy/lib/tasks"
624-
assert_no_directory "test/dummy/test"
625-
assert_no_directory "test/dummy/vendor"
626-
assert_no_directory "test/dummy/.git"
627-
end
628-
629647
def test_skipping_test_files
630648
run_generator [destination_root, "--skip-test"]
631649
assert_no_directory "test"

0 commit comments

Comments
 (0)