1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #7058 from frodsan/fix_as_random_tests

Fix tests that depend on run order
This commit is contained in:
Rafael Mendonça França 2012-08-24 08:56:16 -07:00
commit 2c571b3f05
6 changed files with 34 additions and 23 deletions

View file

@ -493,14 +493,18 @@ class BaseTest < ActiveSupport::TestCase
end
test "assets tags should use a Mailer's asset_host settings when available" do
ActionMailer::Base.config.asset_host = "global.com"
ActionMailer::Base.config.assets_dir = "global/"
begin
ActionMailer::Base.config.asset_host = "http://global.com"
ActionMailer::Base.config.assets_dir = "global/"
AssetMailer.asset_host = "http://local.com"
AssetMailer.asset_host = "http://local.com"
mail = AssetMailer.welcome
mail = AssetMailer.welcome
assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
ensure
AssetMailer.asset_host = ActionMailer::Base.config.asset_host
end
end
# Before and After hooks

View file

@ -11,7 +11,6 @@ class CustomSanitizer < ActiveModel::MassAssignmentSecurity::Sanitizer
end
class MassAssignmentSecurityTest < ActiveModel::TestCase
def test_attribute_protection
user = User.new
expected = { "name" => "John Smith", "email" => "john@smith.com" }
@ -96,7 +95,6 @@ class MassAssignmentSecurityTest < ActiveModel::TestCase
assert_blank TightDescendant.protected_attributes(:admin) - TightDescendant.attributes_protected_by_default
assert_equal Set.new(['name', 'address', 'admin', 'super_powers']), TightDescendant.accessible_attributes(:admin)
end
def test_mass_assignment_multiparameter_protector
@ -107,14 +105,14 @@ class MassAssignmentSecurityTest < ActiveModel::TestCase
end
def test_custom_sanitizer
old_sanitizer = User._mass_assignment_sanitizer
user = User.new
User.mass_assignment_sanitizer = CustomSanitizer.new
assert_raise StandardError do
user.sanitize_for_mass_assignment("admin" => true)
end
ensure
User.mass_assignment_sanitizer = nil
User.mass_assignment_sanitizer = old_sanitizer
end
end
end

View file

@ -1,3 +1,3 @@
class ClassFolder::ClassFolderSubclass < ClassFolder
ConstantInClassFolder
ConstantInClassFolder = 'indeed'
end

View file

@ -67,17 +67,24 @@ class QualifiedConstTest < ActiveSupport::TestCase
end
test "qualified_const_set" do
m = Module.new
assert_equal m, Object.qualified_const_set("QualifiedConstTestMod2", m)
assert_equal m, ::QualifiedConstTestMod2
begin
m = Module.new
assert_equal m, Object.qualified_const_set("QualifiedConstTestMod2", m)
assert_equal m, ::QualifiedConstTestMod2
# We are going to assign to existing constants on purpose, so silence warnings.
silence_warnings do
assert_equal true, QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", true)
assert_equal true, QualifiedConstTestMod::X
# We are going to assign to existing constants on purpose, so silence warnings.
silence_warnings do
assert_equal true, QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", true)
assert_equal true, QualifiedConstTestMod::X
assert_equal 10, QualifiedConstTestMod::M.qualified_const_set("X", 10)
assert_equal 10, QualifiedConstTestMod::M::X
assert_equal 10, QualifiedConstTestMod::M.qualified_const_set("X", 10)
assert_equal 10, QualifiedConstTestMod::M::X
end
ensure
silence_warnings do
QualifiedConstTestMod.qualified_const_set('QualifiedConstTestMod::X', false)
QualifiedConstTestMod::M.qualified_const_set('X', 1)
end
end
end

View file

@ -679,6 +679,8 @@ class DependenciesTest < ActiveSupport::TestCase
assert_equal true, M.unloadable
assert_equal false, M.unloadable
end
ensure
Object.class_eval { remove_const :M }
end
def test_unloadable_constants_should_receive_callback

View file

@ -169,11 +169,11 @@ class InflectorTest < ActiveSupport::TestCase
def test_underscore_acronym_sequence
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym("API")
inflect.acronym("HTML5")
inflect.acronym("JSON")
inflect.acronym("HTML")
end
assert_equal("html5_html_api", ActiveSupport::Inflector.underscore("HTML5HTMLAPI"))
assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
end
def test_underscore