2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-04-26 03:36:13 -04:00
|
|
|
require "isolation/abstract_unit"
|
2017-09-03 12:55:26 -04:00
|
|
|
require "env_helpers"
|
2010-04-26 03:36:13 -04:00
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class RakeTest < ActiveSupport::TestCase
|
2017-09-03 12:55:26 -04:00
|
|
|
include ActiveSupport::Testing::Isolation, EnvHelpers
|
2010-04-26 03:36:13 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
2010-06-19 11:51:29 -04:00
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2010-04-26 03:36:13 -04:00
|
|
|
def test_gems_tasks_are_loaded_first_than_application_ones
|
|
|
|
app_file "lib/tasks/app.rake", <<-RUBY
|
|
|
|
$task_loaded = Rake::Task.task_defined?("db:create:all")
|
|
|
|
RUBY
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-04-26 03:36:13 -04:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
::Rails.application.load_tasks
|
|
|
|
assert $task_loaded
|
|
|
|
end
|
2010-04-29 02:39:44 -04:00
|
|
|
|
2016-03-04 20:37:30 -05:00
|
|
|
test "task is protected when previous migration was production" do
|
2017-09-03 12:55:26 -04:00
|
|
|
with_rails_env "production" do
|
|
|
|
rails "generate", "model", "product", "name:string"
|
|
|
|
rails "db:create", "db:migrate"
|
|
|
|
output = rails("db:test:prepare", allow_failure: true)
|
2015-08-14 12:31:33 -04:00
|
|
|
|
2016-01-10 22:31:12 -05:00
|
|
|
assert_match(/ActiveRecord::ProtectedEnvironmentError/, output)
|
2015-08-14 12:31:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_not_protected_when_previous_migration_was_not_production
|
2017-09-03 12:55:26 -04:00
|
|
|
with_rails_env "test" do
|
|
|
|
rails "generate", "model", "product", "name:string"
|
|
|
|
rails "db:create", "db:migrate"
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:test:prepare", "test")
|
2015-08-14 12:31:33 -04:00
|
|
|
|
2018-04-03 21:34:51 -04:00
|
|
|
assert_no_match(/ActiveRecord::ProtectedEnvironmentError/, output)
|
2015-08-14 12:31:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-29 02:39:44 -04:00
|
|
|
def test_environment_is_required_in_rake_tasks
|
|
|
|
app_file "config/environment.rb", <<-RUBY
|
|
|
|
SuperMiddleware = Struct.new(:app)
|
|
|
|
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.configure do
|
2010-04-29 02:39:44 -04:00
|
|
|
config.middleware.use SuperMiddleware
|
|
|
|
end
|
|
|
|
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.initialize!
|
2010-04-29 02:39:44 -04:00
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
assert_match("SuperMiddleware", rails("middleware"))
|
2010-04-29 02:39:44 -04:00
|
|
|
end
|
2010-09-24 09:06:35 -04:00
|
|
|
|
2010-11-18 11:19:29 -05:00
|
|
|
def test_initializers_are_executed_in_rake_tasks
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
initializer "do_something" do
|
|
|
|
puts "Doing something..."
|
|
|
|
end
|
|
|
|
|
|
|
|
rake_tasks do
|
2012-10-14 06:03:39 -04:00
|
|
|
task do_nothing: :environment do
|
2010-11-18 11:19:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("do_nothing")
|
2010-11-18 11:19:29 -05:00
|
|
|
assert_match "Doing something...", output
|
|
|
|
end
|
|
|
|
|
2013-07-09 16:36:50 -04:00
|
|
|
def test_does_not_explode_when_accessing_a_model
|
2012-08-01 09:07:01 -04:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
rake_tasks do
|
2012-10-14 06:03:39 -04:00
|
|
|
task do_nothing: :environment do
|
2012-08-01 09:07:01 -04:00
|
|
|
Hello.new.world
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "app/models/hello.rb", <<-RUBY
|
2013-07-09 16:36:50 -04:00
|
|
|
class Hello
|
|
|
|
def world
|
|
|
|
puts 'Hello world'
|
|
|
|
end
|
2012-08-01 09:07:01 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("do_nothing")
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_match "Hello world", output
|
2012-08-01 09:07:01 -04:00
|
|
|
end
|
|
|
|
|
2013-07-09 16:36:50 -04:00
|
|
|
def test_should_not_eager_load_model_for_rake
|
2013-04-11 06:10:54 -04:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
rake_tasks do
|
|
|
|
task do_nothing: :environment do
|
2017-09-14 05:28:57 -04:00
|
|
|
puts 'There is nothing'
|
2013-04-11 06:10:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
add_to_env_config "production", <<-RUBY
|
2013-07-09 16:36:50 -04:00
|
|
|
config.eager_load = true
|
2013-04-11 06:10:54 -04:00
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "app/models/hello.rb", <<-RUBY
|
2013-07-09 16:36:50 -04:00
|
|
|
raise 'should not be pre-required for rake even eager_load=true'
|
|
|
|
RUBY
|
|
|
|
|
2017-09-14 05:28:57 -04:00
|
|
|
output = rails("do_nothing", "RAILS_ENV=production")
|
|
|
|
assert_match "There is nothing", output
|
2013-04-11 06:10:54 -04:00
|
|
|
end
|
|
|
|
|
2010-09-24 09:06:35 -04:00
|
|
|
def test_code_statistics_sanity
|
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
|
|
|
assert_match "Code LOC: 32 Test LOC: 0 Code to Test Ratio: 1:0.0",
|
2017-09-03 12:55:26 -04:00
|
|
|
rails("stats")
|
2010-09-24 09:06:35 -04:00
|
|
|
end
|
2010-11-09 00:10:39 -05:00
|
|
|
|
2011-05-05 16:51:29 -04:00
|
|
|
def test_logger_is_flushed_when_exiting_production_rake_tasks
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
rake_tasks do
|
2012-10-14 06:03:39 -04:00
|
|
|
task log_something: :environment do
|
2011-05-05 16:51:29 -04:00
|
|
|
Rails.logger.error("Sample log message")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "log_something", "RAILS_ENV=production"
|
|
|
|
assert_match "Sample log message", File.read("#{app_path}/log/production.log")
|
2011-05-05 16:51:29 -04:00
|
|
|
end
|
|
|
|
|
2011-01-12 18:18:45 -05:00
|
|
|
def test_loading_specific_fixtures
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "model", "product", "name:string"
|
|
|
|
rails "db:migrate"
|
2011-01-12 18:18:45 -05:00
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
2011-06-06 08:54:05 -04:00
|
|
|
|
2011-01-12 18:18:45 -05:00
|
|
|
# loading a specific fixture
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "db:fixtures:load", "FIXTURES=products"
|
2011-01-12 18:18:45 -05:00
|
|
|
|
|
|
|
assert_equal 2, ::AppTemplate::Application::Product.count
|
|
|
|
assert_equal 0, ::AppTemplate::Application::User.count
|
|
|
|
end
|
2011-07-07 17:58:04 -04:00
|
|
|
|
2012-06-16 13:37:00 -04:00
|
|
|
def test_loading_only_yml_fixtures
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "db:migrate"
|
2012-06-16 13:37:00 -04:00
|
|
|
|
|
|
|
app_file "test/fixtures/products.csv", ""
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "db:fixtures:load"
|
2012-06-16 13:37:00 -04:00
|
|
|
end
|
|
|
|
|
2011-07-07 17:58:04 -04:00
|
|
|
def test_scaffold_tests_pass_by_default
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "scaffold", "user", "username:string", "password:string"
|
2017-09-14 05:28:57 -04:00
|
|
|
with_rails_env("test") { rails("db:migrate") }
|
|
|
|
output = rails("test")
|
2011-07-07 17:58:04 -04:00
|
|
|
|
2016-05-28 16:26:45 -04:00
|
|
|
assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output)
|
2012-03-14 13:36:15 -04:00
|
|
|
assert_no_match(/Errors running/, output)
|
|
|
|
end
|
|
|
|
|
2015-04-19 18:22:14 -04:00
|
|
|
def test_api_scaffold_tests_pass_by_default
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.api_only = true
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/controllers/application_controller.rb", <<-RUBY
|
|
|
|
class ApplicationController < ActionController::API
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "scaffold", "user", "username:string", "password:string"
|
2017-09-14 05:28:57 -04:00
|
|
|
with_rails_env("test") { rails("db:migrate") }
|
|
|
|
output = rails("test")
|
2015-04-19 18:22:14 -04:00
|
|
|
|
2015-06-11 19:24:39 -04:00
|
|
|
assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output)
|
2015-04-19 18:22:14 -04:00
|
|
|
assert_no_match(/Errors running/, output)
|
|
|
|
end
|
|
|
|
|
2016-02-05 22:15:28 -05:00
|
|
|
def test_scaffold_with_references_columns_tests_pass_by_default
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "Product"
|
|
|
|
rails "generate", "model", "Cart"
|
|
|
|
rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to"
|
2017-09-14 05:28:57 -04:00
|
|
|
with_rails_env("test") { rails("db:migrate") }
|
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
|
|
|
rails("webpacker:compile")
|
2017-09-14 05:28:57 -04:00
|
|
|
output = rails("test")
|
2012-12-09 22:35:03 -05:00
|
|
|
|
2016-05-28 16:26:45 -04:00
|
|
|
assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output)
|
2012-12-09 22:35:03 -05:00
|
|
|
assert_no_match(/Errors running/, output)
|
|
|
|
end
|
|
|
|
|
2012-06-25 13:40:06 -04:00
|
|
|
def test_db_test_prepare_when_using_sql_format
|
|
|
|
add_to_config "config.active_record.schema_format = :sql"
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "scaffold", "user", "username:string"
|
|
|
|
rails "db:migrate"
|
2017-09-14 05:42:49 -04:00
|
|
|
output = rails("db:test:prepare", "--trace")
|
2012-06-25 13:40:06 -04:00
|
|
|
assert_match(/Execute db:test:load_structure/, output)
|
|
|
|
end
|
|
|
|
|
2011-12-18 14:43:36 -05:00
|
|
|
def test_rake_dump_structure_should_respect_db_structure_env_variable
|
2017-09-03 12:55:26 -04:00
|
|
|
# ensure we have a schema_migrations table to dump
|
|
|
|
rails "db:migrate", "db:structure:dump", "SCHEMA=db/my_structure.sql"
|
2016-08-06 13:16:09 -04:00
|
|
|
assert File.exist?(File.join(app_path, "db", "my_structure.sql"))
|
2011-12-18 14:43:36 -05:00
|
|
|
end
|
2012-02-29 11:01:12 -05:00
|
|
|
|
2012-03-17 00:57:10 -04:00
|
|
|
def test_rake_dump_structure_should_be_called_twice_when_migrate_redo
|
|
|
|
add_to_config "config.active_record.schema_format = :sql"
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "g", "model", "post", "title:string"
|
|
|
|
output = rails("db:migrate:redo", "--trace")
|
2012-03-17 00:57:10 -04:00
|
|
|
|
|
|
|
# expect only Invoke db:structure:dump (first_time)
|
|
|
|
assert_no_match(/^\*\* Invoke db:structure:dump\s+$/, output)
|
|
|
|
end
|
|
|
|
|
2012-02-29 11:01:12 -05:00
|
|
|
def test_rake_dump_schema_cache
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "post", "title:string"
|
|
|
|
rails "generate", "model", "product", "name:string"
|
|
|
|
rails "db:migrate", "db:schema:cache:dump"
|
2016-11-13 22:18:14 -05:00
|
|
|
assert File.exist?(File.join(app_path, "db", "schema_cache.yml"))
|
2012-02-29 11:01:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rake_clear_schema_cache
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "db:schema:cache:dump", "db:schema:cache:clear"
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not File.exist?(File.join(app_path, "db", "schema_cache.yml"))
|
2012-02-29 11:01:12 -05:00
|
|
|
end
|
2012-05-28 11:10:04 -04:00
|
|
|
|
2012-06-10 10:26:55 -04:00
|
|
|
def test_copy_templates
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "app:templates:copy"
|
|
|
|
%w(controller mailer scaffold).each do |dir|
|
|
|
|
assert File.exist?(File.join(app_path, "lib", "templates", "erb", dir))
|
|
|
|
end
|
|
|
|
%w(controller helper scaffold_controller assets).each do |dir|
|
|
|
|
assert File.exist?(File.join(app_path, "lib", "templates", "rails", dir))
|
2012-06-10 10:26:55 -04:00
|
|
|
end
|
|
|
|
end
|
2014-03-08 09:51:49 -05:00
|
|
|
|
|
|
|
def test_template_load_initializers
|
|
|
|
app_file "config/initializers/dummy.rb", "puts 'Hello, World!'"
|
|
|
|
app_file "template.rb", ""
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("app:template", "LOCATION=template.rb")
|
2014-03-08 09:51:49 -05:00
|
|
|
assert_match(/Hello, World!/, output)
|
|
|
|
end
|
2010-04-26 03:36:13 -04:00
|
|
|
end
|
2011-09-09 21:50:32 -04:00
|
|
|
end
|