test_runner_test.rb 22.6 KB
Newer Older
1 2 3
require "isolation/abstract_unit"
require "active_support/core_ext/string/strip"
require "env_helpers"
4 5 6

module ApplicationTests
  class TestRunnerTest < ActiveSupport::TestCase
7
    include ActiveSupport::Testing::Isolation, EnvHelpers
8 9 10 11 12 13 14 15 16 17

    def setup
      build_app
      create_schema
    end

    def teardown
      teardown_app
    end

18 19 20 21 22 23 24 25 26 27
    def test_run_via_backwardscompatibility
      require "rails/test_unit/minitest_plugin"

      assert_nothing_raised do
        Minitest.run_via[:ruby] = true
      end

      assert_predicate Minitest.run_via, :ruby?
    end

28
    def test_run_single_file
29 30
      create_test_file :models, "foo"
      create_test_file :models, "bar"
31
      assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb")
32 33 34
    end

    def test_run_multiple_files
35 36
      create_test_file :models,  "foo"
      create_test_file :models,  "bar"
37
      assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb")
38 39 40
    end

    def test_run_file_with_syntax_error
41
      app_file "test/models/error_test.rb", <<-RUBY
42 43 44 45
        require 'test_helper'
        def; end
      RUBY

46
      error = capture(:stderr) { run_test_command("test/models/error_test.rb") }
47
      assert_match "syntax error", error
48 49 50
    end

    def test_run_models
51 52 53
      create_test_file :models, "foo"
      create_test_file :models, "bar"
      create_test_file :controllers, "foobar_controller"
54
      run_test_command("test/models").tap do |output|
55 56
        assert_match "FooTest", output
        assert_match "BarTest", output
57
        assert_match "2 runs, 2 assertions, 0 failures", output
58 59 60 61
      end
    end

    def test_run_helpers
62 63 64
      create_test_file :helpers, "foo_helper"
      create_test_file :helpers, "bar_helper"
      create_test_file :controllers, "foobar_controller"
65
      run_test_command("test/helpers").tap do |output|
66 67
        assert_match "FooHelperTest", output
        assert_match "BarHelperTest", output
68
        assert_match "2 runs, 2 assertions, 0 failures", output
69 70 71 72
      end
    end

    def test_run_units
73 74 75 76
      create_test_file :models, "foo"
      create_test_file :helpers, "bar_helper"
      create_test_file :unit, "baz_unit"
      create_test_file :controllers, "foobar_controller"
77 78 79 80 81 82 83 84

      Dir.chdir(app_path) do
        `bin/rails test:units`.tap do |output|
          assert_match "FooTest", output
          assert_match "BarHelperTest", output
          assert_match "BazUnitTest", output
          assert_match "3 runs, 3 assertions, 0 failures", output
        end
85 86 87 88
      end
    end

    def test_run_controllers
89 90 91
      create_test_file :controllers, "foo_controller"
      create_test_file :controllers, "bar_controller"
      create_test_file :models, "foo"
92
      run_test_command("test/controllers").tap do |output|
93 94
        assert_match "FooControllerTest", output
        assert_match "BarControllerTest", output
95
        assert_match "2 runs, 2 assertions, 0 failures", output
96 97 98 99
      end
    end

    def test_run_mailers
100 101 102
      create_test_file :mailers, "foo_mailer"
      create_test_file :mailers, "bar_mailer"
      create_test_file :models, "foo"
103
      run_test_command("test/mailers").tap do |output|
104 105
        assert_match "FooMailerTest", output
        assert_match "BarMailerTest", output
106
        assert_match "2 runs, 2 assertions, 0 failures", output
107 108 109
      end
    end

Y
yuuji.yaginuma 已提交
110
    def test_run_jobs
111 112 113
      create_test_file :jobs, "foo_job"
      create_test_file :jobs, "bar_job"
      create_test_file :models, "foo"
114
      run_test_command("test/jobs").tap do |output|
Y
yuuji.yaginuma 已提交
115 116 117 118 119 120
        assert_match "FooJobTest", output
        assert_match "BarJobTest", output
        assert_match "2 runs, 2 assertions, 0 failures", output
      end
    end

121
    def test_run_functionals
122 123 124 125
      create_test_file :mailers, "foo_mailer"
      create_test_file :controllers, "bar_controller"
      create_test_file :functional, "baz_functional"
      create_test_file :models, "foo"
