diff options
Diffstat (limited to 'railties/test/application/rake_test.rb')
-rw-r--r-- | railties/test/application/rake_test.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 0da0928b48..639875dd6e 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -24,6 +24,26 @@ module ApplicationTests assert $task_loaded end + def test_the_test_rake_task_is_protected_when_previous_migration_was_production + Dir.chdir(app_path) do + output = `bin/rails generate model product name:string; + env RAILS_ENV=production bin/rake db:create db:migrate; + env RAILS_ENV=production bin/rake db:test:prepare test 2>&1` + + assert_match(/ActiveRecord::ProtectedEnvironmentError/, output) + 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; + env RAILS_ENV=test bin/rake db:create db:migrate; + env RAILS_ENV=test bin/rake db:test:prepare test 2>&1` + + refute_match(/ActiveRecord::ProtectedEnvironmentError/, output) + end + end + def test_environment_is_required_in_rake_tasks app_file "config/environment.rb", <<-RUBY SuperMiddleware = Struct.new(:app) @@ -98,7 +118,7 @@ module ApplicationTests end def test_code_statistics_sanity - assert_match "Code LOC: 7 Test LOC: 0 Code to Test Ratio: 1:0.0", + assert_match "Code LOC: 14 Test LOC: 0 Code to Test Ratio: 1:0.0", Dir.chdir(app_path){ `bin/rake stats` } end @@ -186,7 +206,7 @@ module ApplicationTests def test_scaffold_tests_pass_by_default output = Dir.chdir(app_path) do `bin/rails generate scaffold user username:string password:string; - bin/rake db:migrate test` + RAILS_ENV=test bin/rake db:migrate test` end assert_match(/7 runs, 12 assertions, 0 failures, 0 errors/, output) @@ -205,7 +225,7 @@ module ApplicationTests output = Dir.chdir(app_path) do `bin/rails generate scaffold user username:string password:string; - bin/rake db:migrate test` + RAILS_ENV=test bin/rake db:migrate test` end assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output) @@ -218,7 +238,7 @@ module ApplicationTests output = Dir.chdir(app_path) do `bin/rails generate scaffold LineItems product:references cart:belongs_to; - bin/rake db:migrate test` + RAILS_ENV=test bin/rake db:migrate test` end assert_match(/7 runs, 12 assertions, 0 failures, 0 errors/, output) |