Skip to content

Commit

Permalink
Merge pull request #15603 from kuldeepaggarwal/remove-deprecation-method
Browse files Browse the repository at this point in the history
remove depricated Validatior#setup
  • Loading branch information
rafaelfranca committed Jun 10, 2014
2 parents be5d648 + e5cc892 commit d5f480c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
16 changes: 0 additions & 16 deletions activemodel/lib/active_model/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def self.kind
# Accepts options that will be made available through the +options+ reader.
def initialize(options = {})
@options = options.except(:class).freeze
deprecated_setup(options)
end

# Returns the kind for this validator.
Expand All @@ -122,21 +121,6 @@ def kind
def validate(record)
raise NotImplementedError, "Subclasses must implement a validate(record) method."
end

private
def deprecated_setup(options) # TODO: remove me in 4.2.
return unless respond_to?(:setup)
ActiveSupport::Deprecation.warn "The `Validator#setup` instance method is deprecated and will be removed on Rails 4.2. Do your setup in the constructor instead:
class MyValidator < ActiveModel::Validator
def initialize(options={})
super
options[:class].send :attr_accessor, :custom_attribute
end
end
"
setup(options[:class])
end
end

# +EachValidator+ is a validator which iterates through the attributes given
Expand Down
21 changes: 0 additions & 21 deletions activemodel/test/cases/validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,25 +378,4 @@ def test_dup_validity_is_independent
assert topic.invalid?
assert duped.valid?
end

# validator test:
def test_setup_is_deprecated_but_still_receives_klass # TODO: remove me in 4.2.
validator_class = Class.new(ActiveModel::Validator) do
def setup(klass)
@old_klass = klass
end

def validate(*)
@old_klass == Topic or raise "#setup didn't work"
end
end

assert_deprecated do
Topic.validates_with validator_class
end

t = Topic.new
t.valid?
end

end

0 comments on commit d5f480c

Please sign in to comment.