aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/errors.rb7
-rw-r--r--activemodel/test/cases/errors_test.rb8
-rw-r--r--activesupport/lib/active_support/tagged_logging.rb5
3 files changed, 16 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index c6535082d3..5cd8f77f0d 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -78,6 +78,11 @@ module ActiveModel
@messages = ActiveSupport::OrderedHash.new
end
+ def initialize_dup(other)
+ @messages = other.messages.dup
+ super
+ end
+
# Clear the messages
def clear
messages.clear
@@ -118,7 +123,7 @@ module ActiveModel
# p.errors[:name] = "must be set"
# p.errors[:name] # => ['must be set']
def []=(attribute, error)
- self[attribute.to_sym] << error
+ self[attribute] << error
end
# Iterates through each error key, value pair in the error messages hash.
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 4edeece3e8..ab80f193b6 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -40,6 +40,14 @@ class ErrorsTest < ActiveModel::TestCase
assert errors.include?(:foo), 'errors should include :foo'
end
+ def test_dup
+ errors = ActiveModel::Errors.new(self)
+ errors[:foo] = 'bar'
+ errors_dup = errors.dup
+ errors_dup[:bar] = 'omg'
+ assert_not_same errors_dup.messages, errors.messages
+ end
+
def test_has_key?
errors = ActiveModel::Errors.new(self)
errors[:foo] = 'omg'
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb
index dc3ca25938..4e2e1a1ff5 100644
--- a/activesupport/lib/active_support/tagged_logging.rb
+++ b/activesupport/lib/active_support/tagged_logging.rb
@@ -14,7 +14,6 @@ module ActiveSupport
class TaggedLogging
def initialize(logger)
@logger = logger
- @tags = Hash.new { |h,k| h[k] = [] }
end
def tagged(*new_tags)
@@ -39,7 +38,7 @@ module ActiveSupport
end
def flush
- @tags.delete(Thread.current)
+ current_tags.clear
@logger.flush if @logger.respond_to?(:flush)
end
@@ -57,7 +56,7 @@ module ActiveSupport
end
def current_tags
- @tags[Thread.current]
+ Thread.current[:activesupport_tagged_logging_tags] ||= []
end
end
end