Verified Commit a40702b4 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

improve actions_list to accept also string and action_name?, as choices

parent c8933b1f
Pipeline #13919 failed with stage
in 25 minutes and 20 seconds
...@@ -60,18 +60,20 @@ class ActiveSupport::TestCase ...@@ -60,18 +60,20 @@ class ActiveSupport::TestCase
(1..cols).to_a.each { |column| assert_nil wb.cell(row, column) } (1..cols).to_a.each { |column| assert_nil wb.cell(row, column) }
end end
def controllers_action_list(controller = nil) def controllers_action_list(controller_name = nil)
controller ||= self.class.name.remove('PolicyTest').underscore.pluralize controller_name ||= self.class.name.remove('PolicyTest').underscore.pluralize
controller_routes = Rails.application.routes.routes.find_all do |route| Rails
route.defaults[:controller] == controller.to_s .application.routes.routes
end .find_all { |route| route.defaults[:controller] == controller_name.to_s }
acts = controller_routes.map { |route| route.defaults[:action] }.uniq .map { |route| route.defaults[:action] }.uniq
acts.map { |action| [action.to_sym, "#{action}?"] }.to_h .map { |action| [action.to_sym, "#{action}?"] }.to_h
end end
def actions_list(*choices) def actions_list(*choices)
if choices.any? if choices.any?
controllers_action_list.values_at(*choices) controllers_action_list.values_at(
*choices.map { |choice| choice.to_s.remove(/\?$/).to_sym }
)
else else
controllers_action_list controllers_action_list
end end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment