diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-10-08 17:24:40 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-10-11 18:06:19 +0300 |
commit | 21940d1edf1604f192957691e99677d191380543 (patch) | |
tree | f9760a1263c9128aca629df81264ea98946055e7 /spec | |
parent | a5ca102aa1440150717a470059f707d5e5842782 (diff) |
Support pushing of feature flags to the frontend
This adds a method to Gitlab::GonHelper called
`push_frontend_feature_flag`. This method can be used to easily expose
the state of a feature flag to Javascript code. For example, using this
method we may write the following controller code:
before_action do
push_frontend_feature_flag(:vim_bindings)
end
def index
# ...
end
def edit
# ...
end
In Javascript we can then check the state of the flag as follows:
if ( gon.features.vimBindings ) {
// ...
}
Fixes https://gitlab.com/gitlab-org/release/framework/issues/17
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/gon_helper_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb new file mode 100644 index 00000000000..c6f09ca2112 --- /dev/null +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::GonHelper do + let(:helper) do + Class.new do + include Gitlab::GonHelper + end.new + end + + describe '#push_frontend_feature_flag' do + it 'pushes a feature flag to the frontend' do + gon = instance_double('gon') + + allow(helper) + .to receive(:gon) + .and_return(gon) + + expect(Feature) + .to receive(:enabled?) + .with(:my_feature_flag, 10) + .and_return(true) + + expect(gon) + .to receive(:push) + .with({ features: { 'myFeatureFlag' => true } }, true) + + helper.push_frontend_feature_flag(:my_feature_flag, 10) + end + end +end |