@@ -199,13 +199,20 @@ def decide(user_context, key, decide_options = [])
199199 experiment = nil
200200 decision_source = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
201201
202- decision , reasons_received = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes , decide_options )
202+ variation , reasons_received = user_context . find_validated_forced_decision ( key , nil )
203203 reasons . push ( *reasons_received )
204204
205+ if variation
206+ decision = Optimizely ::DecisionService ::Decision . new ( nil , variation , Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ] )
207+ else
208+ decision , reasons_received = @decision_service . get_variation_for_feature ( config , feature_flag , user_context , decide_options )
209+ reasons . push ( *reasons_received )
210+ end
211+
205212 # Send impression event if Decision came from a feature test and decide options doesn't include disableDecisionEvent
206213 if decision . is_a? ( Optimizely ::DecisionService ::Decision )
207214 experiment = decision . experiment
208- rule_key = experiment [ 'key' ]
215+ rule_key = experiment ? experiment [ 'key' ] : nil
209216 variation = decision [ 'variation' ]
210217 variation_key = variation [ 'key' ]
211218 feature_enabled = variation [ 'featureEnabled' ]
@@ -291,6 +298,10 @@ def decide_for_keys(user_context, keys, decide_options = [])
291298 decisions
292299 end
293300
301+ def get_flag_variation_by_key ( flag_key , variation_key )
302+ project_config . get_variation_from_flag ( flag_key , variation_key )
303+ end
304+
294305 # Buckets visitor and sends impression event to Optimizely.
295306 #
296307 # @param experiment_key - Experiment which needs to be activated.
@@ -490,7 +501,8 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
490501 return false
491502 end
492503
493- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
504+ user_context = create_user_context ( user_id , attributes )
505+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
494506
495507 feature_enabled = false
496508 source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
@@ -739,7 +751,8 @@ def get_all_feature_variables(feature_flag_key, user_id, attributes = nil)
739751 return nil
740752 end
741753
742- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
754+ user_context = create_user_context ( user_id , attributes )
755+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
743756 variation = decision ? decision [ 'variation' ] : nil
744757 feature_enabled = variation ? variation [ 'featureEnabled' ] : false
745758 all_variables = { }
@@ -881,7 +894,8 @@ def get_variation_with_config(experiment_key, user_id, attributes, config)
881894
882895 return nil unless user_inputs_valid? ( attributes )
883896
884- variation_id , = @decision_service . get_variation ( config , experiment_id , user_id , attributes )
897+ user_context = create_user_context ( user_id , attributes )
898+ variation_id , = @decision_service . get_variation ( config , experiment_id , user_context )
885899 variation = config . get_variation_from_id ( experiment_key , variation_id ) unless variation_id . nil?
886900 variation_key = variation [ 'key' ] if variation
887901 decision_notification_type = if config . feature_experiment? ( experiment_id )
@@ -947,7 +961,8 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
947961 return nil
948962 end
949963
950- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
964+ user_context = create_user_context ( user_id , attributes )
965+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
951966 variation = decision ? decision [ 'variation' ] : nil
952967 feature_enabled = variation ? variation [ 'featureEnabled' ] : false
953968
@@ -1083,8 +1098,12 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
10831098 experiment_id = experiment [ 'id' ]
10841099 experiment_key = experiment [ 'key' ]
10851100
1086- variation_id = ''
1087- variation_id = config . get_variation_id_from_key_by_experiment_id ( experiment_id , variation_key ) if experiment_id != ''
1101+ if experiment_id != ''
1102+ variation_id = config . get_variation_id_from_key_by_experiment_id ( experiment_id , variation_key )
1103+ else
1104+ varaition = get_flag_variation_by_key ( flag_key , variation_key )
1105+ variation_id = varaition ? varaition [ 'id' ] : ''
1106+ end
10881107
10891108 metadata = {
10901109 flag_key : flag_key ,
0 commit comments