aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/CHANGELOG.md10
-rw-r--r--activemodel/lib/active_model/validations.rb15
-rw-r--r--activemodel/test/cases/validations_test.rb8
3 files changed, 1 insertions, 32 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md
index 2a5598e1b2..2c966943ee 100644
--- a/activemodel/CHANGELOG.md
+++ b/activemodel/CHANGELOG.md
@@ -1,15 +1,5 @@
## Rails 4.0.0 (unreleased) ##
-* `ActiveModel::Validators#validators_on` now accepts a `:kind` option which will filter out the
- validators on a particular attribute based on its kind.
-
- Person.validators_on(:name)
- # => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
- # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}>]
-
- Person.validators_on(:name, kind: :presence)
- # => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>]
-
* Add `ActiveModel::ForbiddenAttributesProtection`, a simple module to
protect attributes from mass assignment when non-permitted attributes are passed.
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index be780d570b..4762f39044 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -187,23 +187,10 @@ module ActiveModel
# # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
# # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}>
# # ]
- #
- # You can also pass a +:kind+ option to filter the validators based on their kind.
- #
- # Person.validators_on(:name, kind: :presence)
- # # => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>]
def validators_on(*attributes)
- options = attributes.extract_options!
-
- validators = attributes.map do |attribute|
+ attributes.map do |attribute|
_validators[attribute.to_sym]
end.flatten
-
- if options[:kind]
- validators.select! { |validator| validator.kind == options[:kind] }
- else
- validators
- end
end
# Returns +true+ if +attribute+ is an attribute method, +false+ otherwise.
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index 66d9e51854..a9d32808da 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -287,14 +287,6 @@ class ValidationsTest < ActiveModel::TestCase
assert_equal [], Topic.validators_on(:author_name)
end
- def test_list_of_validators_on_an_attribute_based_on_kind
- Topic.validates_presence_of :title, :content
- Topic.validates_length_of :title, :minimum => 2
-
- assert_equal Topic.validators_on(:title).select { |v| v.kind == :presence },
- Topic.validators_on(:title, kind: :presence)
- end
-
def test_validations_on_the_instance_level
auto = Automobile.new