diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-13 12:35:24 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 12:35:24 +0900 |
commit | 293401809dc597a61e46843019ee8be6ce731429 (patch) | |
tree | 17f8cfed3bfbab1532040b7bd2a61bbde6466b63 /activerecord/test | |
parent | 9d43a84f73c1b3853a91d052a462ee60eccaf957 (diff) | |
parent | 011e641d19d235e4ec03fd9eb20ecea644ec5e06 (diff) | |
download | rails-293401809dc597a61e46843019ee8be6ce731429.tar.gz rails-293401809dc597a61e46843019ee8be6ce731429.tar.bz2 rails-293401809dc597a61e46843019ee8be6ce731429.zip |
Merge pull request #31423 from bogdanvlviv/fix-protected_environments-with-symbols
Fix protected environments with symbols
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/tasks/database_tasks_test.rb | 21 |
2 files changed, 31 insertions, 2 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 875b98f0b8..7fc4a396e4 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1503,4 +1503,16 @@ class BasicsTest < ActiveRecord::TestCase assert_match(/SELECT #{quoted_id}.* FROM `developers`/, query) end + + test "protected environments by default is an array with production" do + assert_equal ["production"], ActiveRecord::Base.protected_environments + end + + def test_protected_environments_are_stored_as_an_array_of_string + previous_protected_environments = ActiveRecord::Base.protected_environments + ActiveRecord::Base.protected_environments = [:staging, "production"] + assert_equal ["staging", "production"], ActiveRecord::Base.protected_environments + ensure + ActiveRecord::Base.protected_environments = previous_protected_environments + end end diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 5a094ead42..fd381f229f 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -30,13 +30,30 @@ module ActiveRecord def test_raises_an_error_when_called_with_protected_environment ActiveRecord::Migrator.stubs(:current_version).returns(1) - protected_environments = ActiveRecord::Base.protected_environments.dup + protected_environments = ActiveRecord::Base.protected_environments current_env = ActiveRecord::Migrator.current_environment assert_not_includes protected_environments, current_env # Assert no error ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! - ActiveRecord::Base.protected_environments << current_env + ActiveRecord::Base.protected_environments = [current_env] + assert_raise(ActiveRecord::ProtectedEnvironmentError) do + ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! + end + ensure + ActiveRecord::Base.protected_environments = protected_environments + end + + def test_raises_an_error_when_called_with_protected_environment_which_name_is_a_symbol + ActiveRecord::Migrator.stubs(:current_version).returns(1) + + protected_environments = ActiveRecord::Base.protected_environments + current_env = ActiveRecord::Migrator.current_environment + assert_not_includes protected_environments, current_env + # Assert no error + ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! + + ActiveRecord::Base.protected_environments = [current_env.to_sym] assert_raise(ActiveRecord::ProtectedEnvironmentError) do ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! end |