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:
Bob Van Landuyt 2018-12-14 14:27:26 +01:00
parent 744f6ed12b
commit 2e8d0153cd
3 changed files with 16 additions and 5 deletions

View File

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

View File

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

View 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