diff --git a/app/models/concerns/flippable.rb b/app/models/concerns/feature_gate.rb similarity index 82% rename from app/models/concerns/flippable.rb rename to app/models/concerns/feature_gate.rb index 341501e8250..5db64fe82c4 100644 --- a/app/models/concerns/flippable.rb +++ b/app/models/concerns/feature_gate.rb @@ -1,4 +1,4 @@ -module Flippable +module FeatureGate def flipper_id return nil if new_record? diff --git a/app/models/user.rb b/app/models/user.rb index bcce260ab08..e08096284ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,7 +11,7 @@ class User < ActiveRecord::Base include CaseSensitivity include TokenAuthenticatable include IgnorableColumn - include Flippable + include FeatureGate DEFAULT_NOTIFICATION_LEVEL = :participating diff --git a/doc/api/features.md b/doc/api/features.md index 0ca2e637614..a3bf5d018a7 100644 --- a/doc/api/features.md +++ b/doc/api/features.md @@ -61,6 +61,8 @@ POST /features/:name | `flipper_group` | string | no | A Flipper group name | | `user` | string | no | A GitLab username | +Note that `flipper_group` and `user` are mutually exclusive. + ```bash curl --data "value=30" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/features/new_library ``` diff --git a/lib/api/features.rb b/lib/api/features.rb index 4e10e36fce9..e426bc050eb 100644 --- a/lib/api/features.rb +++ b/lib/api/features.rb @@ -42,6 +42,7 @@ module API requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time' optional :flipper_group, type: String, desc: 'A Flipper group name' optional :user, type: String, desc: 'A GitLab username' + mutually_exclusive :flipper_group, :user end post ':name' do feature = Feature.get(params[:name]) diff --git a/spec/models/concerns/feature_gate_spec.rb b/spec/models/concerns/feature_gate_spec.rb new file mode 100644 index 00000000000..3f601243245 --- /dev/null +++ b/spec/models/concerns/feature_gate_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe FeatureGate do + describe 'User' do + describe '#flipper_id' do + context 'when user is not persisted' do + let(:user) { build(:user) } + + it { expect(user.flipper_id).to be_nil } + end + + context 'when user is persisted' do + let(:user) { create(:user) } + + it { expect(user.flipper_id).to eq "User:#{user.id}" } + end + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 05ba887c51f..8e895ec6634 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -430,20 +430,6 @@ describe User, models: true do end end - describe '#flipper_id' do - context 'when user is not persisted' do - let(:user) { build(:user) } - - it { expect(user.flipper_id).to be_nil } - end - - context 'when user is persisted' do - let(:user) { create(:user) } - - it { expect(user.flipper_id).to eq "User:#{user.id}" } - end - end - describe '#generate_password' do it "does not generate password by default" do user = create(:user, password: 'abcdefghe')