adds #feature_flag? to Setting
This commit is contained in:
@@ -3,6 +3,10 @@ class Setting < ActiveRecord::Base
|
|||||||
|
|
||||||
default_scope { order(id: :asc) }
|
default_scope { order(id: :asc) }
|
||||||
|
|
||||||
|
def feature_flag?
|
||||||
|
key.start_with?('feature.')
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def [](key)
|
def [](key)
|
||||||
where(key: key).pluck(:value).first.presence
|
where(key: key).pluck(:value).first.presence
|
||||||
|
|||||||
@@ -16,4 +16,16 @@ describe Setting do
|
|||||||
it "should persist a setting on the db" do
|
it "should persist a setting on the db" do
|
||||||
expect(Setting.where(key: 'official_level_1_name', value: 'Stormtrooper')).to exist
|
expect(Setting.where(key: 'official_level_1_name', value: 'Stormtrooper')).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#feature_flag?" do
|
||||||
|
it "should be true if key starts with 'feature.'" do
|
||||||
|
setting = Setting.create(key: 'feature.whatever')
|
||||||
|
expect(setting.feature_flag?).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be false if key does not start with 'feature.'" do
|
||||||
|
setting = Setting.create(key: 'whatever')
|
||||||
|
expect(setting.feature_flag?).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user