diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 20 | ||||
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/version.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 15 |
5 files changed, 38 insertions, 7 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index bd9ed996fe..b722e70450 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,9 +1,7 @@ -## Rails 3.2.0 (unreleased) ## +## Rails 3.2.0 (January 20, 2012) ## * Deprecated `define_attr_method` in `ActiveModel::AttributeMethods`, because this only existed to - support methods like `set_table_name` in Active Record, which are themselves being deprecated. - - *Jon Leighton* + support methods like `set_table_name` in Active Record, which are themselves being deprecated. *Jon Leighton* * Add ActiveModel::Errors#added? to check if a specific error has been added *Martin Svalin* diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index aafd1c8a74..80621cd7da 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -79,6 +79,19 @@ module ActiveModel @messages = ActiveSupport::OrderedHash.new end + def initialize_dup(other) + @messages = other.messages.dup + end + + # Backport dup from 1.9 so that #initialize_dup gets called + unless Object.respond_to?(:initialize_dup) + def dup # :nodoc: + copy = super + copy.initialize_dup(self) + copy + end + end + # Clear the messages def clear messages.clear @@ -100,6 +113,11 @@ module ActiveModel messages[key] = value end + # Delete messages for +key+ + def delete(key) + messages.delete(key) + end + # When passed a symbol or a name of a method, returns an array of errors # for the method. # @@ -114,7 +132,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/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 755e54efcd..a253be6765 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -1,7 +1,7 @@ require 'active_support/inflector' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/module/introspection' -require 'active_support/core_ext/module/deprecation' +require 'active_support/deprecation' module ActiveModel class Name < String diff --git a/activemodel/lib/active_model/version.rb b/activemodel/lib/active_model/version.rb index 7c0530bad8..67d2460321 100644 --- a/activemodel/lib/active_model/version.rb +++ b/activemodel/lib/active_model/version.rb @@ -3,7 +3,7 @@ module ActiveModel MAJOR = 3 MINOR = 2 TINY = 0 - PRE = "rc2" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 8ddedb160a..e2dea12589 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -27,6 +27,13 @@ class ErrorsTest < ActiveModel::TestCase end end + def test_delete + errors = ActiveModel::Errors.new(self) + errors[:foo] = 'omg' + errors.delete(:foo) + assert errors[:foo].empty? + end + def test_include? errors = ActiveModel::Errors.new(self) errors[:foo] = 'omg' @@ -39,6 +46,14 @@ class ErrorsTest < ActiveModel::TestCase assert errors.has_key?(:foo), 'errors should have key :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 + test "should return true if no errors" do person = Person.new person.errors[:foo] |