126 127 128 129 130 131 132 133

      Dir.chdir(app_path) do
        `bin/rails test:functionals`.tap do |output|
          assert_match "FooMailerTest", output
          assert_match "BarControllerTest", output
          assert_match "BazFunctionalTest", output
          assert_match "3 runs, 3 assertions, 0 failures", output
        end
134 135 136 137
      end
    end

    def test_run_integration
138 139
      create_test_file :integration, "foo_integration"
      create_test_file :models, "foo"
140
      run_test_command("test/integration").tap do |output|
141
        assert_match "FooIntegration", output
142
        assert_match "1 runs, 1 assertions, 0 failures", output
143 144 145
      end
    end

146
    def test_run_all_suites
Y
yuuji.yaginuma 已提交
147
      suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration, :jobs]
148
      suites.each { |suite| create_test_file suite, "foo_#{suite}" }
149
      run_test_command("") .tap do |output|
150
        suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output }
Y
yuuji.yaginuma 已提交
151
        assert_match "8 runs, 8 assertions, 0 failures", output
152 153 154
      end
    end

155
    def test_run_named_test
156
      app_file "test/unit/chu_2_koi_test.rb", <<-RUBY
157 158 159 160 161 162 163 164 165 166 167 168 169
        require 'test_helper'

        class Chu2KoiTest < ActiveSupport::TestCase
          def test_rikka
            puts 'Rikka'
          end

          def test_sanae
            puts 'Sanae'
          end
        end
      RUBY

170
      run_test_command("-n test_rikka test/unit/chu_2_koi_test.rb").tap do |output|
171 172 173 174 175 176
        assert_match "Rikka", output
        assert_no_match "Sanae", output
      end
    end

    def test_run_matched_test
177
      app_file "test/unit/chu_2_koi_test.rb", <<-RUBY
178 179 180 181 182 183 184 185 186 187 188 189 190
        require 'test_helper'

        class Chu2KoiTest < ActiveSupport::TestCase
          def test_rikka
            puts 'Rikka'
          end

          def test_sanae
            puts 'Sanae'
          end
        end
      RUBY

191
      run_test_command("-n /rikka/ test/unit/chu_2_koi_test.rb").tap do |output|
192 193
        assert_match "Rikka", output
        assert_no_match "Sanae", output
194 195 196
      end
    end

197 198
    def test_load_fixtures_when_running_test_suites
      create_model_with_fixture
199
      suites = [:models, :helpers, :controllers, :mailers, :integration]
200

201 202
      suites.each do |suite, directory|
        directory ||= suite
203
        create_fixture_test directory
204
        assert_match "3 users", run_test_command("test/#{suite}")
205 206 207 208
        Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
      end
    end

209
    def test_run_with_model
210
      skip "These feel a bit odd. Not sure we should keep supporting them."
211
      create_model_with_fixture
212
      create_fixture_test "models", "user"
213 214 215 216
      assert_match "3 users", run_task(["test models/user"])
      assert_match "3 users", run_task(["test app/models/user.rb"])
    end

217
    def test_run_different_environment_using_env_var
218
      skip "no longer possible. Running tests in a different environment should be explicit"
219
      app_file "test/unit/env_test.rb", <<-RUBY
220 221 222 223 224 225 226 227 228
        require 'test_helper'

        class EnvTest < ActiveSupport::TestCase
          def test_env
            puts Rails.env
          end
        end
      RUBY

229 230
      ENV["RAILS_ENV"] = "development"
      assert_match "development", run_test_command("test/unit/env_test.rb")
231 232
    end

233 234 235
    def test_run_in_test_environment_by_default
      create_env_test

236
      assert_match "Current Environment: test", run_test_command("test/unit/env_test.rb")
237 238
    end

239
    def test_run_different_environment
240 241 242 243 244 245 246 247
      create_env_test

      assert_match "Current Environment: development",
        run_test_command("-e development test/unit/env_test.rb")
    end

    def test_generated_scaffold_works_with_rails_test
      create_scaffold
248
      assert_match "0 failures, 0 errors, 0 skips", run_test_command("")
249 250
    end

251 252
    def test_generated_controller_works_with_rails_test
      create_controller
253
      assert_match "0 failures, 0 errors, 0 skips", run_test_command("")
254 255
    end

256
    def test_run_multiple_folders
257 258
      create_test_file :models, "account"
      create_test_file :controllers, "accounts_controller"
259

260 261 262 263
      run_test_command("test/models test/controllers").tap do |output|
        assert_match "AccountTest", output
        assert_match "AccountsControllerTest", output
        assert_match "2 runs, 2 assertions, 0 failures, 0 errors, 0 skips", output
