From f0ee4a6002d4f7e27fb472051778eed8c4a3b47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 29 Aug 2010 20:45:34 -0300 Subject: Remove deprecations in ActiveModel. --- activemodel/lib/active_model.rb | 1 - .../lib/active_model/deprecated_error_methods.rb | 33 -------------------- activemodel/lib/active_model/errors.rb | 23 -------------- activemodel/lib/active_model/translation.rb | 6 ---- activemodel/test/cases/validations_test.rb | 36 ---------------------- 5 files changed, 99 deletions(-) delete mode 100644 activemodel/lib/active_model/deprecated_error_methods.rb diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index 5ed21a39c2..9b8f843432 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -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 diff --git a/activemodel/lib/active_model/deprecated_error_methods.rb b/activemodel/lib/active_model/deprecated_error_methods.rb deleted file mode 100644 index adc50773d9..0000000000 --- a/activemodel/lib/active_model/deprecated_error_methods.rb +++ /dev/null @@ -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 diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 14312283d1..e9a61daab2 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -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 @@ module ActiveModel # 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 @@ module ActiveModel # 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 @@ module ActiveModel 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}" ] diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 6c1cecd9b7..dbb76244e4 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -54,11 +54,5 @@ module ActiveModel 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 diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 1eed0b0c4d..4024002aaa 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -215,42 +215,6 @@ class ValidationsTest < ActiveModel::TestCase 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 }) -- cgit v1.2.3