summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-06-27 18:58:56 +0200
committerRémy Coutable <remy@rymai.me>2017-06-27 18:59:51 +0200
commit5fa9d6a17dac86e9976946ded7857e1392403136 (patch)
tree842b40fb6948b5ba444d9b526554393cede3ba2a
parentb4d325c80c63ee9ee2676a57a42fac472b5b20d5 (diff)
downloadgitlab-ce-5fa9d6a17dac86e9976946ded7857e1392403136.tar.gz
Rename FLippable to FeatureGate and make `flipper_group` and `user` mutually exclusive
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--app/models/concerns/feature_gate.rb (renamed from app/models/concerns/flippable.rb)2
-rw-r--r--app/models/user.rb2
-rw-r--r--doc/api/features.md2
-rw-r--r--lib/api/features.rb1
-rw-r--r--spec/models/concerns/feature_gate_spec.rb19
-rw-r--r--spec/models/user_spec.rb14
6 files changed, 24 insertions, 16 deletions
diff --git a/app/models/concerns/flippable.rb b/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')