2010-04-26 03:36:13 -04:00
|
|
|
require "isolation/abstract_unit"
|
2013-02-18 19:26:25 -05:00
|
|
|
require "active_support/core_ext/string/strip"
|
2010-04-26 03:36:13 -04:00
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class RakeTest < ActiveSupport::TestCase
|
2010-04-26 03:36:13 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
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
|
2015-08-14 12:31:33 -04:00
|
|
|
Dir.chdir(app_path) do
|
|
|
|
output = `bin/rails generate model product name:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
env RAILS_ENV=production bin/rails db:create db:migrate;
|
|
|
|
env RAILS_ENV=production bin/rails db:test:prepare test 2>&1`
|
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
|
|
|
|
Dir.chdir(app_path) do
|
|
|
|
output = `bin/rails generate model product name:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
env RAILS_ENV=test bin/rails db:create db:migrate;
|
|
|
|
env RAILS_ENV=test bin/rails db:test:prepare test 2>&1`
|
2015-08-14 12:31:33 -04:00
|
|
|
|
2016-01-10 22:31:12 -05:00
|
|
|
refute_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
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_match("SuperMiddleware", Dir.chdir(app_path) { `bin/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
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/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
|
|
|
|
|
2016-01-23 14:25:02 -05:00
|
|
|
output = Dir.chdir(app_path) { `bin/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
|
|
|
|
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
|
|
|
|
|
|
|
|
Dir.chdir(app_path) do
|
2016-08-06 13:16:09 -04:00
|
|
|
assert system("bin/rails do_nothing RAILS_ENV=production"),
|
|
|
|
"should not be pre-required for rake even eager_load=true"
|
2013-07-09 16:36:50 -04:00
|
|
|
end
|
2013-04-11 06:10:54 -04:00
|
|
|
end
|
|
|
|
|
2010-09-24 09:06:35 -04:00
|
|
|
def test_code_statistics_sanity
|
2016-04-24 05:15:55 -04:00
|
|
|
assert_match "Code LOC: 26 Test LOC: 0 Code to Test Ratio: 1:0.0",
|
|
|
|
Dir.chdir(app_path) { `bin/rails stats` }
|
2010-09-24 09:06:35 -04:00
|
|
|
end
|
2010-11-09 00:10:39 -05:00
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_calls_the_route_inspector
|
2010-11-09 00:10:39 -05:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get '/cart', to: 'cart#show'
|
2010-11-09 00:10:39 -05:00
|
|
|
end
|
|
|
|
RUBY
|
2013-02-19 07:21:03 -05:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes` }
|
2013-11-22 02:51:12 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
2013-05-29 17:25:25 -04:00
|
|
|
end
|
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_with_controller_environment
|
2013-05-29 17:25:25 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.routes.draw do
|
2013-05-29 17:25:25 -04:00
|
|
|
get '/cart', to: 'cart#show'
|
|
|
|
get '/basketball', to: 'basketball#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes CONTROLLER=cart` }
|
2016-02-02 18:16:18 -05:00
|
|
|
assert_equal ["Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.",
|
|
|
|
"Please use `bin/rails routes -c controller_name` instead.",
|
2016-01-24 15:02:44 -05:00
|
|
|
"Prefix Verb URI Pattern Controller#Action",
|
|
|
|
" cart GET /cart(.:format) cart#show\n"].join("\n"), output
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c cart` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
|
|
|
end
|
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_with_namespaced_controller_environment
|
2016-01-24 15:02:44 -05:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
Rails.application.routes.draw do
|
|
|
|
namespace :admin do
|
|
|
|
resource :post
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
expected_output = [" Prefix Verb URI Pattern Controller#Action",
|
|
|
|
" admin_post POST /admin/post(.:format) admin/posts#create",
|
|
|
|
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
|
|
|
|
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
|
|
|
|
" GET /admin/post(.:format) admin/posts#show",
|
|
|
|
" PATCH /admin/post(.:format) admin/posts#update",
|
|
|
|
" PUT /admin/post(.:format) admin/posts#update",
|
|
|
|
" DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n")
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal expected_output, output
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c PostController` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal expected_output, output
|
|
|
|
end
|
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_with_global_search_key
|
2016-01-24 15:02:44 -05:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
Rails.application.routes.draw do
|
|
|
|
get '/cart', to: 'cart#show'
|
2016-02-11 04:46:33 -05:00
|
|
|
post '/cart', to: 'cart#create'
|
|
|
|
get '/basketballs', to: 'basketball#index'
|
2016-01-24 15:02:44 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -g show` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
2016-02-11 04:46:33 -05:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -g POST` }
|
2016-02-11 04:46:33 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n POST /cart(.:format) cart#create\n", output
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -g basketballs` }
|
2016-02-11 04:46:33 -05:00
|
|
|
assert_equal " Prefix Verb URI Pattern Controller#Action\n" \
|
|
|
|
"basketballs GET /basketballs(.:format) basketball#index\n", output
|
2016-01-24 15:02:44 -05:00
|
|
|
end
|
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_with_controller_search_key
|
2016-01-24 15:02:44 -05:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
Rails.application.routes.draw do
|
|
|
|
get '/cart', to: 'cart#show'
|
|
|
|
get '/basketball', to: 'basketball#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c cart` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c Cart` }
|
2016-01-24 15:02:44 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails routes -c CartController` }
|
2013-11-22 02:51:12 -05:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
2010-11-09 00:10:39 -05:00
|
|
|
end
|
2011-01-01 15:21:25 -05:00
|
|
|
|
2016-03-04 07:43:33 -05:00
|
|
|
def test_rails_routes_displays_message_when_no_routes_are_defined
|
2013-02-18 13:26:59 -05:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.routes.draw do
|
2013-02-18 13:26:59 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_equal <<-MESSAGE.strip_heredoc, Dir.chdir(app_path) { `bin/rails routes` }
|
2013-02-18 19:26:25 -05:00
|
|
|
You don't have any routes defined!
|
2013-02-18 13:26:59 -05:00
|
|
|
|
2013-02-18 19:26:25 -05:00
|
|
|
Please add some routes in config/routes.rb.
|
2013-02-18 13:26:59 -05:00
|
|
|
|
2013-02-18 19:33:50 -05:00
|
|
|
For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.
|
2013-02-19 07:21:03 -05:00
|
|
|
MESSAGE
|
2013-02-18 13:26:59 -05:00
|
|
|
end
|
|
|
|
|
2016-04-24 00:40:58 -04:00
|
|
|
def test_rake_routes_with_rake_options
|
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
Rails.application.routes.draw do
|
|
|
|
get '/cart', to: 'cart#show'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile routes` }
|
2016-04-24 00:40:58 -04:00
|
|
|
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
output = Dir.chdir(app_path) { `bin/rails log_something RAILS_ENV=production && cat log/production.log` }
|
2011-05-05 16:51:29 -04:00
|
|
|
assert_match "Sample log message", output
|
|
|
|
end
|
|
|
|
|
2011-01-12 18:18:45 -05:00
|
|
|
def test_loading_specific_fixtures
|
|
|
|
Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate model user username:string password:string;
|
|
|
|
bin/rails generate model product name:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
bin/rails db:migrate`
|
2011-01-12 18:18:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2016-01-23 14:25:02 -05:00
|
|
|
errormsg = Dir.chdir(app_path) { `bin/rails db:fixtures:load FIXTURES=products` }
|
2011-01-12 18:18:45 -05:00
|
|
|
assert $?.success?, errormsg
|
|
|
|
|
|
|
|
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
|
|
|
|
Dir.chdir(app_path) do
|
2016-01-23 14:25:02 -05:00
|
|
|
`bin/rails db:migrate`
|
2012-06-16 13:37:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
app_file "test/fixtures/products.csv", ""
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
2016-01-23 14:25:02 -05:00
|
|
|
errormsg = Dir.chdir(app_path) { `bin/rails db:fixtures:load` }
|
2012-06-16 13:37:00 -04:00
|
|
|
assert $?.success?, errormsg
|
|
|
|
end
|
|
|
|
|
2011-07-07 17:58:04 -04:00
|
|
|
def test_scaffold_tests_pass_by_default
|
2012-03-14 13:36:15 -04:00
|
|
|
output = Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate scaffold user username:string password:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
RAILS_ENV=test bin/rails db:migrate test`
|
2011-07-07 17:58:04 -04:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
output = Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate scaffold user username:string password:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
RAILS_ENV=test bin/rails db:migrate test`
|
2015-04-19 18:22:14 -04:00
|
|
|
end
|
|
|
|
|
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
|
2012-12-09 22:35:03 -05:00
|
|
|
output = Dir.chdir(app_path) do
|
2016-02-05 22:15:28 -05:00
|
|
|
`bin/rails generate model Product;
|
|
|
|
bin/rails generate model Cart;
|
|
|
|
bin/rails generate scaffold LineItems product:references cart:belongs_to;
|
2016-01-23 14:25:02 -05:00
|
|
|
RAILS_ENV=test bin/rails db:migrate test`
|
2012-12-09 22:35:03 -05:00
|
|
|
end
|
|
|
|
|
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:33:08 -04:00
|
|
|
def test_db_test_clone_when_using_sql_format
|
|
|
|
add_to_config "config.active_record.schema_format = :sql"
|
|
|
|
output = Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate scaffold user username:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
bin/rails db:migrate;
|
|
|
|
bin/rails db:test:clone 2>&1 --trace`
|
2012-06-25 13:33:08 -04:00
|
|
|
end
|
|
|
|
assert_match(/Execute db:test:clone_structure/, 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"
|
|
|
|
output = Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate scaffold user username:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
bin/rails db:migrate;
|
|
|
|
bin/rails db:test:prepare 2>&1 --trace`
|
2012-06-25 13:40:06 -04:00
|
|
|
end
|
|
|
|
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
|
|
|
|
Dir.chdir(app_path) do
|
2012-03-08 17:32:41 -05:00
|
|
|
# ensure we have a schema_migrations table to dump
|
2016-01-23 14:25:02 -05:00
|
|
|
`bin/rails db:migrate db:structure:dump SCHEMA=db/my_structure.sql`
|
2011-12-18 14:43:36 -05:00
|
|
|
end
|
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"
|
|
|
|
|
|
|
|
output = Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails g model post title:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
bin/rails db:migrate:redo 2>&1 --trace;`
|
2012-03-17 00:57:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
Dir.chdir(app_path) do
|
2015-06-30 05:19:01 -04:00
|
|
|
`bin/rails generate model post title:string;
|
|
|
|
bin/rails generate model product name:string;
|
2016-01-23 14:25:02 -05:00
|
|
|
bin/rails db:migrate db:schema:cache:dump`
|
2012-02-29 11:01:12 -05:00
|
|
|
end
|
2016-08-06 13:16:09 -04:00
|
|
|
assert File.exist?(File.join(app_path, "db", "schema_cache.dump"))
|
2012-02-29 11:01:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rake_clear_schema_cache
|
|
|
|
Dir.chdir(app_path) do
|
2016-01-23 14:25:02 -05:00
|
|
|
`bin/rails db:schema:cache:dump db:schema:cache:clear`
|
2012-02-29 11:01:12 -05:00
|
|
|
end
|
2016-08-06 13:16:09 -04:00
|
|
|
assert !File.exist?(File.join(app_path, "db", "schema_cache.dump"))
|
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
|
|
|
|
Dir.chdir(app_path) do
|
2016-02-13 00:14:23 -05:00
|
|
|
`bin/rails app:templates:copy`
|
2012-06-10 10:26:55 -04:00
|
|
|
%w(controller mailer scaffold).each do |dir|
|
2016-08-06 13:16:09 -04:00
|
|
|
assert File.exist?(File.join(app_path, "lib", "templates", "erb", dir))
|
2012-06-10 10:26:55 -04:00
|
|
|
end
|
|
|
|
%w(controller helper scaffold_controller assets).each do |dir|
|
2016-08-06 13:16:09 -04:00
|
|
|
assert File.exist?(File.join(app_path, "lib", "templates", "rails", dir))
|
2012-06-10 10:26:55 -04:00
|
|
|
end
|
|
|
|
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", ""
|
|
|
|
|
|
|
|
output = Dir.chdir(app_path) do
|
2016-02-13 00:14:23 -05:00
|
|
|
`bin/rails app:template LOCATION=template.rb`
|
2014-03-08 09:51:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/Hello, World!/, output)
|
|
|
|
end
|
2015-05-26 08:09:22 -04:00
|
|
|
|
|
|
|
def test_tmp_clear_should_work_if_folder_missing
|
|
|
|
FileUtils.remove_dir("#{app_path}/tmp")
|
2016-01-23 14:25:02 -05:00
|
|
|
errormsg = Dir.chdir(app_path) { `bin/rails tmp:clear` }
|
2015-05-26 08:09:22 -04:00
|
|
|
assert_predicate $?, :success?
|
|
|
|
assert_empty errormsg
|
|
|
|
end
|
2010-04-26 03:36:13 -04:00
|
|
|
end
|
2011-09-09 21:50:32 -04:00
|
|
|
end
|