diff options
-rw-r--r-- | config/routes/api.rb | 2 | ||||
-rw-r--r-- | lib/constraints/feature_constrainer.rb | 8 | ||||
-rw-r--r-- | spec/lib/constraints/feature_constrainer_spec.rb | 11 |
3 files changed, 16 insertions, 5 deletions
diff --git a/config/routes/api.rb b/config/routes/api.rb index 5398e726398..3719b7d3a1e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -1,4 +1,4 @@ -constraints(::Constraints::FeatureConstrainer.new(:graphql, nil, true)) do +constraints(::Constraints::FeatureConstrainer.new(:graphql, default_enabled: true)) do post '/api/graphql', to: 'graphql#execute' mount GraphiQL::Rails::Engine, at: '/-/graphql-explorer', graphql_path: '/api/graphql' end diff --git a/lib/constraints/feature_constrainer.rb b/lib/constraints/feature_constrainer.rb index 5f8d97c8cdc..cd246cf37a4 100644 --- a/lib/constraints/feature_constrainer.rb +++ b/lib/constraints/feature_constrainer.rb @@ -2,14 +2,14 @@ module Constraints class FeatureConstrainer - attr_reader :feature, :thing, :default_enabled + attr_reader :args - def initialize(feature, thing, default_enabled) - @feature, @thing, @default_enabled = feature, thing, default_enabled + def initialize(*args) + @args = args end def matches?(_request) - Feature.enabled?(feature, @thing, default_enabled: true) + Feature.enabled?(*args) end end end diff --git a/spec/lib/constraints/feature_constrainer_spec.rb b/spec/lib/constraints/feature_constrainer_spec.rb new file mode 100644 index 00000000000..42efc164f81 --- /dev/null +++ b/spec/lib/constraints/feature_constrainer_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Constraints::FeatureConstrainer do + describe '#matches' do + it 'calls Feature.enabled? with the correct arguments' do + expect(Feature).to receive(:enabled?).with(:feature_name, "an object", default_enabled: true) + + described_class.new(:feature_name, "an object", default_enabled: true).matches?(double('request')) + end + end +end |