2016-08-06 13:16:09 -04:00
require " generators/generators_test_helper "
require " rails/generators/rails/plugin/plugin_generator "
require " generators/shared_generator_tests "
2017-01-16 08:27:51 -05:00
require " rails/engine/updater "
2010-10-15 10:46:31 -04:00
DEFAULT_PLUGIN_FILES = %w(
. gitignore
Gemfile
Rakefile
2015-10-25 20:01:51 -04:00
README . md
2010-10-15 10:46:31 -04:00
bukkits . gemspec
MIT - LICENSE
lib
lib / bukkits . rb
2010-11-02 10:44:07 -04:00
lib / tasks / bukkits_tasks . rake
2011-07-29 13:35:40 -04:00
lib / bukkits / version . rb
2010-10-15 10:46:31 -04:00
test / bukkits_test . rb
test / test_helper . rb
test / dummy
)
2013-06-30 17:02:19 -04:00
class PluginGeneratorTest < Rails :: Generators :: TestCase
2010-10-15 10:46:31 -04:00
include GeneratorsTestHelper
destination File . join ( Rails . root , " tmp/bukkits " )
arguments [ destination_root ]
2011-05-06 18:11:13 -04:00
# brings setup, teardown, and some tests
2010-10-20 18:55:08 -04:00
include SharedGeneratorTests
2010-10-15 10:46:31 -04:00
def test_invalid_plugin_name_raises_an_error
2016-08-16 03:30:11 -04:00
content = capture ( :stderr ) { run_generator [ File . join ( destination_root , " my_plugin-31fr-extension " ) ] }
2014-01-05 14:41:16 -05:00
assert_equal " Invalid plugin name my_plugin-31fr-extension. Please give a name which does not contain a namespace starting with numeric characters. \n " , content
2012-01-30 08:47:05 -05:00
2016-08-16 03:30:11 -04:00
content = capture ( :stderr ) { run_generator [ File . join ( destination_root , " things4.3 " ) ] }
2014-01-05 14:41:16 -05:00
assert_equal " Invalid plugin name things4.3. Please give a name which uses only alphabetic, numeric, \" _ \" or \" - \" characters. \n " , content
2012-05-01 22:29:56 -04:00
2016-08-16 03:30:11 -04:00
content = capture ( :stderr ) { run_generator [ File . join ( destination_root , " 43things " ) ] }
2012-01-30 08:47:05 -05:00
assert_equal " Invalid plugin name 43things. Please give a name which does not start with numbers. \n " , content
2014-01-05 15:48:05 -05:00
2016-08-16 03:30:11 -04:00
content = capture ( :stderr ) { run_generator [ File . join ( destination_root , " plugin " ) ] }
2015-07-01 10:58:42 -04:00
assert_equal " Invalid plugin name plugin. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test \n " , content
2014-01-05 15:48:05 -05:00
2016-08-16 03:30:11 -04:00
content = capture ( :stderr ) { run_generator [ File . join ( destination_root , " Digest " ) ] }
2014-01-05 15:48:05 -05:00
assert_equal " Invalid plugin name Digest, constant Digest is already in use. Please choose another plugin name. \n " , content
2010-10-15 10:46:31 -04:00
end
2014-01-05 14:41:16 -05:00
def test_correct_file_in_lib_folder_of_hyphenated_plugin_name
run_generator [ File . join ( destination_root , " hyphenated-name " ) ]
assert_no_file " hyphenated-name/lib/hyphenated-name.rb "
assert_no_file " hyphenated-name/lib/hyphenated_name.rb "
2017-05-06 15:08:58 -04:00
assert_file " hyphenated-name/lib/hyphenated/name.rb " , / module Hyphenated \ n module Name \ n # Your code goes here \ . \ . \ . \ n end \ nend /
2014-01-05 14:41:16 -05:00
end
def test_correct_file_in_lib_folder_of_camelcase_plugin_name
2011-11-19 12:03:44 -05:00
run_generator [ File . join ( destination_root , " CamelCasedName " ) ]
assert_no_file " CamelCasedName/lib/CamelCasedName.rb "
assert_file " CamelCasedName/lib/camel_cased_name.rb " , / module CamelCasedName /
end
2011-01-14 20:32:40 -05:00
def test_generating_without_options
2010-10-15 10:46:31 -04:00
run_generator
2015-10-25 20:01:51 -04:00
assert_file " README.md " , / Bukkits /
2011-01-14 20:32:40 -05:00
assert_no_file " config/routes.rb "
2015-10-12 01:39:53 -04:00
assert_no_file " app/assets/config/bukkits_manifest.js "
2014-09-16 22:42:04 -04:00
assert_file " test/test_helper.rb " do | content |
2017-06-11 08:59:23 -04:00
assert_match ( / require_relative.+test \/ dummy \/ config \/ environment / , content )
2014-09-16 22:42:04 -04:00
assert_match ( / ActiveRecord::Migrator \ .migrations_paths.+test \/ dummy \/ db \/ migrate / , content )
2014-12-01 12:31:06 -05:00
assert_match ( / Minitest \ .backtrace_filter = Minitest::BacktraceFilter \ .new / , content )
2015-11-16 18:49:46 -05:00
assert_match ( / Rails::TestUnitReporter \ .executable = 'bin \/ test' / , content )
2014-09-16 22:42:04 -04:00
end
2017-06-26 00:01:54 -04:00
assert_file " lib/bukkits/railtie.rb " , / module Bukkits \ n class Railtie < ::Rails::Railtie \ n end \ nend /
assert_file " lib/bukkits.rb " , / require "bukkits \/ railtie" /
2010-10-15 10:46:31 -04:00
assert_file " test/bukkits_test.rb " , / assert_kind_of Module, Bukkits /
2016-08-06 13:16:09 -04:00
assert_file " bin/test "
assert_no_file " bin/rails "
2010-10-15 10:46:31 -04:00
end
2017-08-07 07:46:14 -04:00
def test_generating_in_full_mode_with_almost_of_all_skip_options
run_generator [ destination_root , " --full " , " -M " , " -O " , " -C " , " -S " , " -T " ]
assert_file " bin/rails " do | content |
assert_no_match ( / \ s+require \ s+["']rails \/ all["'] / , content )
end
assert_file " bin/rails " , / # \ s+require \ s+["']active_record \/ railtie["'] /
assert_file " bin/rails " , / # \ s+require \ s+["']action_mailer \/ railtie["'] /
assert_file " bin/rails " , / # \ s+require \ s+["']action_cable \/ engine["'] /
assert_file " bin/rails " , / # \ s+require \ s+["']sprockets \/ railtie["'] /
assert_file " bin/rails " , / # \ s+require \ s+["']rails \/ test_unit \/ railtie["'] /
end
2010-10-26 16:22:15 -04:00
def test_generating_test_files_in_full_mode
run_generator [ destination_root , " --full " ]
assert_directory " test/integration/ "
2010-11-02 09:05:11 -04:00
assert_file " test/integration/navigation_test.rb " , / ActionDispatch::IntegrationTest /
2010-10-26 16:22:15 -04:00
end
2017-08-07 05:10:31 -04:00
def test_inclusion_of_git_source
run_generator [ destination_root ]
assert_file " Gemfile " , / git_source /
end
2014-04-08 14:57:12 -04:00
def test_inclusion_of_a_debugger
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --full " ]
2014-12-22 15:43:58 -05:00
if defined? ( JRUBY_VERSION ) || RUBY_ENGINE == " rbx "
2013-12-06 10:48:28 -05:00
assert_file " Gemfile " do | content |
2014-04-08 14:57:12 -04:00
assert_no_match ( / byebug / , content )
2013-12-06 10:48:28 -05:00
end
2014-04-08 14:57:12 -04:00
else
assert_file " Gemfile " , / # gem 'byebug' /
2013-12-06 10:48:28 -05:00
end
end
2012-06-08 08:59:23 -04:00
def test_generating_test_files_in_full_mode_without_unit_test_files
run_generator [ destination_root , " -T " , " --full " ]
assert_no_directory " test/integration/ "
2017-08-09 10:05:21 -04:00
assert_no_directory " test "
2013-02-28 14:09:04 -05:00
assert_file " Rakefile " do | contents |
assert_no_match ( / APP_RAKEFILE / , contents )
end
2017-08-06 02:07:46 -04:00
assert_file " bin/rails " do | contents |
assert_no_match ( / APP_PATH / , contents )
end
2012-06-08 08:59:23 -04:00
end
2017-08-09 10:05:21 -04:00
def test_generating_adds_dummy_app_without_sprockets
run_generator [ destination_root , " --skip-sprockets " ]
2016-11-14 04:09:26 -05:00
2017-08-09 10:05:21 -04:00
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 )
2016-11-14 04:09:26 -05:00
end
end
2012-11-07 14:54:49 -05:00
def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " -T " , " --mountable " , " --dummy-path " , " my_dummy_app " ]
2013-02-28 14:09:04 -05:00
assert_file " Rakefile " , / APP_RAKEFILE /
2017-08-06 02:07:46 -04:00
assert_file " bin/rails " , / APP_PATH /
2013-02-28 14:09:04 -05:00
end
def test_generating_adds_dummy_app_without_javascript_and_assets_deps
2014-07-30 22:13:59 -04:00
run_generator
2012-11-07 14:54:49 -05:00
2013-02-28 14:09:04 -05:00
assert_file " test/dummy/app/assets/stylesheets/application.css "
assert_file " test/dummy/app/assets/javascripts/application.js " do | contents |
assert_no_match ( / jquery / , contents )
end
2012-11-07 14:54:49 -05:00
end
2010-10-23 14:56:02 -04:00
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
FileUtils . cd ( Rails . root )
2011-03-12 19:01:12 -05:00
assert_no_match ( / It works from file!.*It works_from_file / , run_generator ( [ destination_root , " -m " , " lib/template.rb " ] ) )
2010-10-19 18:47:13 -04:00
end
2010-11-02 10:13:10 -04:00
def test_ensure_that_test_dummy_can_be_generated_from_a_template
FileUtils . cd ( Rails . root )
2015-01-27 17:59:48 -05:00
run_generator ( [ destination_root , " -m " , " lib/create_test_dummy_template.rb " , " --skip-test " ] )
2017-08-09 10:05:21 -04:00
assert_directory " spec/dummy "
assert_no_directory " test "
2010-11-02 10:13:10 -04:00
end
2011-06-13 04:34:09 -04:00
def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode
2010-11-02 09:23:45 -04:00
run_generator ( [ destination_root , " --full " ] )
assert_file " test/dummy/config/database.yml " , / sqlite /
2011-07-28 11:44:29 -04:00
assert_file " bukkits.gemspec " , / sqlite3 /
2010-11-02 09:23:45 -04:00
end
def test_config_another_database
run_generator ( [ destination_root , " -d " , " mysql " , " --full " ] )
assert_file " test/dummy/config/database.yml " , / mysql /
2011-07-28 11:44:29 -04:00
assert_file " bukkits.gemspec " , / mysql /
2010-11-02 09:23:45 -04:00
end
2012-06-08 13:09:18 -04:00
def test_dont_generate_development_dependency
run_generator [ destination_root , " --skip-active-record " ]
assert_file " bukkits.gemspec " do | contents |
2017-05-06 15:08:58 -04:00
assert_no_match ( / s \ .add_development_dependency "sqlite3" / , contents )
2012-06-08 13:09:18 -04:00
end
end
2014-12-31 08:10:26 -05:00
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 )
2017-08-09 10:05:21 -04:00
assert_match ( / ^ config \ .read_encrypted_secrets = true / , content )
2014-12-31 08:10:26 -05:00
end
end
2017-08-09 10:05:21 -04:00
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
2010-11-02 09:23:45 -04:00
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
2010-10-26 16:22:15 -04:00
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 "
2013-02-28 14:09:04 -05:00
assert_file " test/test_helper.rb " do | contents |
2013-04-03 13:19:30 -04:00
assert_no_match ( / ActiveRecord / , contents )
2013-02-28 14:09:04 -05:00
end
2010-10-26 16:22:15 -04:00
end
2014-12-31 08:10:26 -05:00
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
2017-08-09 10:05:21 -04:00
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["'] /
2017-08-09 11:56:33 -04:00
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
2014-12-31 08:10:26 -05:00
end
2010-10-26 18:16:57 -04:00
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 /
end
2016-07-01 16:34:31 -04:00
def test_generation_runs_bundle_install
assert_generates_without_bundler
end
def test_dev_option
assert_generates_without_bundler ( dev : true )
2016-08-06 13:16:09 -04:00
rails_path = File . expand_path ( " ../../.. " , Rails . root )
assert_file " Gemfile " , / ^gem \ s+["']rails["'], \ s+path: \ s+["'] #{ Regexp . escape ( rails_path ) } ["']$ /
2016-07-01 16:34:31 -04:00
end
def test_edge_option
assert_generates_without_bundler ( edge : true )
2016-09-13 22:50:29 -04:00
assert_file " Gemfile " , %r{ ^gem \ s+["']rails["'], \ s+github: \ s+["'] #{ Regexp . escape ( " rails/rails " ) } ["']$ }
2016-07-01 16:34:31 -04:00
end
def test_generation_does_not_run_bundle_install_with_full_and_mountable
assert_generates_without_bundler ( mountable : true , full : true , dev : true )
assert_no_file " #{ destination_root } /Gemfile.lock "
2011-05-17 18:29:20 -04:00
end
2010-12-15 06:20:20 -05:00
def test_skipping_javascripts_without_mountable_option
run_generator
2011-06-12 21:29:14 -04:00
assert_no_file " app/assets/javascripts/bukkits/application.js "
2010-12-15 06:20:20 -05:00
end
def test_javascripts_generation
run_generator [ destination_root , " --mountable " ]
2011-06-12 21:29:14 -04:00
assert_file " app/assets/javascripts/bukkits/application.js "
2010-12-15 06:20:20 -05:00
end
def test_skip_javascripts
run_generator [ destination_root , " --skip-javascript " , " --mountable " ]
2011-06-12 21:29:14 -04:00
assert_no_file " app/assets/javascripts/bukkits/application.js "
2010-12-15 06:20:20 -05:00
end
2010-10-19 19:05:34 -04:00
def test_template_from_dir_pwd
FileUtils . cd ( Rails . root )
2011-03-12 19:01:12 -05:00
assert_match ( / It works from file! / , run_generator ( [ destination_root , " -m " , " lib/template.rb " ] ) )
2010-10-19 19:05:34 -04:00
end
2011-05-12 18:43:43 -04:00
def test_ensure_that_tests_work
2010-10-20 15:21:37 -04:00
run_generator
FileUtils . cd destination_root
2016-08-06 13:16:09 -04:00
quietly { system " bundle install " }
2015-11-16 18:49:46 -05:00
assert_match ( / 1 runs, 1 assertions, 0 failures, 0 errors / , ` bin/test 2>&1 ` )
2010-10-20 15:21:37 -04:00
end
2010-10-26 16:22:15 -04:00
def test_ensure_that_tests_works_in_full_mode
2010-12-04 11:12:57 -05:00
run_generator [ destination_root , " --full " , " --skip_active_record " ]
2010-10-26 16:22:15 -04:00
FileUtils . cd destination_root
2016-08-06 13:16:09 -04:00
quietly { system " bundle install " }
2017-08-04 12:57:51 -04:00
# 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 ` )
2010-10-26 16:22:15 -04:00
end
2011-07-04 16:48:15 -04:00
def test_ensure_that_migration_tasks_work_with_mountable_option
run_generator [ destination_root , " --mountable " ]
FileUtils . cd destination_root
2016-08-06 13:16:09 -04:00
quietly { system " bundle install " }
2016-01-20 18:11:58 -05:00
output = ` bin/rails db:migrate 2>&1 `
2014-03-14 12:33:42 -04:00
assert $? . success? , " Command failed: #{ output } "
2011-07-04 16:48:15 -04:00
end
2010-10-26 16:22:15 -04:00
def test_creating_engine_in_full_mode
run_generator [ destination_root , " --full " ]
2011-06-12 21:29:14 -04:00
assert_file " app/assets/javascripts/bukkits "
assert_file " app/assets/stylesheets/bukkits "
assert_file " app/assets/images/bukkits "
2011-04-17 04:23:07 -04:00
assert_file " app/models "
assert_file " app/controllers "
assert_file " app/views "
assert_file " app/helpers "
2011-07-29 12:36:36 -04:00
assert_file " app/mailers "
2017-08-07 07:46:14 -04:00
assert_file " bin/rails " , / \ s+require \ s+["']rails \/ all["'] /
2011-01-14 20:32:40 -05:00
assert_file " config/routes.rb " , / Rails.application.routes.draw do /
2011-05-26 06:06:17 -04:00
assert_file " lib/bukkits/engine.rb " , / module Bukkits \ n class Engine < ::Rails::Engine \ n end \ nend /
2010-10-26 16:22:15 -04:00
assert_file " lib/bukkits.rb " , / require "bukkits \/ engine" /
end
2014-01-05 14:41:16 -05:00
def test_creating_engine_with_hyphenated_name_in_full_mode
run_generator [ File . join ( destination_root , " hyphenated-name " ) , " --full " ]
assert_file " hyphenated-name/app/assets/javascripts/hyphenated/name "
assert_file " hyphenated-name/app/assets/stylesheets/hyphenated/name "
assert_file " hyphenated-name/app/assets/images/hyphenated/name "
assert_file " hyphenated-name/app/models "
assert_file " hyphenated-name/app/controllers "
assert_file " hyphenated-name/app/views "
assert_file " hyphenated-name/app/helpers "
assert_file " hyphenated-name/app/mailers "
assert_file " hyphenated-name/bin/rails "
assert_file " hyphenated-name/config/routes.rb " , / Rails.application.routes.draw do /
assert_file " hyphenated-name/lib/hyphenated/name/engine.rb " , / module Hyphenated \ n module Name \ n class Engine < ::Rails::Engine \ n end \ n end \ nend /
assert_file " hyphenated-name/lib/hyphenated/name.rb " , / require "hyphenated \/ name \/ engine" /
2017-05-15 10:17:28 -04:00
assert_file " hyphenated-name/bin/rails " , / \ . \ . \/ lib \/ hyphenated \/ name \/ engine /
2014-01-05 14:41:16 -05:00
end
def test_creating_engine_with_hyphenated_and_underscored_name_in_full_mode
run_generator [ File . join ( destination_root , " my_hyphenated-name " ) , " --full " ]
assert_file " my_hyphenated-name/app/assets/javascripts/my_hyphenated/name "
assert_file " my_hyphenated-name/app/assets/stylesheets/my_hyphenated/name "
assert_file " my_hyphenated-name/app/assets/images/my_hyphenated/name "
assert_file " my_hyphenated-name/app/models "
assert_file " my_hyphenated-name/app/controllers "
assert_file " my_hyphenated-name/app/views "
assert_file " my_hyphenated-name/app/helpers "
assert_file " my_hyphenated-name/app/mailers "
assert_file " my_hyphenated-name/bin/rails "
2017-05-06 15:08:58 -04:00
assert_file " my_hyphenated-name/config/routes.rb " , / Rails \ .application \ .routes \ .draw do /
2014-01-05 14:41:16 -05:00
assert_file " my_hyphenated-name/lib/my_hyphenated/name/engine.rb " , / module MyHyphenated \ n module Name \ n class Engine < ::Rails::Engine \ n end \ n end \ nend /
assert_file " my_hyphenated-name/lib/my_hyphenated/name.rb " , / require "my_hyphenated \/ name \/ engine" /
2017-05-15 10:17:28 -04:00
assert_file " my_hyphenated-name/bin/rails " , / \ . \ . \/ lib \/ my_hyphenated \/ name \/ engine /
2014-01-05 14:41:16 -05:00
end
2010-10-27 21:00:42 -04:00
def test_being_quiet_while_creating_dummy_application
2017-05-06 15:08:58 -04:00
assert_no_match ( / create \ s+config \/ application \ .rb / , run_generator )
2010-10-27 21:00:42 -04:00
end
2010-11-02 11:34:07 -04:00
def test_create_mountable_application_with_mountable_option
run_generator [ destination_root , " --mountable " ]
2011-06-12 21:29:14 -04:00
assert_file " app/assets/javascripts/bukkits "
assert_file " app/assets/stylesheets/bukkits "
assert_file " app/assets/images/bukkits "
2017-05-06 15:08:58 -04:00
assert_file " config/routes.rb " , / Bukkits::Engine \ .routes \ .draw do /
2010-11-02 11:34:07 -04:00
assert_file " lib/bukkits/engine.rb " , / isolate_namespace Bukkits /
assert_file " test/dummy/config/routes.rb " , / mount Bukkits::Engine => " \/ bukkits" /
2010-11-16 10:41:37 -05:00
assert_file " app/controllers/bukkits/application_controller.rb " , / module Bukkits \ n class ApplicationController < ActionController::Base /
2016-01-01 23:20:46 -05:00
assert_file " app/models/bukkits/application_record.rb " , / module Bukkits \ n class ApplicationRecord < ActiveRecord::Base /
2015-07-16 20:28:39 -04:00
assert_file " app/jobs/bukkits/application_job.rb " , / module Bukkits \ n class ApplicationJob < ActiveJob::Base /
2017-05-06 15:08:58 -04:00
assert_file " app/mailers/bukkits/application_mailer.rb " , / module Bukkits \ n class ApplicationMailer < ActionMailer::Base \ n default from: 'from@example \ .com' \ n layout 'mailer' \ n /
2010-11-02 11:34:07 -04:00
assert_file " app/helpers/bukkits/application_helper.rb " , / module Bukkits \ n module ApplicationHelper /
2011-06-12 21:29:14 -04:00
assert_file " app/views/layouts/bukkits/application.html.erb " do | contents |
assert_match " <title>Bukkits</title> " , contents
2011-09-03 22:53:13 -04:00
assert_match ( / stylesheet_link_tag \ s+['"]bukkits \/ application['"] / , contents )
assert_match ( / javascript_include_tag \ s+['"]bukkits \/ application['"] / , contents )
2011-06-12 21:29:14 -04:00
end
2014-10-12 17:22:49 -04:00
assert_file " test/test_helper.rb " do | content |
assert_match ( / ActiveRecord::Migrator \ .migrations_paths.+ \ . \ . \/ test \/ dummy \/ db \/ migrate / , content )
assert_match ( / ActiveRecord::Migrator \ .migrations_paths.+<<.+ \ . \ . \/ db \/ migrate / , content )
2015-07-27 07:34:10 -04:00
assert_match ( / ActionDispatch::IntegrationTest \ .fixture_path = ActiveSupport::TestCase \ .fixture_pat / , content )
2015-11-16 18:49:46 -05:00
assert_no_match ( / Rails::TestUnitReporter \ .executable = 'bin \/ test' / , content )
2014-10-12 17:22:49 -04:00
end
2016-08-06 13:16:09 -04:00
assert_no_file " bin/test "
2010-11-02 11:34:07 -04:00
end
2014-01-05 14:41:16 -05:00
def test_create_mountable_application_with_mountable_option_and_hypenated_name
run_generator [ File . join ( destination_root , " hyphenated-name " ) , " --mountable " ]
assert_file " hyphenated-name/app/assets/javascripts/hyphenated/name "
assert_file " hyphenated-name/app/assets/stylesheets/hyphenated/name "
assert_file " hyphenated-name/app/assets/images/hyphenated/name "
2017-05-06 15:08:58 -04:00
assert_file " hyphenated-name/config/routes.rb " , / Hyphenated::Name::Engine \ .routes \ .draw do /
assert_file " hyphenated-name/lib/hyphenated/name/version.rb " , / module Hyphenated \ n module Name \ n VERSION = '0 \ .1 \ .0' \ n end \ nend /
2015-01-30 18:42:51 -05:00
assert_file " hyphenated-name/lib/hyphenated/name/engine.rb " , / module Hyphenated \ n module Name \ n class Engine < ::Rails::Engine \ n isolate_namespace Hyphenated::Name \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " hyphenated-name/lib/hyphenated/name.rb " , / require "hyphenated \/ name \/ engine" /
assert_file " hyphenated-name/test/dummy/config/routes.rb " , / mount Hyphenated::Name::Engine => " \/ hyphenated-name" /
2016-02-12 17:31:46 -05:00
assert_file " hyphenated-name/app/controllers/hyphenated/name/application_controller.rb " , / module Hyphenated \ n module Name \ n class ApplicationController < ActionController::Base \ n protect_from_forgery with: :exception \ n end \ n end \ nend \ n /
2016-01-01 23:20:46 -05:00
assert_file " hyphenated-name/app/models/hyphenated/name/application_record.rb " , / module Hyphenated \ n module Name \ n class ApplicationRecord < ActiveRecord::Base \ n self \ .abstract_class = true \ n end \ n end \ nend /
assert_file " hyphenated-name/app/jobs/hyphenated/name/application_job.rb " , / module Hyphenated \ n module Name \ n class ApplicationJob < ActiveJob::Base /
2017-05-06 15:08:58 -04:00
assert_file " hyphenated-name/app/mailers/hyphenated/name/application_mailer.rb " , / module Hyphenated \ n module Name \ n class ApplicationMailer < ActionMailer::Base \ n default from: 'from@example \ .com' \ n layout 'mailer' \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " hyphenated-name/app/helpers/hyphenated/name/application_helper.rb " , / module Hyphenated \ n module Name \ n module ApplicationHelper \ n end \ n end \ nend /
assert_file " hyphenated-name/app/views/layouts/hyphenated/name/application.html.erb " do | contents |
assert_match " <title>Hyphenated name</title> " , contents
assert_match ( / stylesheet_link_tag \ s+['"]hyphenated \/ name \/ application['"] / , contents )
assert_match ( / javascript_include_tag \ s+['"]hyphenated \/ name \/ application['"] / , contents )
end
end
def test_create_mountable_application_with_mountable_option_and_hypenated_and_underscored_name
run_generator [ File . join ( destination_root , " my_hyphenated-name " ) , " --mountable " ]
assert_file " my_hyphenated-name/app/assets/javascripts/my_hyphenated/name "
assert_file " my_hyphenated-name/app/assets/stylesheets/my_hyphenated/name "
assert_file " my_hyphenated-name/app/assets/images/my_hyphenated/name "
2017-05-06 15:08:58 -04:00
assert_file " my_hyphenated-name/config/routes.rb " , / MyHyphenated::Name::Engine \ .routes \ .draw do /
assert_file " my_hyphenated-name/lib/my_hyphenated/name/version.rb " , / module MyHyphenated \ n module Name \ n VERSION = '0 \ .1 \ .0' \ n end \ nend /
2015-01-30 18:42:51 -05:00
assert_file " my_hyphenated-name/lib/my_hyphenated/name/engine.rb " , / module MyHyphenated \ n module Name \ n class Engine < ::Rails::Engine \ n isolate_namespace MyHyphenated::Name \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " my_hyphenated-name/lib/my_hyphenated/name.rb " , / require "my_hyphenated \/ name \/ engine" /
2015-01-30 18:42:51 -05:00
assert_file " my_hyphenated-name/test/dummy/config/routes.rb " , / mount MyHyphenated::Name::Engine => " \/ my_hyphenated-name" /
2016-02-12 17:31:46 -05:00
assert_file " my_hyphenated-name/app/controllers/my_hyphenated/name/application_controller.rb " , / module MyHyphenated \ n module Name \ n class ApplicationController < ActionController::Base \ n protect_from_forgery with: :exception \ n end \ n end \ nend \ n /
2016-01-01 23:20:46 -05:00
assert_file " my_hyphenated-name/app/models/my_hyphenated/name/application_record.rb " , / module MyHyphenated \ n module Name \ n class ApplicationRecord < ActiveRecord::Base \ n self \ .abstract_class = true \ n end \ n end \ nend /
assert_file " my_hyphenated-name/app/jobs/my_hyphenated/name/application_job.rb " , / module MyHyphenated \ n module Name \ n class ApplicationJob < ActiveJob::Base /
2017-05-06 15:08:58 -04:00
assert_file " my_hyphenated-name/app/mailers/my_hyphenated/name/application_mailer.rb " , / module MyHyphenated \ n module Name \ n class ApplicationMailer < ActionMailer::Base \ n default from: 'from@example \ .com' \ n layout 'mailer' \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " my_hyphenated-name/app/helpers/my_hyphenated/name/application_helper.rb " , / module MyHyphenated \ n module Name \ n module ApplicationHelper \ n end \ n end \ nend /
assert_file " my_hyphenated-name/app/views/layouts/my_hyphenated/name/application.html.erb " do | contents |
assert_match " <title>My hyphenated name</title> " , contents
assert_match ( / stylesheet_link_tag \ s+['"]my_hyphenated \/ name \/ application['"] / , contents )
assert_match ( / javascript_include_tag \ s+['"]my_hyphenated \/ name \/ application['"] / , contents )
end
end
def test_create_mountable_application_with_mountable_option_and_multiple_hypenates_in_name
run_generator [ File . join ( destination_root , " deep-hyphenated-name " ) , " --mountable " ]
assert_file " deep-hyphenated-name/app/assets/javascripts/deep/hyphenated/name "
assert_file " deep-hyphenated-name/app/assets/stylesheets/deep/hyphenated/name "
assert_file " deep-hyphenated-name/app/assets/images/deep/hyphenated/name "
2017-05-06 15:08:58 -04:00
assert_file " deep-hyphenated-name/config/routes.rb " , / Deep::Hyphenated::Name::Engine \ .routes \ .draw do /
assert_file " deep-hyphenated-name/lib/deep/hyphenated/name/version.rb " , / module Deep \ n module Hyphenated \ n module Name \ n VERSION = '0 \ .1 \ .0' \ n end \ n end \ nend /
2015-01-30 18:42:51 -05:00
assert_file " deep-hyphenated-name/lib/deep/hyphenated/name/engine.rb " , / module Deep \ n module Hyphenated \ n module Name \ n class Engine < ::Rails::Engine \ n isolate_namespace Deep::Hyphenated::Name \ n end \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " deep-hyphenated-name/lib/deep/hyphenated/name.rb " , / require "deep \/ hyphenated \/ name \/ engine" /
2015-01-30 18:42:51 -05:00
assert_file " deep-hyphenated-name/test/dummy/config/routes.rb " , / mount Deep::Hyphenated::Name::Engine => " \/ deep-hyphenated-name" /
2016-02-12 17:31:46 -05:00
assert_file " deep-hyphenated-name/app/controllers/deep/hyphenated/name/application_controller.rb " , / module Deep \ n module Hyphenated \ n module Name \ n class ApplicationController < ActionController::Base \ n protect_from_forgery with: :exception \ n end \ n end \ n end \ nend \ n /
2016-01-01 23:20:46 -05:00
assert_file " deep-hyphenated-name/app/models/deep/hyphenated/name/application_record.rb " , / module Deep \ n module Hyphenated \ n module Name \ n class ApplicationRecord < ActiveRecord::Base \ n self \ .abstract_class = true \ n end \ n end \ n end \ nend /
assert_file " deep-hyphenated-name/app/jobs/deep/hyphenated/name/application_job.rb " , / module Deep \ n module Hyphenated \ n module Name \ n class ApplicationJob < ActiveJob::Base /
2017-05-06 15:08:58 -04:00
assert_file " deep-hyphenated-name/app/mailers/deep/hyphenated/name/application_mailer.rb " , / module Deep \ n module Hyphenated \ n module Name \ n class ApplicationMailer < ActionMailer::Base \ n default from: 'from@example \ .com' \ n layout 'mailer' \ n end \ n end \ n end \ nend /
2014-01-05 14:41:16 -05:00
assert_file " deep-hyphenated-name/app/helpers/deep/hyphenated/name/application_helper.rb " , / module Deep \ n module Hyphenated \ n module Name \ n module ApplicationHelper \ n end \ n end \ n end \ nend /
assert_file " deep-hyphenated-name/app/views/layouts/deep/hyphenated/name/application.html.erb " do | contents |
assert_match " <title>Deep hyphenated name</title> " , contents
assert_match ( / stylesheet_link_tag \ s+['"]deep \/ hyphenated \/ name \/ application['"] / , contents )
assert_match ( / javascript_include_tag \ s+['"]deep \/ hyphenated \/ name \/ application['"] / , contents )
end
end
2011-05-24 03:30:23 -04:00
def test_creating_gemspec
2011-05-24 06:37:57 -04:00
run_generator
2017-05-06 15:08:58 -04:00
assert_file " bukkits.gemspec " , / s \ .name \ s+= "bukkits" /
assert_file " bukkits.gemspec " , / s \ .files = Dir \ [" \ {app,config,db,lib \ } \/ \ * \ * \/ \ *", "MIT-LICENSE", "Rakefile", "README \ .md" \ ] /
assert_file " bukkits.gemspec " , / s \ .version \ s+ = Bukkits::VERSION /
2011-05-24 03:30:23 -04:00
end
2011-05-27 02:25:56 -04:00
def test_usage_of_engine_commands
2011-05-27 07:44:10 -04:00
run_generator [ destination_root , " --full " ]
2017-05-15 10:17:28 -04:00
assert_file " bin/rails " , / ENGINE_PATH = File \ .expand_path \ (' \ . \ . \/ lib \/ bukkits \/ engine', __dir__ \ ) /
assert_file " bin/rails " , / ENGINE_ROOT = File \ .expand_path \ (' \ . \ .', __dir__ \ ) /
assert_file " bin/rails " , %r|APP_PATH = File\.expand_path\('\.\./test/dummy/config/application', __dir__\)|
2013-01-06 18:13:47 -05:00
assert_file " bin/rails " , / require 'rails \/ all' /
assert_file " bin/rails " , / require 'rails \/ engine \/ commands' /
2011-05-27 02:25:56 -04:00
end
2011-05-24 07:57:36 -04:00
def test_shebang
2011-05-27 07:44:10 -04:00
run_generator [ destination_root , " --full " ]
2013-01-06 18:13:47 -05:00
assert_file " bin/rails " , / # ! \/ usr \/ bin \/ env ruby /
2011-05-24 07:57:36 -04:00
end
2010-11-08 16:43:51 -05:00
def test_passing_dummy_path_as_a_parameter
run_generator [ destination_root , " --dummy_path " , " spec/dummy " ]
assert_file " spec/dummy "
assert_file " spec/dummy/config/application.rb "
assert_no_file " test/dummy "
2014-09-16 22:42:04 -04:00
assert_file " test/test_helper.rb " do | content |
2017-06-11 08:59:23 -04:00
assert_match ( / require_relative.+spec \/ dummy \/ config \/ environment / , content )
2014-09-16 22:42:04 -04:00
assert_match ( / ActiveRecord::Migrator \ .migrations_paths.+spec \/ dummy \/ db \/ migrate / , content )
end
2010-11-08 16:43:51 -05:00
end
2011-05-25 09:03:42 -04:00
2012-05-10 17:11:59 -04:00
def test_creating_dummy_application_with_different_name
run_generator [ destination_root , " --dummy_path " , " spec/fake " ]
assert_file " spec/fake "
assert_file " spec/fake/config/application.rb "
assert_no_file " test/dummy "
2014-09-16 22:42:04 -04:00
assert_file " test/test_helper.rb " do | content |
2017-06-11 08:59:23 -04:00
assert_match ( / require_relative.+spec \/ fake \/ config \/ environment / , content )
2014-09-16 22:42:04 -04:00
assert_match ( / ActiveRecord::Migrator \ .migrations_paths.+spec \/ fake \/ db \/ migrate / , content )
end
2012-05-10 17:11:59 -04:00
end
2011-05-24 07:18:27 -04:00
def test_creating_dummy_without_tests_but_with_dummy_path
2015-01-27 17:59:48 -05:00
run_generator [ destination_root , " --dummy_path " , " spec/dummy " , " --skip-test " ]
2017-08-09 10:05:21 -04:00
assert_directory " spec/dummy "
assert_file " spec/dummy/config/application.rb " , / # \ s+require \ s+["']rails \/ test_unit \/ railtie["'] /
assert_no_directory " test "
2016-08-06 13:16:09 -04:00
assert_file " .gitignore " do | contents |
2012-07-03 12:58:17 -04:00
assert_match ( / spec \/ dummy / , contents )
end
2011-05-24 07:18:27 -04:00
end
2012-01-07 12:53:49 -05:00
2016-02-18 07:11:06 -05:00
def test_dummy_appplication_skip_listen_by_default
run_generator
2016-08-06 13:16:09 -04:00
assert_file " test/dummy/config/environments/development.rb " do | contents |
2017-05-06 15:08:58 -04:00
assert_match ( / ^ \ s* # config \ .file_watcher = ActiveSupport::EventedFileUpdateChecker / , contents )
2016-02-18 07:11:06 -05:00
end
end
2011-11-10 02:22:26 -05:00
def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path
FileUtils . cd ( Rails . root )
2015-01-27 17:59:48 -05:00
run_generator ( [ destination_root , " --dummy_path " , " spec/dummy " , " --skip-test " ] )
2011-11-10 02:22:26 -05:00
assert_file " .gitignore " do | contents |
assert_match ( / spec \/ dummy / , contents )
end
end
2010-11-08 16:43:51 -05:00
2015-10-23 06:41:56 -04:00
def test_unnecessary_files_are_not_generated_in_dummy_application
run_generator
2016-08-06 13:16:09 -04:00
assert_no_file " test/dummy/.gitignore "
assert_no_file " test/dummy/db/seeds.rb "
assert_no_file " test/dummy/Gemfile "
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/test "
assert_no_directory " test/dummy/vendor "
2017-02-17 20:59:46 -05:00
assert_no_directory " test/dummy/.git "
2015-10-23 06:41:56 -04:00
end
2015-01-29 15:44:26 -05:00
def test_skipping_test_files
2015-01-27 17:59:48 -05:00
run_generator [ destination_root , " --skip-test " ]
2017-08-09 10:05:21 -04:00
assert_no_directory " test "
2016-08-06 13:16:09 -04:00
assert_file " .gitignore " do | contents |
2017-08-06 02:40:47 -04:00
assert_no_match ( / test \/ dummy / , contents )
2012-07-03 12:58:17 -04:00
end
2011-05-25 09:03:07 -04:00
end
2010-11-14 20:04:17 -05:00
def test_skipping_gemspec
run_generator [ destination_root , " --skip-gemspec " ]
assert_no_file " bukkits.gemspec "
2012-06-05 01:49:40 -04:00
assert_file " Gemfile " do | contents |
2016-08-06 13:16:09 -04:00
assert_no_match ( " gemspec " , contents )
2015-12-18 09:39:19 -05:00
assert_match ( / gem 'rails' / , contents )
2013-11-23 05:38:54 -05:00
assert_match_sqlite3 ( contents )
2012-06-05 01:49:40 -04:00
end
end
def test_skipping_gemspec_in_full_mode
run_generator [ destination_root , " --skip-gemspec " , " --full " ]
assert_no_file " bukkits.gemspec "
assert_file " Gemfile " do | contents |
2016-08-06 13:16:09 -04:00
assert_no_match ( " gemspec " , contents )
2015-12-18 09:39:19 -05:00
assert_match ( / gem 'rails' / , contents )
2013-11-23 05:38:54 -05:00
assert_match_sqlite3 ( contents )
2012-06-05 01:49:40 -04:00
end
2010-11-14 20:04:17 -05:00
end
2012-01-07 12:53:49 -05:00
def test_creating_plugin_in_app_directory_adds_gemfile_entry
2013-12-02 09:05:02 -05:00
# simulate application existence
2012-01-07 12:53:49 -05:00
gemfile_path = " #{ Rails . root } /Gemfile "
2016-08-06 13:16:09 -04:00
Object . const_set ( " APP_PATH " , Rails . root )
2012-01-07 12:53:49 -05:00
FileUtils . touch gemfile_path
2014-07-30 22:13:59 -04:00
run_generator
2012-01-07 12:53:49 -05:00
2012-05-22 05:26:06 -04:00
assert_file gemfile_path , / gem 'bukkits', path: 'tmp \/ bukkits' /
2012-01-07 12:53:49 -05:00
ensure
2016-08-06 13:16:09 -04:00
Object . send ( :remove_const , " APP_PATH " )
2012-01-07 12:53:49 -05:00
FileUtils . rm gemfile_path
end
2017-02-18 02:42:48 -05:00
def test_creating_plugin_only_specify_plugin_name_in_app_directory_adds_gemfile_entry
# simulate application existence
gemfile_path = " #{ Rails . root } /Gemfile "
Object . const_set ( " APP_PATH " , Rails . root )
FileUtils . touch gemfile_path
FileUtils . cd ( destination_root )
run_generator [ " bukkits " ]
assert_file gemfile_path , / gem 'bukkits', path: 'bukkits' /
ensure
Object . send ( :remove_const , " APP_PATH " )
FileUtils . rm gemfile_path
end
2012-01-07 12:53:49 -05:00
def test_skipping_gemfile_entry
2013-12-02 09:05:02 -05:00
# simulate application existence
2012-01-07 12:53:49 -05:00
gemfile_path = " #{ Rails . root } /Gemfile "
2016-08-06 13:16:09 -04:00
Object . const_set ( " APP_PATH " , Rails . root )
2012-01-07 12:53:49 -05:00
FileUtils . touch gemfile_path
run_generator [ destination_root , " --skip-gemfile-entry " ]
assert_file gemfile_path do | contents |
2012-05-22 05:26:06 -04:00
assert_no_match ( / gem 'bukkits', path: 'tmp \/ bukkits' / , contents )
2012-01-07 12:53:49 -05:00
end
ensure
2016-08-06 13:16:09 -04:00
Object . send ( :remove_const , " APP_PATH " )
2012-01-07 12:53:49 -05:00
FileUtils . rm gemfile_path
end
2014-02-25 08:57:23 -05:00
def test_generating_controller_inside_mountable_engine
run_generator [ destination_root , " --mountable " ]
capture ( :stdout ) do
` #{ destination_root } /bin/rails g controller admin/dashboard foo `
end
assert_file " config/routes.rb " do | contents |
assert_match ( / namespace :admin / , contents )
assert_no_match ( / namespace :bukkit / , contents )
end
end
2012-01-07 12:53:49 -05:00
2013-04-12 00:51:52 -04:00
def test_git_name_and_email_in_gemspec_file
2014-05-02 05:26:31 -04:00
name = ` git config user.name ` . chomp rescue " TODO: Write your name "
email = ` git config user.email ` . chomp rescue " TODO: Write your email address "
2013-04-12 00:51:52 -04:00
2014-07-30 22:13:59 -04:00
run_generator
2013-04-12 00:51:52 -04:00
assert_file " bukkits.gemspec " do | contents |
2014-07-30 22:06:30 -04:00
assert_match name , contents
assert_match email , contents
2013-04-12 00:51:52 -04:00
end
end
2014-05-02 05:26:31 -04:00
def test_git_name_in_license_file
name = ` git config user.name ` . chomp rescue " TODO: Write your name "
2013-04-12 00:51:52 -04:00
2014-07-30 22:13:59 -04:00
run_generator
2013-04-12 00:51:52 -04:00
assert_file " MIT-LICENSE " do | contents |
2014-07-30 22:06:30 -04:00
assert_match name , contents
2013-04-12 00:51:52 -04:00
end
end
2014-05-02 05:26:31 -04:00
def test_no_details_from_git_when_skip_git
name = " TODO: Write your name "
email = " TODO: Write your email address "
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --skip-git " ]
2014-05-02 05:26:31 -04:00
assert_file " MIT-LICENSE " do | contents |
2014-07-30 22:06:30 -04:00
assert_match name , contents
2014-05-02 05:26:31 -04:00
end
assert_file " bukkits.gemspec " do | contents |
2014-07-30 22:06:30 -04:00
assert_match name , contents
assert_match email , contents
2014-05-02 05:26:31 -04:00
end
end
2015-07-23 11:52:51 -04:00
def test_skipping_useless_folders_generation_for_api_engines
2016-08-06 13:16:09 -04:00
[ " --full " , " --mountable " ] . each do | option |
run_generator [ destination_root , option , " --api " ]
2015-07-23 11:52:51 -04:00
assert_no_directory " app/assets "
assert_no_directory " app/helpers "
assert_no_directory " app/views "
FileUtils . rm_rf destination_root
end
end
2015-07-23 11:58:02 -04:00
def test_application_controller_parent_for_mountable_api_plugins
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " , " --api " ]
2015-07-23 11:58:02 -04:00
assert_file " app/controllers/bukkits/application_controller.rb " do | content |
assert_match " ApplicationController < ActionController::API " , content
end
end
2015-07-23 12:01:53 -04:00
def test_dummy_api_application_for_api_plugins
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --api " ]
2015-07-23 12:01:53 -04:00
assert_file " test/dummy/config/application.rb " do | content |
assert_match " config.api_only = true " , content
end
end
2015-07-23 12:03:40 -04:00
def test_api_generators_configuration_for_api_engines
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --full " , " --api " ]
2015-07-23 12:03:40 -04:00
assert_file " lib/bukkits/engine.rb " do | content |
assert_match " config.generators.api_only = true " , content
end
end
def test_scaffold_generator_for_mountable_api_plugins
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " , " --api " ]
2015-07-23 12:03:40 -04:00
capture ( :stdout ) do
` #{ destination_root } /bin/rails g scaffold article `
end
assert_file " app/models/bukkits/article.rb "
assert_file " app/controllers/bukkits/articles_controller.rb " do | content |
assert_match " only: [:show, :update, :destroy] " , content
end
assert_no_directory " app/assets "
assert_no_directory " app/helpers "
assert_no_directory " app/views "
end
2016-01-01 23:20:46 -05:00
def test_model_with_existent_application_record_in_mountable_engine
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " ]
2016-01-01 23:20:46 -05:00
capture ( :stdout ) do
` #{ destination_root } /bin/rails g model article `
end
assert_file " app/models/bukkits/article.rb " , / class Article < ApplicationRecord /
end
2016-03-11 22:31:06 -05:00
def test_generate_application_mailer_when_does_not_exist_in_mountable_engine
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " ]
2016-03-11 22:31:06 -05:00
FileUtils . rm " #{ destination_root } /app/mailers/bukkits/application_mailer.rb "
capture ( :stdout ) do
` #{ destination_root } /bin/rails g mailer User `
end
assert_file " #{ destination_root } /app/mailers/bukkits/application_mailer.rb " do | mailer |
assert_match ( / module Bukkits / , mailer )
assert_match ( / class ApplicationMailer < ActionMailer::Base / , mailer )
end
end
2016-05-13 02:02:36 -04:00
def test_generate_mailer_layouts_when_does_not_exist_in_mountable_engine
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " ]
2016-05-13 02:02:36 -04:00
capture ( :stdout ) do
` #{ destination_root } /bin/rails g mailer User `
end
assert_file " #{ destination_root } /app/views/layouts/bukkits/mailer.text.erb " do | view |
assert_match ( / <%= yield %> / , view )
end
assert_file " #{ destination_root } /app/views/layouts/bukkits/mailer.html.erb " do | view |
assert_match ( %r{ <body> \ n <%= yield %> \ n </body> } , view )
end
end
2016-03-12 01:00:55 -05:00
def test_generate_application_job_when_does_not_exist_in_mountable_engine
2016-08-06 13:16:09 -04:00
run_generator [ destination_root , " --mountable " ]
2016-03-12 01:00:55 -05:00
FileUtils . rm " #{ destination_root } /app/jobs/bukkits/application_job.rb "
capture ( :stdout ) do
` #{ destination_root } /bin/rails g job refresh_counters `
end
assert_file " #{ destination_root } /app/jobs/bukkits/application_job.rb " do | record |
assert_match ( / module Bukkits / , record )
assert_match ( / class ApplicationJob < ActiveJob::Base / , record )
end
end
2017-01-16 08:27:51 -05:00
def test_app_update_generates_bin_file
run_generator [ destination_root , " --mountable " ]
Object . const_set ( " ENGINE_ROOT " , destination_root )
FileUtils . rm ( " #{ destination_root } /bin/rails " )
quietly { Rails :: Engine :: Updater . run ( :create_bin_files ) }
assert_file " #{ destination_root } /bin/rails " do | content |
2017-05-15 10:17:28 -04:00
assert_match ( %r|APP_PATH = File\.expand_path\('\.\./test/dummy/config/application', __dir__\)| , content )
2017-01-16 08:27:51 -05:00
end
ensure
Object . send ( :remove_const , " ENGINE_ROOT " )
end
2016-12-23 09:45:39 -05:00
private
2016-01-28 13:43:24 -05:00
2016-07-01 16:34:31 -04:00
def action ( * args , & block )
2016-08-16 03:30:11 -04:00
silence ( :stdout ) { generator . send ( * args , & block ) }
2016-01-28 13:43:24 -05:00
end
2016-07-01 16:34:31 -04:00
def default_files
:: DEFAULT_PLUGIN_FILES
2016-01-28 13:43:24 -05:00
end
2016-07-01 16:34:31 -04:00
def assert_match_sqlite3 ( contents )
if defined? ( JRUBY_VERSION )
assert_match ( / group :development do \ n gem 'activerecord-jdbcsqlite3-adapter' \ nend / , contents )
else
assert_match ( / group :development do \ n gem 'sqlite3' \ nend / , contents )
2016-01-28 13:43:24 -05:00
end
end
2016-07-01 16:34:31 -04:00
def assert_generates_without_bundler ( options = { } )
generator ( [ destination_root ] , options )
2016-01-28 13:43:24 -05:00
2016-07-01 16:34:31 -04:00
command_check = - > command do
case command
2016-08-06 13:16:09 -04:00
when " install "
2016-07-01 16:34:31 -04:00
flunk " install expected to not be called "
2016-08-06 13:16:09 -04:00
when " exec spring binstub --all "
2016-07-01 16:34:31 -04:00
# Called when running tests with spring, let through unscathed.
end
end
2013-11-23 05:38:54 -05:00
2016-07-01 16:34:31 -04:00
generator . stub :bundle_command , command_check do
quietly { generator . invoke_all }
end
2013-11-23 05:38:54 -05:00
end
2010-10-15 10:46:31 -04:00
end