diff --git a/lib/splitclient-rb/clients/split_client.rb b/lib/splitclient-rb/clients/split_client.rb index 69f7e906..4e6e17a7 100644 --- a/lib/splitclient-rb/clients/split_client.rb +++ b/lib/splitclient-rb/clients/split_client.rb @@ -273,6 +273,7 @@ def treatments(key, feature_flag_names, attributes = {}, options = nil, calling_ bucketing_key, matching_key = keys_from_key(key) bucketing_key = bucketing_key ? bucketing_key.to_s : nil matching_key = matching_key ? matching_key.to_s : nil + attributes = parsed_attributes(attributes) if !@config.split_validator.valid_get_treatments_parameters(calling_method, key, sanitized_feature_flag_names, matching_key, bucketing_key, attributes) to_return = Hash.new @@ -379,7 +380,7 @@ def evaluate_treatment(feature_flag, feature_flag_name, bucketing_key, matching_ impressions_disabled = false end - options, size = validate_options(options) + options, size = validate_options(options) unless options.nil? options[:properties] = nil unless options.nil? or check_properties_size((EVENT_AVERAGE_SIZE + size), "Properties are ignored") record_latency(calling_method, start) diff --git a/spec/cache/senders/impressions_formatter_spec.rb b/spec/cache/senders/impressions_formatter_spec.rb index 965665be..4e85dfeb 100644 --- a/spec/cache/senders/impressions_formatter_spec.rb +++ b/spec/cache/senders/impressions_formatter_spec.rb @@ -75,7 +75,7 @@ it 'formats multiple impressions for one key' do params = { attributes: {}, time: 1_478_113_518_900 } impressions = [] - impressions << { :impression => impressions_manager.build_impression('matching_key3', nil, 'foo2', treatment3, false, params, {"prop": "val"}), :disabled => false } + impressions << { :impression => impressions_manager.build_impression('matching_key3', nil, 'foo2', treatment3, false, params, {:properties => {:prop => "val"}}), :disabled => false } impressions_manager.track(impressions) expect(formatted_impressions.find { |i| i[:f] == :foo1 }[:i]).to match_array( diff --git a/spec/cache/senders/impressions_sender_spec.rb b/spec/cache/senders/impressions_sender_spec.rb index 219b789f..975d1a8b 100644 --- a/spec/cache/senders/impressions_sender_spec.rb +++ b/spec/cache/senders/impressions_sender_spec.rb @@ -46,7 +46,7 @@ params2 = { attributes: {}, time: 1_478_113_518_285 } impressions = [] impressions << { :impression => impressions_manager.build_impression('matching_key', 'foo1', 'foo1', treatment1, false, params), :disabled => false } - impressions << { :impression => impressions_manager.build_impression('matching_key2', 'foo2', 'foo2', treatment2, false, params2, {:prop=>"val"}), :disabled => false } + impressions << { :impression => impressions_manager.build_impression('matching_key2', 'foo2', 'foo2', treatment2, false, params2, {:properties => {:prop => "val"}}), :disabled => false } impressions_manager.track(impressions) end diff --git a/spec/engine_spec.rb b/spec/engine_spec.rb index 7909d64d..3501468c 100644 --- a/spec/engine_spec.rb +++ b/spec/engine_spec.rb @@ -77,6 +77,22 @@ treatment: 'off', config: nil ) + expect(subject.get_treatment_with_config('nicolas', 'mauro_test', {}, nil)).to eq( + treatment: 'off', + config: nil + ) + expect(subject.get_treatment_with_config('nicolas', 'mauro_test', {}, {})).to eq( + treatment: 'off', + config: nil + ) + expect(subject.get_treatment_with_config('nicolas', 'mauro_test', {}, "prop")).to eq( + treatment: 'off', + config: nil + ) + expect(subject.get_treatment_with_config('nicolas', 'mauro_test', {}, 123)).to eq( + treatment: 'off', + config: nil + ) close_redis end @@ -84,6 +100,10 @@ expect(subject.get_treatment('nicolas', 'mauro_test', nil)).to eq 'off' expect(subject.get_treatment('nicolas', 'mauro_test')).to eq 'off' expect(subject.get_treatment('nicolas', 'mauro_test', {})).to eq 'off' + expect(subject.get_treatment('nicolas', 'mauro_test', {}, nil)).to eq 'off' + expect(subject.get_treatment('nicolas', 'mauro_test', {}, {})).to eq 'off' + expect(subject.get_treatment('nicolas', 'mauro_test', {}, "prop")).to eq 'off' + expect(subject.get_treatment('nicolas', 'mauro_test', {}, 123)).to eq 'off' end it 'get_treatments returns off' do @@ -96,6 +116,18 @@ expect(subject.get_treatments('nicolas', ['mauro_test'], {})).to eq( mauro_test: 'off' ) + expect(subject.get_treatments('nicolas', ['mauro_test'], {}, nil)).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments('nicolas', ['mauro_test'], {}, {})).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments('nicolas', ['mauro_test'], {}, "prop")).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments('nicolas', ['mauro_test'], {}, 123)).to eq( + mauro_test: 'off' + ) close_redis end @@ -109,6 +141,18 @@ expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {})).to eq( mauro_test: 'off' ) + expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {}, {})).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {}, nil)).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {}, "prop")).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {}, 123)).to eq( + mauro_test: 'off' + ) close_redis end @@ -122,6 +166,18 @@ expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {})).to eq( mauro_test: 'off' ) + expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {}, {})).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {}, nil)).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {}, "prop")).to eq( + mauro_test: 'off' + ) + expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {}, 123)).to eq( + mauro_test: 'off' + ) close_redis end end @@ -141,8 +197,7 @@ end it 'returns CONTROL and label for incorrect feature name' do - treatment = subject.get_treatment('random_user_id', 'test_featur', nil, nil, false, true) - puts treatment + treatment = subject.get_treatment('random_user_id', 'test_featur', nil, nil, nil, false, true) expect(treatment).to eq( treatment: SplitIoClient::Engine::Models::Treatment::CONTROL, label: SplitIoClient::Engine::Models::Label::NOT_FOUND, @@ -229,7 +284,7 @@ #TODO We will remove multiple param in the future. it 'returns CONTROL and label on nil key' do - expect(subject.get_treatment(nil, 'test_feature', nil, nil, false, true)).to eq( + expect(subject.get_treatment(nil, 'test_feature', nil, nil, nil, false, true)).to eq( treatment: SplitIoClient::Engine::Models::Treatment::CONTROL, label: nil, change_number: nil @@ -289,7 +344,7 @@ #TODO We will remove multiple param in the future. it 'returns CONTROL and label on nil split_name' do - expect(subject.get_treatment('random_user_id', nil, nil, nil, false, true)).to eq( + expect(subject.get_treatment('random_user_id', nil, nil, nil, nil, false, true)).to eq( treatment: SplitIoClient::Engine::Models::Treatment::CONTROL, label: nil, change_number: nil