Commit 2a9401dd authored by Sean McGivern's avatar Sean McGivern

Use DSL style for feature categories in users API

This isn't possible for custom attributes, as they're a mixin, but
everywhere else can use the DSL style.

This also means a slight tweak to the validation in WithFeatureCategory:
previously we didn't allow duplicates at all, but now we allow
duplicates with the same category. That's because the API supports
different HTTP methods to the same path, but those methods will always
be the same category. Omitting the feature category from the duplicates
would look odd.
parent 753a3da0
This diff is collapsed.
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
def validate_config!(config) def validate_config!(config)
empty = config.find { |_, actions| actions.empty? } empty = config.find { |_, actions| actions.empty? }
duplicate_actions = config.values.flatten.group_by(&:itself).select { |_, v| v.count > 1 }.keys duplicate_actions = config.values.map(&:uniq).flatten.group_by(&:itself).select { |_, v| v.count > 1 }.keys
if config.length > 1 && empty if config.length > 1 && empty
raise ArgumentError, "#{empty.first} is defined for all actions, but other categories are set" raise ArgumentError, "#{empty.first} is defined for all actions, but other categories are set"
......
...@@ -56,5 +56,14 @@ RSpec.describe Gitlab::WithFeatureCategory do ...@@ -56,5 +56,14 @@ RSpec.describe Gitlab::WithFeatureCategory do
end end
end.to raise_error(ArgumentError, "Actions have multiple feature categories: world") end.to raise_error(ArgumentError, "Actions have multiple feature categories: world")
end end
it "does not raise an error when multiple calls define the same action and feature category" do
expect do
Class.new(base_controller) do
feature_category :hello, [:world]
feature_category :hello, ["world"]
end
end.not_to raise_error
end
end end
end end
Markdown is supported
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