Rename FLippable to FeatureGate and make flipper_group and user mutually exclusive

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2017-06-27 18:58:56 +02:00
parent b4d325c80c
commit 5fa9d6a17d
6 changed files with 24 additions and 16 deletions

View file

@ -1,4 +1,4 @@
module Flippable
module FeatureGate
def flipper_id
return nil if new_record?

View file

@ -11,7 +11,7 @@ class User < ActiveRecord::Base
include CaseSensitivity
include TokenAuthenticatable
include IgnorableColumn
include Flippable
include FeatureGate
DEFAULT_NOTIFICATION_LEVEL = :participating

View file

@ -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
```

View file

@ -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])

View file

@ -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

View file

@ -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')