From a71bbed76aab9e8a9a6b2da18bcacd8ee32a0dd0 Mon Sep 17 00:00:00 2001 From: claudiob Date: Sat, 2 Dec 2017 12:00:09 -0800 Subject: Fix typo in test error message With the current code, a failing test shows this error, which is missing the number of times called and has two periods at the end. ``` /railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install Failure: AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]: active_storage:install expected to be called once, but was called times.. Expected: 1 Actual: 2 ``` After the fix, the error message looks correct: ``` /railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install Failure: AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]: active_storage:install expected to be called once, but was called 2 times. Expected: 1 Actual: 2 ``` --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 774fd0f315..8d12f4e5a7 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -310,7 +310,7 @@ class AppGeneratorTest < Rails::Generators::TestCase case command when "active_storage:install" @binstub_called += 1 - assert_equal 1, @binstub_called, "active_storage:install expected to be called once, but was called #{@install_called} times." + assert_equal 1, @binstub_called, "active_storage:install expected to be called once, but was called #{@binstub_called} times" end end -- cgit v1.2.3 From dbee80bca0ef504120219e6c7686437456511060 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 1 Dec 2017 18:16:06 +0900 Subject: Make `Migrator.current_version` work without a current database This is necessary in order to make the processing dependent on `Migrator.current_version` work even without database. Context: https://github.com/rails/rails/pull/31135#issuecomment-348404326 --- railties/test/application/rake/dbs_test.rb | 14 ++++++++++++++ railties/test/isolation/abstract_unit.rb | 15 +++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 0235210fdd..2082e9fa9f 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -98,6 +98,20 @@ module ApplicationTests end end + test "db:create works when schema cache exists and database does not exist" do + use_postgresql + + begin + rails %w(db:create db:migrate db:schema:cache:dump) + + rails "db:drop" + rails "db:create" + assert_equal 0, $?.exitstatus + ensure + rails "db:drop" rescue nil + end + end + test "db:drop failure because database does not exist" do output = rails("db:drop:_unsafe", "--trace") assert_match(/does not exist/, output) diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 7522237a38..5b1c06d4e5 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -381,6 +381,21 @@ module TestHelpers $:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' } end + + def use_postgresql + 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 + end end end -- cgit v1.2.3 From 915f0e682cecf80080914d0390ce22eb06f41470 Mon Sep 17 00:00:00 2001 From: Tsukuru Tanimichi Date: Wed, 29 Nov 2017 18:44:46 +0900 Subject: Add tests for the `--webpack` option We probably don't have any tests for the `--webpack` option. related: #27288 --- railties/test/generators/app_generator_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 774fd0f315..c9c85078d4 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -743,6 +743,20 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_webpack_option + command_check = -> command, *_ do + @called ||= 0 + @called += 1 if command == "webpacker:install" + assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times." + end + + generator([destination_root], webpack: true).stub(:rails_command, command_check) do + quietly { generator.invoke_all } + end + + assert_gem "webpacker" + end + def test_generator_if_skip_turbolinks_is_given run_generator [destination_root, "--skip-turbolinks"] -- cgit v1.2.3 From b9fb74514b752df3b707fa420e09dca459a3844f Mon Sep 17 00:00:00 2001 From: Tsukuru Tanimichi Date: Tue, 5 Dec 2017 18:41:44 +0900 Subject: Modify `test_webpack_option` --- railties/test/generators/app_generator_test.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index decea77d48..68b31148d6 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -746,11 +746,13 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_webpack_option command_check = -> command, *_ do @called ||= 0 - @called += 1 if command == "webpacker:install" - assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times." + if command == "webpacker:install" + @called += 1 + assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times." + end end - generator([destination_root], webpack: true).stub(:rails_command, command_check) do + generator([destination_root], webpack: "webpack").stub(:rails_command, command_check) do quietly { generator.invoke_all } end -- cgit v1.2.3 From 6a11b0c1549e88a7ca32a73764d8b6634dc326e2 Mon Sep 17 00:00:00 2001 From: Tsukuru Tanimichi Date: Tue, 5 Dec 2017 18:43:15 +0900 Subject: Add more tests for the `--webpack` option --- railties/test/generators/app_generator_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 68b31148d6..96803db838 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -759,6 +759,25 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_gem "webpacker" end + def test_webpack_option_with_js_framework + command_check = -> command, *_ do + case command + when "webpacker:install" + @webpacker ||= 0 + @webpacker += 1 + assert_equal 1, @webpacker, "webpacker:install expected to be called once, but was called #{@webpacker} times." + when "webpacker:install:react" + @react ||= 0 + @react += 1 + assert_equal 1, @react, "webpacker:install:react expected to be called once, but was called #{@react} times." + end + end + + generator([destination_root], webpack: "react").stub(:rails_command, command_check) do + quietly { generator.invoke_all } + end + end + def test_generator_if_skip_turbolinks_is_given run_generator [destination_root, "--skip-turbolinks"] -- cgit v1.2.3