Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/splitclient-rb/clients/split_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]_validator.valid_get_treatments_parameters(calling_method, key, sanitized_feature_flag_names, matching_key, bucketing_key, attributes)
to_return = Hash.new
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/cache/senders/impressions_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion spec/cache/senders/impressions_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
63 changes: 59 additions & 4 deletions spec/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,33 @@
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

it 'get_treatment returns off' do
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
Expand All @@ -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

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

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down