2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
# Note:
|
|
|
|
# It is important to keep this file as light as possible
|
|
|
|
# the goal for tests that require this is to test booting up
|
2016-07-12 02:51:36 -04:00
|
|
|
# Rails from an empty state, so anything added here could
|
2009-09-25 22:32:28 -04:00
|
|
|
# hide potential failures
|
|
|
|
#
|
|
|
|
# It is also good to know what is the bare minimum to get
|
|
|
|
# Rails booted up.
|
2016-08-06 13:16:09 -04:00
|
|
|
require "fileutils"
|
2009-10-07 20:02:36 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "bundler/setup" unless defined?(Bundler)
|
|
|
|
require "active_support"
|
|
|
|
require "active_support/testing/autorun"
|
|
|
|
require "active_support/testing/stream"
|
2019-08-02 00:24:21 -04:00
|
|
|
require "active_support/testing/method_call_assertions"
|
2016-08-06 13:16:09 -04:00
|
|
|
require "active_support/test_case"
|
2018-10-10 18:33:09 -04:00
|
|
|
require "minitest/retry"
|
|
|
|
|
2019-04-16 19:10:45 -04:00
|
|
|
if ENV["BUILDKITE"]
|
|
|
|
Minitest::Retry.use!(verbose: false, retry_count: 1)
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
|
2017-05-15 10:17:28 -04:00
|
|
|
RAILS_FRAMEWORK_ROOT = File.expand_path("../../..", __dir__)
|
2009-09-25 22:32:28 -04:00
|
|
|
|
|
|
|
# These files do not require any others and are needed
|
|
|
|
# to run the tests
|
2016-06-13 11:54:52 -04:00
|
|
|
require "active_support/core_ext/object/blank"
|
2012-05-11 12:56:05 -04:00
|
|
|
require "active_support/testing/isolation"
|
|
|
|
require "active_support/core_ext/kernel/reporting"
|
2016-08-06 13:16:09 -04:00
|
|
|
require "tmpdir"
|
2017-02-23 12:15:28 -05:00
|
|
|
require "rails/secrets"
|
2009-09-25 22:32:28 -04:00
|
|
|
|
|
|
|
module TestHelpers
|
|
|
|
module Paths
|
2012-06-19 17:27:52 -04:00
|
|
|
def app_template_path
|
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps
* Stop including coffee-rails by default
* Drop using a js_compressor by default
* Drop extra test for coffeescript inclusion by default
* Stick with skip_javascript to signify skipping webpack
* Don't install a JS runtime by default any more
* app/javascript will be the new default directory for JS
* Make it clear that this is just for configuring the default Webpack framework setup now
* Start using the Webpack tag in the default layout
* Irrelevant test
* jQuery is long gone
* Stop having asset pipeline compile default application.js
* Add rails-ujs by default to the Webpack setup
* Add Active Storage JavaScript to application.js pack by default
* Consistent quoting
* Add Turbolinks to default pack
* Add Action Cable to default pack
Need some work on how to set the global consumer that channels will
work with. @javan?
* Require all channels by default and use a separate consumer stub
* Channel generator now targets Webpack style
* Update task docs to match new generator style
* Use uniform import style
* Drop the JS assets generator
It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!
* Add app/javascript to the stats directories
* Simpler import style
Which match the other imports.
* Address test failures from dropping JS compilation (and compression)
* webpacker-default: Modify `AssetsGeneratorTest`
Before:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201
F
Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10
.
Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```
After:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571
..
Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```
* webpacker-default: Modify `ChannelGeneratorTest`
Before:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986
.F
Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34
.F
Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22
E
Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60
F
Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80
F
Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68
Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```
After:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857
.......
Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```
* Fix shared generator tests.
* webpacker-default: Modify `ControllerGeneratorTest`
The JS assets generator was dropped. ref. https://github.com/rails/rails/commit/46215b179483d3e4d264555f5a4952f43eb8142a
* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.
This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.
* require webpacker in test app
* Add webpacker without making the build hang/timeout. (#33640)
* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required
* no longer need to have webpacker in env templates as webpacker moved this config to yml file
* Fix rubocop violation
* Got the test passing for the running scaffold
* update expected lines of code
* update middleware tests to account for webpacker
* disable js in plugins be default to get the tests passing (#34009)
* clear codeclimate report issues
* Anything newer than currently released is good
* Use Webpacker development version during development of Rails
* Edge should get development webpacker as well
* Add changelog entry for Webpacker change
2018-10-01 01:31:21 -04:00
|
|
|
File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/app_template"
|
2012-06-19 17:27:52 -04:00
|
|
|
end
|
2009-10-14 19:13:45 -04:00
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
def tmp_path(*args)
|
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps
* Stop including coffee-rails by default
* Drop using a js_compressor by default
* Drop extra test for coffeescript inclusion by default
* Stick with skip_javascript to signify skipping webpack
* Don't install a JS runtime by default any more
* app/javascript will be the new default directory for JS
* Make it clear that this is just for configuring the default Webpack framework setup now
* Start using the Webpack tag in the default layout
* Irrelevant test
* jQuery is long gone
* Stop having asset pipeline compile default application.js
* Add rails-ujs by default to the Webpack setup
* Add Active Storage JavaScript to application.js pack by default
* Consistent quoting
* Add Turbolinks to default pack
* Add Action Cable to default pack
Need some work on how to set the global consumer that channels will
work with. @javan?
* Require all channels by default and use a separate consumer stub
* Channel generator now targets Webpack style
* Update task docs to match new generator style
* Use uniform import style
* Drop the JS assets generator
It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!
* Add app/javascript to the stats directories
* Simpler import style
Which match the other imports.
* Address test failures from dropping JS compilation (and compression)
* webpacker-default: Modify `AssetsGeneratorTest`
Before:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201
F
Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10
.
Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```
After:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571
..
Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```
* webpacker-default: Modify `ChannelGeneratorTest`
Before:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986
.F
Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34
.F
Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22
E
Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60
F
Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80
F
Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68
Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```
After:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857
.......
Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```
* Fix shared generator tests.
* webpacker-default: Modify `ControllerGeneratorTest`
The JS assets generator was dropped. ref. https://github.com/rails/rails/commit/46215b179483d3e4d264555f5a4952f43eb8142a
* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.
This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.
* require webpacker in test app
* Add webpacker without making the build hang/timeout. (#33640)
* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required
* no longer need to have webpacker in env templates as webpacker moved this config to yml file
* Fix rubocop violation
* Got the test passing for the running scaffold
* update expected lines of code
* update middleware tests to account for webpacker
* disable js in plugins be default to get the tests passing (#34009)
* clear codeclimate report issues
* Anything newer than currently released is good
* Use Webpacker development version during development of Rails
* Edge should get development webpacker as well
* Add changelog entry for Webpacker change
2018-10-01 01:31:21 -04:00
|
|
|
@tmp_path ||= File.realpath(Dir.mktmpdir(nil, File.join(RAILS_FRAMEWORK_ROOT, "tmp")))
|
2012-06-19 19:27:54 -04:00
|
|
|
File.join(@tmp_path, *args)
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def app_path(*args)
|
2017-12-20 16:59:41 -05:00
|
|
|
path = tmp_path(*%w[app] + args)
|
|
|
|
if block_given?
|
|
|
|
yield path
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
2009-10-05 10:41:08 -04:00
|
|
|
|
2009-10-08 21:12:28 -04:00
|
|
|
def framework_path
|
|
|
|
RAILS_FRAMEWORK_ROOT
|
|
|
|
end
|
|
|
|
|
2009-10-05 10:41:08 -04:00
|
|
|
def rails_root
|
|
|
|
app_path
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Rack
|
2010-10-02 11:42:36 -04:00
|
|
|
def app(env = "production")
|
|
|
|
old_env = ENV["RAILS_ENV"]
|
|
|
|
@app ||= begin
|
|
|
|
ENV["RAILS_ENV"] = env
|
2015-09-27 17:34:13 -04:00
|
|
|
|
2017-09-08 20:48:15 -04:00
|
|
|
require "#{app_path}/config/environment"
|
2015-09-27 17:34:13 -04:00
|
|
|
|
2010-10-02 11:42:36 -04:00
|
|
|
Rails.application
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
ENV["RAILS_ENV"] = old_env
|
|
|
|
end
|
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
def extract_body(response)
|
2018-05-17 04:32:27 -04:00
|
|
|
(+"").tap do |body|
|
2016-08-16 03:30:11 -04:00
|
|
|
response[2].each { |chunk| body << chunk }
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(path)
|
|
|
|
@app.call(::Rack::MockRequest.env_for(path))
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_welcome(resp)
|
2016-01-25 11:26:20 -05:00
|
|
|
resp = Array(resp)
|
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
assert_equal 200, resp[0]
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_match "text/html", resp[1]["Content-Type"]
|
|
|
|
assert_match "charset=utf-8", resp[1]["Content-Type"]
|
2016-01-25 11:26:20 -05:00
|
|
|
assert extract_body(resp).match(/Yay! You.*re on Rails!/)
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Generation
|
2011-04-15 12:14:12 -04:00
|
|
|
# Build an application by invoking the generator and going through the whole stack.
|
2009-09-29 19:07:29 -04:00
|
|
|
def build_app(options = {})
|
2016-08-06 13:16:09 -04:00
|
|
|
@prev_rails_env = ENV["RAILS_ENV"]
|
2016-10-28 23:05:58 -04:00
|
|
|
ENV["RAILS_ENV"] = "development"
|
2011-06-06 08:54:05 -04:00
|
|
|
|
2009-09-29 19:07:29 -04:00
|
|
|
FileUtils.rm_rf(app_path)
|
2012-06-19 17:27:52 -04:00
|
|
|
FileUtils.cp_r(app_template_path, app_path)
|
2009-09-29 19:07:29 -04:00
|
|
|
|
|
|
|
# Delete the initializers unless requested
|
|
|
|
unless options[:initializers]
|
2016-05-28 10:11:20 -04:00
|
|
|
Dir["#{app_path}/config/initializers/**/*.rb"].each do |initializer|
|
2009-09-29 19:07:29 -04:00
|
|
|
File.delete(initializer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-21 19:03:20 -05:00
|
|
|
routes = File.read("#{app_path}/config/routes.rb")
|
2017-04-24 08:22:12 -04:00
|
|
|
if routes =~ /(\n\s*end\s*)\z/
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_path}/config/routes.rb", "w") do |f|
|
2016-03-01 03:48:53 -05:00
|
|
|
f.puts $` + "\nActiveSupport::Deprecation.silence { match ':controller(/:action(/:id))(.:format)', via: :all }\n" + $1
|
2009-12-21 19:03:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 14:23:59 -04:00
|
|
|
if options[:multi_db]
|
|
|
|
File.open("#{app_path}/config/database.yml", "w") do |f|
|
|
|
|
f.puts <<-YAML
|
|
|
|
default: &default
|
|
|
|
adapter: sqlite3
|
|
|
|
pool: 5
|
|
|
|
timeout: 5000
|
2019-03-18 16:23:00 -04:00
|
|
|
variables:
|
|
|
|
statement_timeout: 1000
|
2018-04-06 14:23:59 -04:00
|
|
|
development:
|
|
|
|
primary:
|
|
|
|
<<: *default
|
|
|
|
database: db/development.sqlite3
|
2018-08-31 10:55:37 -04:00
|
|
|
primary_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/development.sqlite3
|
|
|
|
replica: true
|
2018-04-06 14:23:59 -04:00
|
|
|
animals:
|
|
|
|
<<: *default
|
|
|
|
database: db/development_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
2018-08-31 10:55:37 -04:00
|
|
|
animals_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/development_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
|
|
|
replica: true
|
2018-04-06 14:23:59 -04:00
|
|
|
test:
|
|
|
|
primary:
|
|
|
|
<<: *default
|
|
|
|
database: db/test.sqlite3
|
2018-08-31 10:55:37 -04:00
|
|
|
primary_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/test.sqlite3
|
|
|
|
replica: true
|
2018-04-06 14:23:59 -04:00
|
|
|
animals:
|
|
|
|
<<: *default
|
|
|
|
database: db/test_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
2018-08-31 10:55:37 -04:00
|
|
|
animals_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/test_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
|
|
|
replica: true
|
2018-04-06 14:23:59 -04:00
|
|
|
production:
|
|
|
|
primary:
|
|
|
|
<<: *default
|
|
|
|
database: db/production.sqlite3
|
2018-08-31 10:55:37 -04:00
|
|
|
primary_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/production.sqlite3
|
|
|
|
replica: true
|
2018-04-06 14:23:59 -04:00
|
|
|
animals:
|
|
|
|
<<: *default
|
|
|
|
database: db/production_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
2018-08-31 10:55:37 -04:00
|
|
|
animals_readonly:
|
|
|
|
<<: *default
|
|
|
|
database: db/production_animals.sqlite3
|
|
|
|
migrations_paths: db/animals_migrate
|
|
|
|
readonly: true
|
2018-04-06 14:23:59 -04:00
|
|
|
YAML
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.open("#{app_path}/config/database.yml", "w") do |f|
|
|
|
|
f.puts <<-YAML
|
|
|
|
default: &default
|
|
|
|
adapter: sqlite3
|
|
|
|
pool: 5
|
|
|
|
timeout: 5000
|
|
|
|
development:
|
|
|
|
<<: *default
|
|
|
|
database: db/development.sqlite3
|
|
|
|
test:
|
|
|
|
<<: *default
|
|
|
|
database: db/test.sqlite3
|
|
|
|
production:
|
|
|
|
<<: *default
|
|
|
|
database: db/production.sqlite3
|
|
|
|
YAML
|
|
|
|
end
|
2013-12-24 03:26:34 -05:00
|
|
|
end
|
|
|
|
|
2012-03-14 13:36:15 -04:00
|
|
|
add_to_config <<-RUBY
|
2018-06-14 04:09:00 -04:00
|
|
|
config.hosts << proc { true }
|
2012-08-01 09:07:01 -04:00
|
|
|
config.eager_load = false
|
2012-10-14 06:03:39 -04:00
|
|
|
config.session_store :cookie_store, key: "_myapp_session"
|
2012-03-14 13:36:15 -04:00
|
|
|
config.active_support.deprecation = :log
|
|
|
|
config.action_controller.allow_forgery_protection = false
|
2014-11-24 18:39:11 -05:00
|
|
|
config.log_level = :info
|
2012-03-14 13:36:15 -04:00
|
|
|
RUBY
|
2009-10-14 19:13:45 -04:00
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown_app
|
2016-08-06 13:16:09 -04:00
|
|
|
ENV["RAILS_ENV"] = @prev_rails_env if @prev_rails_env
|
2017-08-07 00:31:14 -04:00
|
|
|
FileUtils.rm_rf(tmp_path)
|
2011-06-06 08:54:05 -04:00
|
|
|
end
|
|
|
|
|
2011-04-15 12:14:12 -04:00
|
|
|
# Make a very basic app, without creating the whole directory structure.
|
|
|
|
# This is faster and simpler than the method above.
|
2010-04-26 03:04:04 -04:00
|
|
|
def make_basic_app
|
|
|
|
require "rails"
|
|
|
|
require "action_controller/railtie"
|
2013-07-30 04:22:39 -04:00
|
|
|
require "action_view/railtie"
|
2010-04-26 03:04:04 -04:00
|
|
|
|
Add credentials using a generic EncryptedConfiguration class (#30067)
* WIP: Add credentials using a generic EncryptedConfiguration class
This is sketch code so far.
* Flesh out EncryptedConfiguration and test it
* Better name
* Add command and generator for credentials
* Use the Pathnames
* Extract EncryptedFile from EncryptedConfiguration and add serializers
* Test EncryptedFile
* Extract serializer validation
* Stress the point about losing comments
* Allow encrypted configuration to be read without parsing for display
* Use credentials by default and base them on the master key
* Derive secret_key_base in test/dev, source it from credentials in other envs
And document the usage.
* Document the new credentials setup
* Stop generating the secrets.yml file now that we have credentials
* Document what we should have instead
Still need to make it happen, tho.
* [ci skip] Keep wording to `key base`; prefer defaults.
Usually we say we change defaults, not "spec" out a release.
Can't use backticks in our sdoc generated documentation either.
* Abstract away OpenSSL; prefer MessageEncryptor.
* Spare needless new when raising.
* Encrypted file test shouldn't depend on subclass.
* [ci skip] Some woordings.
* Ditch serializer future coding.
* I said flip it. Flip it good.
* [ci skip] Move require_master_key to the real production.rb.
* Add require_master_key to abort the boot process.
In case the master key is required in a certain environment
we should inspect that the key is there and abort if it isn't.
* Print missing key message and exit immediately.
Spares us a lengthy backtrace and prevents further execution.
I've verified the behavior in a test app, but couldn't figure the
test out as loading the app just exits immediately with:
```
/Users/kasperhansen/Documents/code/rails/activesupport/lib/active_support/testing/isolation.rb:23:in `load': marshal data too short (ArgumentError)
from /Users/kasperhansen/Documents/code/rails/activesupport/lib/active_support/testing/isolation.rb:23:in `run'
from /Users/kasperhansen/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:830:in `run_one_method'
from /Users/kasperhansen/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest/parallel.rb:32:in `block (2 levels) in start'
```
It's likely we need to capture and prevent the exit somehow.
Kernel.stub(:exit) didn't work. Leaving it for tomorrow.
* Fix require_master_key config test.
Loading the app would trigger the `exit 1` per require_master_key's
semantics, which then aborted the test.
Fork and wait for the child process to finish, then inspect the
exit status.
Also check we aborted because of a missing master key, so something
else didn't just abort the boot.
Much <3 to @tenderlove for the tip.
* Support reading/writing configs via methods.
* Skip needless deep symbolizing.
* Remove save; test config reader elsewhere.
* Move secret_key_base check to when we're reading it.
Otherwise we'll abort too soon since we don't assign the secret_key_base
to secrets anymore.
* Add missing string literal comments; require unneeded yaml require.
* ya ya ya, rubocop.
* Add master_key/credentials after bundle.
Then we can reuse the existing message on `rails new bc4`.
It'll look like:
```
Using web-console 3.5.1 from https://github.com/rails/web-console.git (at master@ce985eb)
Using rails 5.2.0.alpha from source at `/Users/kasperhansen/Documents/code/rails`
Using sass-rails 5.0.6
Bundle complete! 16 Gemfile dependencies, 72 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Adding config/master.key to store the master encryption key: 97070158c44b4675b876373a6bc9d5a0
Save this in a password manager your team can access.
If you lose the key, no one, including you, can access anything encrypted with it.
create config/master.key
```
And that'll be executed even if `--skip-bundle` was passed.
* Ensure test app has secret_key_base.
* Assign secret_key_base to app or omit.
* Merge noise
* Split options for dynamic delegation into its own method and use deep symbols to make it work
* Update error to point to credentials instead
* Appease Rubocop
* Validate secret_key_base when reading it.
Instead of relying on the validation in key_generator move that into
secret_key_base itself.
* Fix generator and secrets test.
Manually add config.read_encrypted_secrets since it's not there by default
anymore.
Move mentions of config/secrets.yml to config/credentials.yml.enc.
* Remove files I have no idea how they got here.
* [ci skip] swap secrets for credentials.
* [ci skip] And now, changelogs are coming.
2017-09-11 14:21:20 -04:00
|
|
|
@app = Class.new(Rails::Application) do
|
|
|
|
def self.name; "RailtiesTestApp"; end
|
|
|
|
end
|
2018-06-14 04:09:00 -04:00
|
|
|
@app.config.hosts << proc { true }
|
2015-09-27 17:34:13 -04:00
|
|
|
@app.config.eager_load = false
|
|
|
|
@app.config.session_store :cookie_store, key: "_myapp_session"
|
|
|
|
@app.config.active_support.deprecation = :log
|
|
|
|
@app.config.log_level = :info
|
2019-03-10 19:37:46 -04:00
|
|
|
@app.secrets.secret_key_base = "b3c631c314c0bbca50c1b2843150fe33"
|
2010-04-26 03:04:04 -04:00
|
|
|
|
2015-09-27 17:34:13 -04:00
|
|
|
yield @app if block_given?
|
|
|
|
@app.initialize!
|
2010-04-26 03:04:04 -04:00
|
|
|
|
2015-09-27 17:34:13 -04:00
|
|
|
@app.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get "/" => "omg#index"
|
2010-04-26 03:04:04 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2010-04-26 03:04:04 -04:00
|
|
|
extend ::Rack::Test::Methods
|
|
|
|
end
|
|
|
|
|
2010-10-02 11:42:36 -04:00
|
|
|
def simple_controller
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2010-10-02 11:42:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get ':controller(/:action)'
|
2010-10-02 11:42:36 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2009-11-06 20:21:39 -05:00
|
|
|
class Bukkit
|
2010-01-26 08:58:00 -05:00
|
|
|
attr_reader :path
|
|
|
|
|
2009-11-06 20:21:39 -05:00
|
|
|
def initialize(path)
|
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
def write(file, string)
|
|
|
|
path = "#{@path}/#{file}"
|
|
|
|
FileUtils.mkdir_p(File.dirname(path))
|
2016-08-16 03:30:11 -04:00
|
|
|
File.open(path, "w") { |f| f.puts string }
|
2009-11-06 20:21:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete(file)
|
|
|
|
File.delete("#{@path}/#{file}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-26 08:58:00 -05:00
|
|
|
def engine(name)
|
|
|
|
dir = "#{app_path}/random/#{name}"
|
|
|
|
FileUtils.mkdir_p(dir)
|
|
|
|
|
|
|
|
app = File.readlines("#{app_path}/config/application.rb")
|
2017-08-14 13:57:45 -04:00
|
|
|
app.insert(4, "$:.unshift(\"#{dir}/lib\")")
|
|
|
|
app.insert(5, "require #{name.inspect}")
|
2010-01-26 08:58:00 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_path}/config/application.rb", "r+") do |f|
|
2010-01-26 08:58:00 -05:00
|
|
|
f.puts app
|
|
|
|
end
|
|
|
|
|
2009-11-06 20:21:39 -05:00
|
|
|
Bukkit.new(dir).tap do |bukkit|
|
|
|
|
yield bukkit if block_given?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
# Invoke a bin/rails command inside the app
|
|
|
|
#
|
2017-10-18 01:31:49 -04:00
|
|
|
# allow_failure:: true to return normally if the command exits with
|
2017-09-03 12:55:26 -04:00
|
|
|
# a non-zero status. By default, this method will raise.
|
|
|
|
# stderr:: true to pass STDERR output straight to the "real" STDERR.
|
|
|
|
# By default, the STDERR and STDOUT of the process will be
|
|
|
|
# combined in the returned string.
|
2019-08-03 19:32:41 -04:00
|
|
|
def rails(*args, allow_failure: false, stderr: false)
|
2017-09-03 12:55:26 -04:00
|
|
|
args = args.flatten
|
2017-09-07 17:56:20 -04:00
|
|
|
fork = true
|
2017-09-03 12:55:26 -04:00
|
|
|
|
|
|
|
command = "bin/rails #{Shellwords.join args}#{' 2>&1' unless stderr}"
|
|
|
|
|
|
|
|
# Don't fork if the environment has disabled it
|
|
|
|
fork = false if ENV["NO_FORK"]
|
|
|
|
|
|
|
|
# Don't fork if the runtime isn't able to
|
|
|
|
fork = false if !Process.respond_to?(:fork)
|
|
|
|
|
|
|
|
# Don't fork if we're re-invoking minitest
|
|
|
|
fork = false if args.first == "t" || args.grep(/\Atest(:|\z)/).any?
|
|
|
|
|
|
|
|
if fork
|
|
|
|
out_read, out_write = IO.pipe
|
|
|
|
if stderr
|
|
|
|
err_read, err_write = IO.pipe
|
|
|
|
else
|
|
|
|
err_write = out_write
|
|
|
|
end
|
|
|
|
|
|
|
|
pid = fork do
|
|
|
|
out_read.close
|
|
|
|
err_read.close if err_read
|
|
|
|
|
2019-08-03 19:32:41 -04:00
|
|
|
$stdin.reopen(File::NULL, "r")
|
2017-09-03 12:55:26 -04:00
|
|
|
$stdout.reopen(out_write)
|
|
|
|
$stderr.reopen(err_write)
|
|
|
|
|
|
|
|
at_exit do
|
|
|
|
case $!
|
|
|
|
when SystemExit
|
|
|
|
exit! $!.status
|
|
|
|
when nil
|
|
|
|
exit! 0
|
|
|
|
else
|
|
|
|
err_write.puts "#{$!.class}: #{$!}"
|
|
|
|
exit! 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Rails.instance_variable_set :@_env, nil
|
|
|
|
|
|
|
|
$-v = $-w = false
|
|
|
|
Dir.chdir app_path unless Dir.pwd == app_path
|
|
|
|
|
|
|
|
ARGV.replace(args)
|
|
|
|
load "./bin/rails"
|
|
|
|
|
|
|
|
exit! 0
|
|
|
|
end
|
|
|
|
|
|
|
|
out_write.close
|
|
|
|
|
|
|
|
if err_read
|
|
|
|
err_write.close
|
|
|
|
|
|
|
|
$stderr.write err_read.read
|
|
|
|
end
|
|
|
|
|
|
|
|
output = out_read.read
|
|
|
|
|
|
|
|
Process.waitpid pid
|
|
|
|
|
|
|
|
else
|
|
|
|
output = `cd #{app_path}; #{command}`
|
2009-10-21 18:45:11 -04:00
|
|
|
end
|
2017-09-03 12:55:26 -04:00
|
|
|
|
|
|
|
raise "rails command failed (#{$?.exitstatus}): #{command}\n#{output}" unless allow_failure || $?.success?
|
|
|
|
|
|
|
|
output
|
2009-10-21 18:45:11 -04:00
|
|
|
end
|
|
|
|
|
2014-11-04 17:14:03 -05:00
|
|
|
def add_to_top_of_config(str)
|
|
|
|
environment = File.read("#{app_path}/config/application.rb")
|
|
|
|
if environment =~ /(Rails::Application\s*)/
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_path}/config/application.rb", "w") do |f|
|
2014-11-04 17:14:03 -05:00
|
|
|
f.puts $` + $1 + "\n#{str}\n" + $'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-14 19:13:45 -04:00
|
|
|
def add_to_config(str)
|
2009-10-15 17:50:02 -04:00
|
|
|
environment = File.read("#{app_path}/config/application.rb")
|
2017-04-24 08:22:12 -04:00
|
|
|
if environment =~ /(\n\s*end\s*end\s*)\z/
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_path}/config/application.rb", "w") do |f|
|
2009-10-14 19:13:45 -04:00
|
|
|
f.puts $` + "\n#{str}\n" + $1
|
2011-09-23 19:56:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_to_env_config(env, str)
|
|
|
|
environment = File.read("#{app_path}/config/environments/#{env}.rb")
|
2017-04-24 08:22:12 -04:00
|
|
|
if environment =~ /(\n\s*end\s*)\z/
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_path}/config/environments/#{env}.rb", "w") do |f|
|
2011-09-23 19:56:49 -04:00
|
|
|
f.puts $` + "\n#{str}\n" + $1
|
2009-09-29 19:07:29 -04:00
|
|
|
end
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
2010-11-18 14:07:23 -05:00
|
|
|
def remove_from_config(str)
|
2016-02-09 19:31:00 -05:00
|
|
|
remove_from_file("#{app_path}/config/application.rb", str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_from_env_config(env, str)
|
|
|
|
remove_from_file("#{app_path}/config/environments/#{env}.rb", str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_from_file(file, str)
|
2010-11-18 15:10:37 -05:00
|
|
|
contents = File.read(file)
|
2016-08-06 13:16:09 -04:00
|
|
|
contents.sub!(/#{str}/, "")
|
2016-02-09 19:31:00 -05:00
|
|
|
File.write(file, contents)
|
2010-11-18 14:07:23 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
def app_file(path, contents, mode = "w")
|
2017-12-06 20:33:16 -05:00
|
|
|
file_name = "#{app_path}/#{path}"
|
|
|
|
FileUtils.mkdir_p File.dirname(file_name)
|
|
|
|
File.open(file_name, mode) do |f|
|
2009-09-25 22:32:28 -04:00
|
|
|
f.puts contents
|
|
|
|
end
|
2017-12-06 20:33:16 -05:00
|
|
|
file_name
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
2019-02-11 15:44:25 -05:00
|
|
|
def app_dir(path)
|
|
|
|
FileUtils.mkdir_p("#{app_path}/#{path}")
|
|
|
|
end
|
|
|
|
|
2011-06-21 10:18:50 -04:00
|
|
|
def remove_file(path)
|
|
|
|
FileUtils.rm_rf "#{app_path}/#{path}"
|
|
|
|
end
|
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
def controller(name, contents)
|
|
|
|
app_file("app/controllers/#{name}_controller.rb", contents)
|
|
|
|
end
|
2009-09-29 19:07:29 -04:00
|
|
|
|
2009-12-22 20:03:23 -05:00
|
|
|
def use_frameworks(arr)
|
2018-12-24 15:16:22 -05:00
|
|
|
to_remove = [:actionmailer, :activerecord, :activestorage, :activejob, :actionmailbox] - arr
|
2014-08-19 21:37:18 -04:00
|
|
|
|
|
|
|
if to_remove.include?(:activerecord)
|
2016-08-06 13:16:09 -04:00
|
|
|
remove_from_config "config.active_record.*"
|
2014-08-19 21:37:18 -04:00
|
|
|
end
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
$:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' }
|
2009-12-22 20:03:23 -05:00
|
|
|
end
|
2017-12-01 04:16:06 -05:00
|
|
|
|
2019-06-03 09:55:37 -04:00
|
|
|
def use_postgresql(multi_db: false)
|
|
|
|
if multi_db
|
|
|
|
File.open("#{app_path}/config/database.yml", "w") do |f|
|
|
|
|
f.puts <<-YAML
|
|
|
|
default: &default
|
|
|
|
adapter: postgresql
|
|
|
|
pool: 5
|
|
|
|
development:
|
|
|
|
primary:
|
|
|
|
<<: *default
|
|
|
|
database: railties_test
|
|
|
|
animals:
|
|
|
|
<<: *default
|
|
|
|
database: railties_animals_test
|
|
|
|
migrations_paths: db/animals_migrate
|
|
|
|
YAML
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.open("#{app_path}/config/database.yml", "w") do |f|
|
|
|
|
f.puts <<-YAML
|
|
|
|
default: &default
|
|
|
|
adapter: postgresql
|
|
|
|
pool: 5
|
|
|
|
database: railties_test
|
|
|
|
development:
|
|
|
|
<<: *default
|
|
|
|
test:
|
|
|
|
<<: *default
|
|
|
|
YAML
|
|
|
|
end
|
2017-12-01 04:16:06 -05:00
|
|
|
end
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
2019-02-18 14:06:28 -05:00
|
|
|
|
|
|
|
module Reload
|
|
|
|
def reload
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
end
|
|
|
|
end
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
2012-01-05 20:30:17 -05:00
|
|
|
class ActiveSupport::TestCase
|
2009-09-25 22:32:28 -04:00
|
|
|
include TestHelpers::Paths
|
|
|
|
include TestHelpers::Rack
|
|
|
|
include TestHelpers::Generation
|
2019-02-18 14:06:28 -05:00
|
|
|
include TestHelpers::Reload
|
2015-01-15 01:42:33 -05:00
|
|
|
include ActiveSupport::Testing::Stream
|
2019-08-02 00:24:21 -04:00
|
|
|
include ActiveSupport::Testing::MethodCallAssertions
|
2009-09-25 22:32:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Create a scope and build a fixture rails app
|
|
|
|
Module.new do
|
|
|
|
extend TestHelpers::Paths
|
2012-06-29 09:25:47 -04:00
|
|
|
|
2009-09-25 22:32:28 -04:00
|
|
|
# Build a rails app
|
2012-06-29 09:25:47 -04:00
|
|
|
FileUtils.rm_rf(app_template_path)
|
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps
* Stop including coffee-rails by default
* Drop using a js_compressor by default
* Drop extra test for coffeescript inclusion by default
* Stick with skip_javascript to signify skipping webpack
* Don't install a JS runtime by default any more
* app/javascript will be the new default directory for JS
* Make it clear that this is just for configuring the default Webpack framework setup now
* Start using the Webpack tag in the default layout
* Irrelevant test
* jQuery is long gone
* Stop having asset pipeline compile default application.js
* Add rails-ujs by default to the Webpack setup
* Add Active Storage JavaScript to application.js pack by default
* Consistent quoting
* Add Turbolinks to default pack
* Add Action Cable to default pack
Need some work on how to set the global consumer that channels will
work with. @javan?
* Require all channels by default and use a separate consumer stub
* Channel generator now targets Webpack style
* Update task docs to match new generator style
* Use uniform import style
* Drop the JS assets generator
It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!
* Add app/javascript to the stats directories
* Simpler import style
Which match the other imports.
* Address test failures from dropping JS compilation (and compression)
* webpacker-default: Modify `AssetsGeneratorTest`
Before:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201
F
Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10
.
Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```
After:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571
..
Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```
* webpacker-default: Modify `ChannelGeneratorTest`
Before:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986
.F
Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34
.F
Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22
E
Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60
F
Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80
F
Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68
Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```
After:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857
.......
Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```
* Fix shared generator tests.
* webpacker-default: Modify `ControllerGeneratorTest`
The JS assets generator was dropped. ref. https://github.com/rails/rails/commit/46215b179483d3e4d264555f5a4952f43eb8142a
* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.
This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.
* require webpacker in test app
* Add webpacker without making the build hang/timeout. (#33640)
* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required
* no longer need to have webpacker in env templates as webpacker moved this config to yml file
* Fix rubocop violation
* Got the test passing for the running scaffold
* update expected lines of code
* update middleware tests to account for webpacker
* disable js in plugins be default to get the tests passing (#34009)
* clear codeclimate report issues
* Anything newer than currently released is good
* Use Webpacker development version during development of Rails
* Edge should get development webpacker as well
* Add changelog entry for Webpacker change
2018-10-01 01:31:21 -04:00
|
|
|
FileUtils.mkdir_p(app_template_path)
|
|
|
|
|
2019-02-06 20:10:27 -05:00
|
|
|
`#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install`
|
2016-08-06 13:16:09 -04:00
|
|
|
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
|
2009-12-31 15:28:48 -05:00
|
|
|
f.puts "require 'rails/all'"
|
2009-10-21 18:45:11 -04:00
|
|
|
end
|
2017-09-02 14:45:25 -04:00
|
|
|
|
2019-03-07 21:33:00 -05:00
|
|
|
unless File.exist?("#{RAILS_FRAMEWORK_ROOT}/actionview/lib/assets/compiled/rails-ujs.js")
|
|
|
|
Dir.chdir("#{RAILS_FRAMEWORK_ROOT}/actionview") { `yarn build` }
|
|
|
|
end
|
|
|
|
|
2019-02-06 20:10:27 -05:00
|
|
|
assets_path = "#{RAILS_FRAMEWORK_ROOT}/railties/test/isolation/assets"
|
2019-03-07 21:33:00 -05:00
|
|
|
unless Dir.exist?("#{assets_path}/node_modules")
|
|
|
|
Dir.chdir(assets_path) { `yarn install` }
|
|
|
|
end
|
2019-02-06 20:10:27 -05:00
|
|
|
FileUtils.cp("#{assets_path}/package.json", "#{app_template_path}/package.json")
|
|
|
|
FileUtils.cp("#{assets_path}/config/webpacker.yml", "#{app_template_path}/config/webpacker.yml")
|
|
|
|
FileUtils.cp_r("#{assets_path}/config/webpack", "#{app_template_path}/config/webpack")
|
|
|
|
FileUtils.ln_s("#{assets_path}/node_modules", "#{app_template_path}/node_modules")
|
|
|
|
FileUtils.chdir(app_template_path) { `bin/rails webpacker:binstubs` }
|
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps
* Stop including coffee-rails by default
* Drop using a js_compressor by default
* Drop extra test for coffeescript inclusion by default
* Stick with skip_javascript to signify skipping webpack
* Don't install a JS runtime by default any more
* app/javascript will be the new default directory for JS
* Make it clear that this is just for configuring the default Webpack framework setup now
* Start using the Webpack tag in the default layout
* Irrelevant test
* jQuery is long gone
* Stop having asset pipeline compile default application.js
* Add rails-ujs by default to the Webpack setup
* Add Active Storage JavaScript to application.js pack by default
* Consistent quoting
* Add Turbolinks to default pack
* Add Action Cable to default pack
Need some work on how to set the global consumer that channels will
work with. @javan?
* Require all channels by default and use a separate consumer stub
* Channel generator now targets Webpack style
* Update task docs to match new generator style
* Use uniform import style
* Drop the JS assets generator
It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!
* Add app/javascript to the stats directories
* Simpler import style
Which match the other imports.
* Address test failures from dropping JS compilation (and compression)
* webpacker-default: Modify `AssetsGeneratorTest`
Before:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201
F
Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10
.
Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```
After:
```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571
..
Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```
* webpacker-default: Modify `ChannelGeneratorTest`
Before:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986
.F
Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34
.F
Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22
E
Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60
F
Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80
F
Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not
bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68
Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```
After:
```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857
.......
Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```
* Fix shared generator tests.
* webpacker-default: Modify `ControllerGeneratorTest`
The JS assets generator was dropped. ref. https://github.com/rails/rails/commit/46215b179483d3e4d264555f5a4952f43eb8142a
* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.
This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.
* require webpacker in test app
* Add webpacker without making the build hang/timeout. (#33640)
* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required
* no longer need to have webpacker in env templates as webpacker moved this config to yml file
* Fix rubocop violation
* Got the test passing for the running scaffold
* update expected lines of code
* update middleware tests to account for webpacker
* disable js in plugins be default to get the tests passing (#34009)
* clear codeclimate report issues
* Anything newer than currently released is good
* Use Webpacker development version during development of Rails
* Edge should get development webpacker as well
* Add changelog entry for Webpacker change
2018-10-01 01:31:21 -04:00
|
|
|
|
2017-09-02 14:45:25 -04:00
|
|
|
# Fake 'Bundler.require' -- we run using the repo's Gemfile, not an
|
|
|
|
# app-specific one: we don't want to require every gem that lists.
|
|
|
|
contents = File.read("#{app_template_path}/config/application.rb")
|
2019-02-13 13:41:28 -05:00
|
|
|
contents.sub!(/^Bundler\.require.*/, "%w(turbolinks webpacker).each { |r| require r }")
|
2017-09-02 14:45:25 -04:00
|
|
|
File.write("#{app_template_path}/config/application.rb", contents)
|
|
|
|
|
|
|
|
require "rails"
|
|
|
|
|
|
|
|
require "active_model"
|
|
|
|
require "active_job"
|
|
|
|
require "active_record"
|
|
|
|
require "action_controller"
|
|
|
|
require "action_mailer"
|
|
|
|
require "action_view"
|
|
|
|
require "active_storage"
|
|
|
|
require "action_cable"
|
2019-01-24 22:06:19 -05:00
|
|
|
require "action_mailbox"
|
|
|
|
require "action_text"
|
2017-09-02 14:45:25 -04:00
|
|
|
require "sprockets"
|
2017-09-03 03:40:14 -04:00
|
|
|
|
|
|
|
require "action_view/helpers"
|
|
|
|
require "action_dispatch/routing/route_set"
|
2011-06-07 06:16:05 -04:00
|
|
|
end unless defined?(RAILS_ISOLATED_ENGINE)
|