Remove deprecations in ActiveModel.
This commit is contained in:
parent
972efa11fd
commit
f0ee4a6002
@ -33,7 +33,6 @@ module ActiveModel
|
||||
autoload :BlockValidator, 'active_model/validator'
|
||||
autoload :Callbacks
|
||||
autoload :Conversion
|
||||
autoload :DeprecatedErrorMethods
|
||||
autoload :Dirty
|
||||
autoload :EachValidator, 'active_model/validator'
|
||||
autoload :Errors
|
||||
|
@ -1,33 +0,0 @@
|
||||
module ActiveModel
|
||||
module DeprecatedErrorMethods
|
||||
def on(attribute)
|
||||
message = "Errors#on have been deprecated, use Errors#[] instead.\n"
|
||||
message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is "
|
||||
message << "returned when there are no errors on the specified attribute."
|
||||
ActiveSupport::Deprecation.warn(message)
|
||||
|
||||
errors = self[attribute]
|
||||
errors.size < 2 ? errors.first : errors
|
||||
end
|
||||
|
||||
def on_base
|
||||
ActiveSupport::Deprecation.warn "Errors#on_base have been deprecated, use Errors#[:base] instead"
|
||||
ActiveSupport::Deprecation.silence { on(:base) }
|
||||
end
|
||||
|
||||
def add_to_base(msg)
|
||||
ActiveSupport::Deprecation.warn "Errors#add_to_base(msg) has been deprecated, use Errors#add(:base, msg) instead"
|
||||
self[:base] << msg
|
||||
end
|
||||
|
||||
def invalid?(attribute)
|
||||
ActiveSupport::Deprecation.warn "Errors#invalid?(attribute) has been deprecated, use Errors#[attribute].any? instead"
|
||||
self[attribute].any?
|
||||
end
|
||||
|
||||
def each_full
|
||||
ActiveSupport::Deprecation.warn "Errors#each_full has been deprecated, use Errors#to_a.each instead"
|
||||
to_a.each { |error| yield error }
|
||||
end
|
||||
end
|
||||
end
|
@ -61,8 +61,6 @@ module ActiveModel
|
||||
# p.errors.full_messages # => ["name can not be nil"]
|
||||
# # etc..
|
||||
class Errors < ActiveSupport::OrderedHash
|
||||
include DeprecatedErrorMethods
|
||||
|
||||
CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank]
|
||||
|
||||
# Pass in the instance of the object that is using the errors object.
|
||||
@ -191,13 +189,6 @@ def add(attribute, message = nil, options = {})
|
||||
|
||||
# Will add an error message to each of the attributes in +attributes+ that is empty.
|
||||
def add_on_empty(attributes, options = {})
|
||||
if options && !options.is_a?(Hash)
|
||||
options = { :message => options }
|
||||
ActiveSupport::Deprecation.warn \
|
||||
"ActiveModel::Errors#add_on_empty(attributes, custom_message) has been deprecated.\n" +
|
||||
"Instead of passing a custom_message pass an options Hash { :message => custom_message }."
|
||||
end
|
||||
|
||||
[attributes].flatten.each do |attribute|
|
||||
value = @base.send(:read_attribute_for_validation, attribute)
|
||||
is_empty = value.respond_to?(:empty?) ? value.empty? : false
|
||||
@ -207,13 +198,6 @@ def add_on_empty(attributes, options = {})
|
||||
|
||||
# Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
|
||||
def add_on_blank(attributes, options = {})
|
||||
if options && !options.is_a?(Hash)
|
||||
options = { :message => options }
|
||||
ActiveSupport::Deprecation.warn \
|
||||
"ActiveModel::Errors#add_on_blank(attributes, custom_message) has been deprecated.\n" +
|
||||
"Instead of passing a custom_message pass an options Hash { :message => custom_message }."
|
||||
end
|
||||
|
||||
[attributes].flatten.each do |attribute|
|
||||
value = @base.send(:read_attribute_for_validation, attribute)
|
||||
add(attribute, :blank, options) if value.blank?
|
||||
@ -281,13 +265,6 @@ def full_messages
|
||||
def generate_message(attribute, type = :invalid, options = {})
|
||||
type = options.delete(:message) if options[:message].is_a?(Symbol)
|
||||
|
||||
if options[:default]
|
||||
ActiveSupport::Deprecation.warn \
|
||||
"ActiveModel::Errors#generate_message(attributes, custom_message) has been deprecated.\n" +
|
||||
"Use ActiveModel::Errors#generate_message(attributes, :message => 'your message') instead."
|
||||
options[:message] = options.delete(:default)
|
||||
end
|
||||
|
||||
defaults = @base.class.lookup_ancestors.map do |klass|
|
||||
[ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.attributes.#{attribute}.#{type}",
|
||||
:"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.#{type}" ]
|
||||
|
@ -54,11 +54,5 @@ def human_attribute_name(attribute, options = {})
|
||||
options.reverse_merge! :count => 1, :default => defaults
|
||||
I18n.translate(defaults.shift, options)
|
||||
end
|
||||
|
||||
# Model.human_name is deprecated. Use Model.model_name.human instead.
|
||||
def human_name(*args)
|
||||
ActiveSupport::Deprecation.warn("human_name has been deprecated, please use model_name.human instead", caller[0,5])
|
||||
model_name.human(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -215,42 +215,6 @@ def test_invalid_should_be_the_opposite_of_valid
|
||||
assert !t.invalid?
|
||||
end
|
||||
|
||||
def test_deprecated_error_messages_on
|
||||
Topic.validates_presence_of :title
|
||||
|
||||
t = Topic.new
|
||||
assert t.invalid?
|
||||
|
||||
[:title, "title"].each do |attribute|
|
||||
assert_deprecated { assert_equal "can't be blank", t.errors.on(attribute) }
|
||||
end
|
||||
|
||||
Topic.validates_each(:title) do |record, attribute|
|
||||
record.errors[attribute] << "invalid"
|
||||
end
|
||||
|
||||
assert t.invalid?
|
||||
|
||||
[:title, "title"].each do |attribute|
|
||||
assert_deprecated do
|
||||
assert t.errors.on(attribute).include?("invalid")
|
||||
assert t.errors.on(attribute).include?("can't be blank")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_deprecated_errors_on_base_and_each
|
||||
t = Topic.new
|
||||
assert t.valid?
|
||||
|
||||
assert_deprecated { t.errors.add_to_base "invalid topic" }
|
||||
assert_deprecated { assert_equal "invalid topic", t.errors.on_base }
|
||||
assert_deprecated { assert t.errors.invalid?(:base) }
|
||||
|
||||
all_errors = t.errors.to_a
|
||||
assert_deprecated { assert_equal all_errors, t.errors.each_full{|err| err} }
|
||||
end
|
||||
|
||||
def test_validation_with_message_as_proc
|
||||
Topic.validates_presence_of(:title, :message => proc { "no blanks here".upcase })
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user