264 265 266 267
      end
    end

    def test_run_with_ruby_command
268
      app_file "test/models/post_test.rb", <<-RUBY
269 270
        require 'test_helper'

271 272 273 274
        class PostTest < ActiveSupport::TestCase
          test 'declarative syntax works' do
            puts 'PostTest'
            assert true
275 276 277 278
          end
        end
      RUBY

279 280
      Dir.chdir(app_path) do
        `ruby -Itest test/models/post_test.rb`.tap do |output|
281 282
          assert_match "PostTest", output
          assert_no_match "is already defined in", output
283 284
        end
      end
285 286
    end

287
    def test_mix_files_and_line_filters
288 289
      create_test_file :models, "account"
      app_file "test/models/post_test.rb", <<-RUBY
290 291 292 293 294 295 296 297 298 299 300 301 302 303
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          def test_post
            puts 'PostTest'
            assert true
          end

          def test_line_filter_does_not_run_this
            assert true
          end
        end
      RUBY

304 305 306 307
      run_test_command("test/models/account_test.rb test/models/post_test.rb:4").tap do |output|
        assert_match "AccountTest", output
        assert_match "PostTest", output
        assert_match "2 runs, 2 assertions", output
308 309 310
      end
    end

311
    def test_more_than_one_line_filter
312
      app_file "test/models/post_test.rb", <<-RUBY
313 314 315 316 317 318 319 320 321 322 323 324 325
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'PostTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'PostTest:SecondFilter'
            assert true
          end

R
Ryuta Kamizono 已提交
326
          test "line filter does not run this" do
327 328 329 330 331
            assert true
          end
        end
      RUBY

332 333 334 335
      run_test_command("test/models/post_test.rb:4:9").tap do |output|
        assert_match "PostTest:FirstFilter", output
        assert_match "PostTest:SecondFilter", output
        assert_match "2 runs, 2 assertions", output
336 337 338 339
      end
    end

    def test_more_than_one_line_filter_with_multiple_files
340
      app_file "test/models/account_test.rb", <<-RUBY
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
        require 'test_helper'

        class AccountTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'AccountTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'AccountTest:SecondFilter'
            assert true
          end

          test "line filter does not run this" do
            assert true
          end
        end
      RUBY

360
      app_file "test/models/post_test.rb", <<-RUBY
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'PostTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'PostTest:SecondFilter'
            assert true
          end

          test "line filter does not run this" do
            assert true
          end
        end
      RUBY

380 381 382 383 384 385
      run_test_command("test/models/account_test.rb:4:9 test/models/post_test.rb:4:9").tap do |output|
        assert_match "AccountTest:FirstFilter", output
        assert_match "AccountTest:SecondFilter", output
        assert_match "PostTest:FirstFilter", output
        assert_match "PostTest:SecondFilter", output
        assert_match "4 runs, 4 assertions", output
386 387 388
      end
    end

389
    def test_multiple_line_filters
390 391
      create_test_file :models, "account"
      create_test_file :models, "post"
392

393 394 395
      run_test_command("test/models/account_test.rb:4 test/models/post_test.rb:4").tap do |output|
        assert_match "AccountTest", output
        assert_match "PostTest", output
396 397 398
      end
    end

399
    def test_line_filters_trigger_only_one_runnable
400
      app_file "test/models/post_test.rb", <<-RUBY
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test 'truth' do
            assert true
          end
        end

        class SecondPostTest < ActiveSupport::TestCase
          test 'truth' do
            assert false, 'ran second runnable'
          end
        end
      RUBY

      # Pass seed guaranteeing failure.
417 418 419
      run_test_command("test/models/post_test.rb:4 --seed 30410").tap do |output|
        assert_no_match "ran second runnable", output
        assert_match "1 runs, 1 assertions", output
420 421 422
      end
    end

423
    def test_line_filter_with_minitest_string_filter
424
      app_file "test/models/post_test.rb", <<-RUBY
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test 'by line' do
            puts 'by line'
            assert true
          end

          test 'by name' do
            puts 'by name'
            assert true
          end
        end
      RUBY

440 441 442 443
      run_test_command("test/models/post_test.rb:4 -n test_by_name").tap do |output|
        assert_match "by line", output
        assert_match "by name", output
        assert_match "2 runs, 2 assertions", output
444 445 446
      end
    end

447 448 449
    def test_shows_filtered_backtrace_by_default
      create_backtrace_test

