2020-07-07 09:08:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
2020-10-26 18:08:27 +00:00
|
|
|
require_relative "../../../lib/gitlab/with_feature_category"
|
2020-07-07 09:08:57 +00:00
|
|
|
|
2020-10-26 18:08:27 +00:00
|
|
|
RSpec.describe Gitlab::WithFeatureCategory do
|
2020-07-07 09:08:57 +00:00
|
|
|
describe ".feature_category_for_action" do
|
|
|
|
let(:base_controller) do
|
|
|
|
Class.new do
|
2020-10-26 18:08:27 +00:00
|
|
|
include ::Gitlab::WithFeatureCategory
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:controller) do
|
|
|
|
Class.new(base_controller) do
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :foo, %w(update edit)
|
|
|
|
feature_category :bar, %w(index show)
|
|
|
|
feature_category :quux, %w(destroy)
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:subclass) do
|
|
|
|
Class.new(controller) do
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :baz, %w(subclass_index)
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is nil when nothing was defined" do
|
|
|
|
expect(base_controller.feature_category_for_action("hello")).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the expected category", :aggregate_failures do
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(controller.feature_category_for_action("update")).to eq(:foo)
|
2020-07-07 09:08:57 +00:00
|
|
|
expect(controller.feature_category_for_action("index")).to eq(:bar)
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(controller.feature_category_for_action("destroy")).to eq(:quux)
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it "returns the expected category for categories defined in subclasses" do
|
|
|
|
expect(subclass.feature_category_for_action("subclass_index")).to eq(:baz)
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it "raises an error when defining for the controller and for individual actions" do
|
2020-07-07 09:08:57 +00:00
|
|
|
expect do
|
|
|
|
Class.new(base_controller) do
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :hello
|
|
|
|
feature_category :goodbye, [:world]
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
2020-10-02 12:09:03 +00:00
|
|
|
end.to raise_error(ArgumentError, "hello is defined for all actions, but other categories are set")
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it "raises an error when multiple calls define the same action" do
|
2020-07-07 09:08:57 +00:00
|
|
|
expect do
|
|
|
|
Class.new(base_controller) do
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :hello, [:world]
|
|
|
|
feature_category :goodbye, ["world"]
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
2020-10-02 12:09:03 +00:00
|
|
|
end.to raise_error(ArgumentError, "Actions have multiple feature categories: world")
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
2020-10-26 18:08:27 +00:00
|
|
|
|
|
|
|
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
|
2020-07-07 09:08:57 +00:00
|
|
|
end
|
|
|
|
end
|