Skip to content

Commit

Permalink
Deprecate any uses of class_name with Class objects
Browse files Browse the repository at this point in the history
Rails 5.1 dropped support for query values of type Class, and we should
have fixed most of them with ManageIQ#18827 and ManageIQ#18829, but since detecting
callers to put_or_update that do this could be difficult, we can still
support this by "fixing" it so rails 5.1 doesn't raise an exception,
and give us time to fix the caller.
  • Loading branch information
jrafanie authored and thearifismail committed Jun 3, 2019
1 parent e8877f0 commit d6a99a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/miq_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,17 @@ def activate_miq_task(args)

# default values for get operations
def self.default_get_options(options)
options.reverse_merge(
result = options.reverse_merge(
:queue_name => DEFAULT_QUEUE,
:state => STATE_READY,
:zone => Zone.determine_queue_zone(options)
)

if result[:class_name].kind_of?(Class)
ActiveSupport::Deprecation.warn("Rails 5.1 dropped support for Class query values, use a String for class_name.", caller[1..-1])
result[:class_name] = result[:class_name].name
end
result
end

private_class_method :default_get_options
Expand Down
10 changes: 10 additions & 0 deletions spec/models/miq_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,16 @@ def self.some_method(single_arg)
expect(MiqQueue.first.args).to eq([3, 3])
end

it "supports a Class object for the class name(deprecated)" do
expect(ActiveSupport::Deprecation).to receive(:warn).with(/use a String for class_name/, anything)
msg = MiqQueue.put_or_update(:class_name => MiqServer, :instance_id => @miq_server.id, :method_name => "my_zone")

status, message, result = msg.deliver
expect(status).to eq(MiqQueue::STATUS_OK)
expect(message).to eq("Message delivered successfully")
expect(result).to eq(@miq_server.my_zone)
end

it "should use args param to find messages on the queue" do
MiqQueue.put(
:class_name => 'MyClass',
Expand Down

0 comments on commit d6a99a6

Please sign in to comment.