450
      assert_match "Rails::BacktraceCleaner", run_test_command("test/unit/backtrace_test.rb")
451 452 453 454 455
    end

    def test_backtrace_option
      create_backtrace_test

456 457 458
      assert_match "Minitest::BacktraceFilter", run_test_command("test/unit/backtrace_test.rb -b")
      assert_match "Minitest::BacktraceFilter",
        run_test_command("test/unit/backtrace_test.rb --backtrace")
459 460 461 462 463
    end

    def test_show_full_backtrace_using_backtrace_environment_variable
      create_backtrace_test

464 465
      switch_env "BACKTRACE", "true" do
        assert_match "Minitest::BacktraceFilter", run_test_command("test/unit/backtrace_test.rb")
466 467 468 469 470
      end
    end

    def test_run_app_without_rails_loaded
      # Simulate a real Rails app boot.
471
      app_file "config/boot.rb", <<-RUBY
B
bogdanvlviv 已提交
472
        ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
473 474 475 476

        require 'bundler/setup' # Set up gems listed in the Gemfile.
      RUBY

477
      assert_match "0 runs, 0 assertions", run_test_command("")
478 479
    end

480
    def test_output_inline_by_default
481
      create_test_file :models, "post", pass: false
482

483
      output = run_test_command("test/models/post_test.rb")
484
      expect = %r{Running:\n\nPostTest\nF\n\nFailure:\nPostTest#test_truth \[[^\]]+test/models/post_test.rb:6\]:\nwups!\n\nbin/rails test test/models/post_test.rb:4\n\n\n\n}
485
      assert_match expect, output
486 487
    end

488
    def test_only_inline_failure_output
489
      create_test_file :models, "post", pass: false
490

491
      output = run_test_command("test/models/post_test.rb")
492 493 494
      assert_match %r{Finished in.*\n\n1 runs, 1 assertions}, output
    end

495
    def test_fail_fast
496
      create_test_file :models, "post", pass: false
497 498

      assert_match(/Interrupt/,
499
        capture(:stderr) { run_test_command("test/models/post_test.rb --fail-fast") })
500 501
    end

502
    def test_raise_error_when_specified_file_does_not_exist
503
      error = capture(:stderr) { run_test_command("test/not_exists.rb") }
504 505 506
      assert_match(%r{cannot load such file.+test/not_exists\.rb}, error)
    end

507
    def test_pass_TEST_env_on_rake_test
508 509
      create_test_file :models, "account"
      create_test_file :models, "post", pass: false
510 511
      # This specifically verifies TEST for backwards compatibility with rake test
      # as bin/rails test already supports running tests from a single file more cleanly.
512
      output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` }
513 514 515

      assert_match "PostTest", output, "passing TEST= should run selected test"
      assert_no_match "AccountTest", output, "passing TEST= should only run selected test"
516
      assert_match "1 runs, 1 assertions", output
517 518
    end

519
    def test_pass_rake_options
520
      create_test_file :models, "account"
521
      output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` }
522

523 524
      assert_match "1 runs, 1 assertions", output
      assert_match "Execute test", output
525 526
    end

527
    def test_rails_db_create_all_restores_db_connection
528
      create_test_file :models, "account"
529
      output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` }
530 531 532 533
      assert_match "ar_internal_metadata", output, "tables should be dumped"
    end

    def test_rails_db_create_all_restores_db_connection_after_drop
534
      create_test_file :models, "account"
535
      Dir.chdir(app_path) { `bin/rails db:create:all` } # create all to avoid warnings
536
      output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` }
537 538 539
      assert_match "ar_internal_metadata", output, "tables should be dumped"
    end

540
    def test_rake_passes_TESTOPTS_to_minitest
541
      create_test_file :models, "account"
542
      output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` }
543 544 545 546
      assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test"
    end

    def test_rake_passes_multiple_TESTOPTS_to_minitest
547
      create_test_file :models, "account"
548
      output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` }
549 550 551 552
      assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test"
      assert_match "seed=1234", output, "passing TEST= should run selected test"
    end

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
    def test_rake_runs_multiple_test_tasks
      create_test_file :models, "account"
      create_test_file :controllers, "accounts_controller"
      output = Dir.chdir(app_path) { `bin/rake test:models test:controllers TESTOPTS='-v'` }
      assert_match "AccountTest#test_truth", output
      assert_match "AccountsControllerTest#test_truth", output
    end

    def test_rake_db_and_test_tasks_parses_args_correctly
      create_test_file :models, "account"
      output = Dir.chdir(app_path) { `bin/rake db:migrate test:models TESTOPTS='-v' && echo ".tables" | rails dbconsole` }
      assert_match "AccountTest#test_truth", output
      assert_match "ar_internal_metadata", output
    end

