Pass on arguments passed to the FeatureConstrainer
All arguments passed to the `FeatureConstrainer` will be passed on to the `Feature.enabled?` check.
This commit is contained in:
parent
744f6ed12b
commit
2e8d0153cd
3 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
11
spec/lib/constraints/feature_constrainer_spec.rb
Normal file
11
spec/lib/constraints/feature_constrainer_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue