Skip to content

Commit 2950416

Browse files
committed
Make sure Queues are indexed by parameterized name
Instead of having them indexed by name and then having to go back and forth between the two ways (original name and parameterized name) in the URL. Also, ensure we use the parameterized name in the queues/index view when linking to each queue.
1 parent d843c9f commit 2950416

File tree

5 files changed

+21
-52
lines changed

5 files changed

+21
-52
lines changed

app/controllers/mission_control/jobs/queues_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ def show
1111

1212
private
1313
def set_queue
14-
@queue = ActiveJob.queues[params[:id]] || ActiveJob.queues.find { |q| q.id == params[:id] }
14+
@queue = ActiveJob.queues[params[:id]]
1515
end
1616
end

app/views/mission_control/jobs/queues/_queue.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<tr class="queue">
22
<td>
3-
<%= link_to queue.name, application_queue_path(@application, queue.name) %>
3+
<%= link_to queue.name, application_queue_path(@application, queue) %>
44
<% if queue.paused? %>
55
<span class="ml-4 tag is-warning">Paused</span>
66
<% end %>

lib/active_job/queues.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ class ActiveJob::Queues
1313
include Enumerable
1414

1515
delegate :each, to: :values
16-
delegate :values, to: :queues_by_name, private: true
17-
delegate :[], :size, :length, :to_s, :inspect, to: :queues_by_name
16+
delegate :values, to: :queues_by_id, private: true
17+
delegate :size, :length, :to_s, :inspect, to: :queues_by_id
1818

1919
def initialize(queues)
20-
@queues_by_name = queues.index_by(&:name).with_indifferent_access
20+
@queues_by_id = queues.index_by(&:id).with_indifferent_access
2121
end
2222

2323
def to_h
24-
queues_by_name.dup
24+
queues_by_id.dup
25+
end
26+
27+
def [](name)
28+
queues_by_id[name.to_s.parameterize]
2529
end
2630

2731
private
28-
attr_reader :queues_by_name
32+
attr_reader :queues_by_id
2933
end

test/active_job/queue_test.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

test/active_job/queues_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ class ActiveJob::QueuesTest < ActiveSupport::TestCase
1818
assert_equal queue_2, queues["queue_2"]
1919
end
2020

21+
test "direct access by name with special characters parameterized" do
22+
queue = ActiveJob::Queue.new("My-Queue_With.Special@Chars! and spaces")
23+
queues = ActiveJob::Queues.new([ queue ])
24+
25+
# Look-up queue by original name
26+
assert_equal queue, queues["My-Queue_With.Special@Chars! and spaces"]
27+
# Look-up queue by parameterized, URL-friendly name
28+
assert_equal queue, queues["my-queue_with-special-chars-and-spaces"]
29+
end
30+
2131
test "convert to hash" do
2232
queue_1 = create_queue "queue_1"
2333
queue_2 = create_queue "queue_2"

0 commit comments

Comments
 (0)