Skip to content

Commit c2fa536

Browse files
authored
Merge pull request rails#26755 from rafaelfranca/deprecations
Remove deprecations in Active Model, Action View and Active Job
2 parents 36f6ab2 + 6a78e0e commit c2fa536

File tree

12 files changed

+25
-300
lines changed

12 files changed

+25
-300
lines changed

actionview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Removed deprecated `#original_exception` in `ActionView::Template::Error`.
2+
3+
*Rafael Mendonça França*
4+
15
* Render now accepts any keys for locals, including reserved words
26

37
Only locals with valid variable names get set directly. Others

actionview/lib/action_view/template/error.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,13 @@ class Error < ActionViewError #:nodoc:
6363
# Override to prevent #cause resetting during re-raise.
6464
attr_reader :cause
6565

66-
def initialize(template, original_exception = nil)
67-
if original_exception
68-
ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
69-
"Exceptions will automatically capture the original exception.", caller)
70-
end
71-
66+
def initialize(template)
7267
super($!.message)
7368
set_backtrace($!.backtrace)
7469
@cause = $!
7570
@template, @sub_templates = template, nil
7671
end
7772

78-
def original_exception
79-
ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
80-
cause
81-
end
82-
8373
def file_name
8474
@template.identifier
8575
end

activejob/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Removed deprecated support to passing the adapter class to `.queue_adapter`.
2+
3+
*Rafael Mendonça França*
4+
5+
* Removed deprecated `#original_exception` in `ActiveJob::DeserializationError`.
6+
7+
*Rafael Mendonça França*
8+
19
* Added instance variable `@queue` to JobWrapper.
210

311
This will fix issues in [resque-scheduler](https://github.com/resque/resque-scheduler) `#job_to_hash` method,

activejob/lib/active_job/arguments.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@ module ActiveJob
55
#
66
# Wraps the original exception raised as +cause+.
77
class DeserializationError < StandardError
8-
def initialize(e = nil) #:nodoc:
9-
if e
10-
ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
11-
"Exceptions will automatically capture the original exception.", caller)
12-
end
13-
8+
def initialize #:nodoc:
149
super("Error while trying to deserialize arguments: #{$!.message}")
1510
set_backtrace $!.backtrace
1611
end
17-
18-
# The original exception that was raised during deserialization of job
19-
# arguments.
20-
def original_exception
21-
ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
22-
cause
23-
end
2412
end
2513

2614
# Raised when an unsupported argument type is set as a job argument. We

activejob/lib/active_job/queue_adapter.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ def interpret_adapter(name_or_adapter_or_class)
3737
else
3838
if queue_adapter?(name_or_adapter_or_class)
3939
name_or_adapter_or_class
40-
elsif queue_adapter_class?(name_or_adapter_or_class)
41-
ActiveSupport::Deprecation.warn "Passing an adapter class is deprecated " \
42-
"and will be removed in Rails 5.1. Please pass an adapter name " \
43-
"(.queue_adapter = :#{name_or_adapter_or_class.name.demodulize.remove('Adapter').underscore}) " \
44-
"or an instance (.queue_adapter = #{name_or_adapter_or_class.name}.new) instead."
45-
name_or_adapter_or_class.new
4640
else
4741
raise ArgumentError
4842
end
@@ -54,10 +48,6 @@ def interpret_adapter(name_or_adapter_or_class)
5448
def queue_adapter?(object)
5549
QUEUE_ADAPTER_METHODS.all? { |meth| object.respond_to?(meth) }
5650
end
57-
58-
def queue_adapter_class?(object)
59-
object.is_a?(Class) && QUEUE_ADAPTER_METHODS.all? { |meth| object.public_method_defined?(meth) }
60-
end
6151
end
6252
end
6353
end

activejob/test/cases/queue_adapter_test.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ class QueueAdapterTest < ActiveJob::TestCase
2020
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex.new }
2121
end
2222

23-
test "should warn on passing an adapter class" do
24-
klass = Class.new do
25-
def self.name
26-
"fake"
27-
end
28-
29-
def enqueue(*); end
30-
def enqueue_at(*); end
31-
end
32-
33-
assert_deprecated { ActiveJob::Base.queue_adapter = klass }
34-
end
35-
3623
test "should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling" do
3724
base_queue_adapter = ActiveJob::Base.queue_adapter
3825

activemodel/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
* Removed deprecated `:tokenizer` in the length validator.
2+
3+
*Rafael Mendonça França*
4+
5+
* Removed deprecated methods in `ActiveModel::Errors`.
6+
7+
`#get`, `#set`, `[]=`, `add_on_empty` and `add_on_blank`.
8+
9+
*Rafael Mendonça França*
10+
111

212
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activemodel/CHANGELOG.md) for previous changes.

activemodel/lib/active_model/errors.rb

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,6 @@ def include?(attribute)
115115
alias :has_key? :include?
116116
alias :key? :include?
117117