568 569 570 571 572 573 574 575 576 577 578
    def test_warnings_option
      app_file "test/models/warnings_test.rb", <<-RUBY
        require 'test_helper'
        def test_warnings
          a = 1
        end
      RUBY
      assert_match(/warning: assigned but unused variable/,
        capture(:stderr) { run_test_command("test/models/warnings_test.rb -w") })
    end

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
    def test_reset_sessions_before_rollback_on_system_tests
      app_file "test/system/reset_session_before_rollback_test.rb", <<-RUBY
        require "application_system_test_case"

        class ResetSessionBeforeRollbackTest < ApplicationSystemTestCase
          def teardown_fixtures
            puts "rollback"
            super
          end

          Capybara.singleton_class.prepend(Module.new do
            def reset_sessions!
              puts "reset sessions"
              super
            end
          end)

          test "dummy" do
          end
        end
      RUBY

      run_test_command("test/system/reset_session_before_rollback_test.rb").tap do |output|
        assert_match "reset sessions\nrollback", output
        assert_match "1 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
      end
    end

607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
    def test_system_tests_are_not_run_with_the_default_test_command
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      run_test_command("").tap do |output|
        assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
      end
    end

    def test_system_tests_are_not_run_through_rake_test
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      output = Dir.chdir(app_path) { `bin/rake test` }
      assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
    end

    def test_system_tests_are_run_through_rake_test_when_given_in_TEST
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      output = Dir.chdir(app_path) { `bin/rake test TEST=test/system/dummy_test.rb` }
      assert_match "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips", output
    end

653
    private
654
      def run_test_command(arguments = "test/unit/test_test.rb")
655
        Dir.chdir(app_path) { `bin/rails t #{arguments}` }
656 657
      end

658
      def create_model_with_fixture
659
        script "generate model user name:string"
660

661
        app_file "test/fixtures/users.yml", <<-YAML.strip_heredoc
662 663 664 665 666 667 668 669 670 671 672
          vampire:
            id: 1
            name: Koyomi Araragi
          crab:
            id: 2
            name: Senjougahara Hitagi
          cat:
            id: 3
            name: Tsubasa Hanekawa
        YAML

673
        run_migration
674 675
      end

676
      def create_fixture_test(path = :unit, name = "test")
677 678 679 680 681 682 683 684 685 686 687
        app_file "test/#{path}/#{name}_test.rb", <<-RUBY
          require 'test_helper'

          class #{name.camelize}Test < ActiveSupport::TestCase
            def test_fixture
              puts "\#{User.count} users (\#{__FILE__})"
            end
          end
        RUBY
      end

688
      def create_backtrace_test
689
        app_file "test/unit/backtrace_test.rb", <<-RUBY
690 691 692 693 694 695 696 697 698 699
          require 'test_helper'

          class BacktraceTest < ActiveSupport::TestCase
            def test_backtrace
              puts Minitest.backtrace_filter
            end
          end
        RUBY
      end

700
      def create_schema
701
        app_file "db/schema.rb", ""
702 703
      end

704
      def create_test_file(path = :unit, name = "test", pass: true)
705 706 707 708 709 710
        app_file "test/#{path}/#{name}_test.rb", <<-RUBY
          require 'test_helper'

          class #{name.camelize}Test < ActiveSupport::TestCase
            def test_truth
              puts "#{name.camelize}Test"
711
              assert #{pass}, 'wups!'
712 713 714 715
            end
          end
        RUBY
      end
716

717
      def create_env_test
718
        app_file "test/unit/env_test.rb", <<-RUBY
719 720 721 722 723 724 725 726 727 728
          require 'test_helper'

          class EnvTest < ActiveSupport::TestCase
            def test_env
              puts "Current Environment: \#{Rails.env}"
            end
          end
        RUBY
      end

729
      def create_scaffold
730 731
        script "generate scaffold user name:string"
        Dir.chdir(app_path) { File.exist?("app/models/user.rb") }
732 733 734
        run_migration
      end

735
      def create_controller
736
        script "generate controller admin/dashboard index"
737 738
      end

739
      def run_migration
740
        Dir.chdir(app_path) { `bin/rails db:migrate` }
741
      end
742 743
  end
end