118-
# Get messages for +key+.
119-
#
120-
# person.errors.messages # => {:name=>["cannot be nil"]}
121-
# person.errors.get(:name) # => ["cannot be nil"]
122-
# person.errors.get(:age) # => []
123-
def get(key)
124-
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
125-
ActiveModel::Errors#get is deprecated and will be removed in Rails 5.1.
126-
127-
To achieve the same use model.errors[:#{key}].
128-
MESSAGE
129-
130-
messages[key]
131-
end
132-
133-
# Set messages for +key+ to +value+.
134-
#
135-
# person.errors[:name] # => ["cannot be nil"]
136-
# person.errors.set(:name, ["can't be nil"])
137-
# person.errors[:name] # => ["can't be nil"]
138-
def set(key, value)
139-
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
140-
ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1.
141-
142-
Use model.errors.add(:#{key}, #{value.inspect}) instead.
143-
MESSAGE
144-
145-
messages[key] = value
146-
end
147-
148118
# Delete messages for +key+. Returns the deleted messages.
149119
#
150120
# person.errors[:name] # => ["cannot be nil"]
@@ -173,20 +143,6 @@ def [](attribute)
173143
messages[attribute.to_sym]
174144
end
175145

176-
# Adds to the supplied attribute the supplied error message.
177-
#
178-
# person.errors[:name] = "must be set"
179-
# person.errors[:name] # => ['must be set']
180-
def []=(attribute, error)
181-
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
182-
ActiveModel::Errors#[]= is deprecated and will be removed in Rails 5.1.
183-
184-
Use model.errors.add(:#{attribute}, #{error.inspect}) instead.
185-
MESSAGE
186-
187-
messages[attribute.to_sym] << error
188-
end
189-
190146
# Iterates through each error key, value pair in the error messages hash.
191147
# Yields the attribute and the error for that attribute. If the attribute
192148
# has more than one error message, yields once for each error message.
@@ -338,49 +294,6 @@ def add(attribute, message = :invalid, options = {})
338294
messages[attribute.to_sym] << message
339295
end
340296

341-
# Will add an error message to each of the attributes in +attributes+
342-
# that is empty.
343-
#
344-
# person.errors.add_on_empty(:name)
345-
# person.errors.messages
346-
# # => {:name=>["can't be empty"]}
347-
def add_on_empty(attributes, options = {})
348-
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
349-
ActiveModel::Errors#add_on_empty is deprecated and will be removed in Rails 5.1.
350-
351-
To achieve the same use:
352-
353-
errors.add(attribute, :empty, options) if value.nil? || value.empty?
354-
MESSAGE
355-
356-
Array(attributes).each do |attribute|
357-
value = @base.send(:read_attribute_for_validation, attribute)
358-
is_empty = value.respond_to?(:empty?) ? value.empty? : false
359-
add(attribute, :empty, options) if value.nil? || is_empty
360-
end
361-
end
362-
363-
# Will add an error message to each of the attributes in +attributes+ that
364-
# is blank (using Object#blank?).
365-
#
366-
# person.errors.add_on_blank(:name)
367-
# person.errors.messages
368-
# # => {:name=>["can't be blank"]}
369-
def add_on_blank(attributes, options = {})
370-
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
371-
ActiveModel::Errors#add_on_blank is deprecated and will be removed in Rails 5.1.
372-
373-
To achieve the same use:
374-
375-
errors.add(attribute, :blank, options) if value.blank?
376-
MESSAGE
377-
378-
Array(attributes).each do |attribute|
379-
value = @base.send(:read_attribute_for_validation, attribute)
380-
add(attribute, :blank, options) if value.blank?
381-
end
382-
end
383-
384297
# Returns +true+ if an error on the attribute with the given message is
385298
# present, or +false+ otherwise. +message+ is treated the same as for +add+.
386299
#

activemodel/lib/active_model/validations/length.rb

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class LengthValidator < EachValidator # :nodoc:
66
MESSAGES = { is: :wrong_length, minimum: :too_short, maximum: :too_long }.freeze
77
CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze
88

9-
RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
9+
RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :too_short, :too_long]
1010

1111
def initialize(options)
1212
if range = (options.delete(:in) || options.delete(:within))
@@ -18,27 +18,6 @@ def initialize(options)
1818
options[:minimum] = 1
1919
end
2020

21-
if options[:tokenizer]
22-
ActiveSupport::Deprecation.warn(<<-EOS.strip_heredoc)
23-
The `:tokenizer` option is deprecated, and will be removed in Rails 5.1.
24-
You can achieve the same functionality by defining an instance method
25-
with the value that you want to validate the length of. For example,
26-
27-
validates_length_of :essay, minimum: 100,
28-
tokenizer: ->(str) { str.scan(/\w+/) }
29-
30-
should be written as
31-
32-
validates_length_of :words_in_essay, minimum: 100
33-
34-
private
35-
36-
def words_in_essay
37-
essay.scan(/\w+/)
38-
end
39-
EOS
40-
end
41-
4221
super
4322
end
4423

@@ -59,7 +38,6 @@ def check_validity!
5938
end
6039

6140
def validate_each(record, attribute, value)
62-
value = tokenize(record, value)
6341
value_length = value.respond_to?(:length) ? value.length : value.to_s.length
6442
errors_options = options.except(*RESERVED_OPTIONS)
6543

@@ -80,17 +58,6 @@ def validate_each(record, attribute, value)
8058
end
8159

8260
private
83-
def tokenize(record, value)
84-
tokenizer = options[:tokenizer]
85-
if tokenizer && value.kind_of?(String)
86-
if tokenizer.kind_of?(Proc)
87-
tokenizer.call(value)
88-
elsif record.respond_to?(tokenizer)
89-
record.send(tokenizer, value)
90-
end
91-
end || value
92-
end
93-
9461
def skip_nil_check?(key)
9562
key == :maximum && options[:allow_nil].nil? && options[:allow_blank].nil?
9663
end

0 commit comments

Comments
 (0)