From 1011bdca260678545f33cb7419ed6c9ba1635c00 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Thu, 5 Nov 2026 12:49:57 -0500 Subject: [PATCH] fix: Make TestDataV2 value_for_all return its value when targeting is off FlagBuilderV2#value_for_all set a single variation but kept the off variation, which is 1 for a new flag. That index is out of range, so the flag failed to evaluate when targeting was off. The method now also sets the off variation to the single variation, so the flag returns the value whether targeting is on or off, as its documentation says. --- .../integrations/test_data_v2/flag_builder_v2.rb | 2 +- spec/integrations/test_data_v2_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb b/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb index 26919a54..a5c980f9 100644 --- a/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb +++ b/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb @@ -179,7 +179,7 @@ def variation_for_all(variation) # @return [FlagBuilderV2] the flag builder # def value_for_all(value) - variations(value).variation_for_all(0) + variations(value).variation_for_all(0).off_variation(0) end # diff --git a/spec/integrations/test_data_v2_spec.rb b/spec/integrations/test_data_v2_spec.rb index d157df40..54f74919 100644 --- a/spec/integrations/test_data_v2_spec.rb +++ b/spec/integrations/test_data_v2_spec.rb @@ -51,6 +51,17 @@ module Integrations expect(init_data[:segments][:mysegment][:included]).to eq(['user2']) end + it 'returns the value_for_all value whether targeting is on or off' do + td = TestDataV2.data_source + flag = td.flag('myflag').value_for_all('x').build(1) + expect(flag[:variations]).to eq(['x']) + expect(flag[:fallthrough]).to eq({ variation: 0 }) + expect(flag[:offVariation]).to eq(0) + + off_flag = td.flag('myflag').value_for_all('x').on(false).build(1) + expect(off_flag[:offVariation]).to eq(0) + end + describe 'TestDataSourceV2' do it 'includes both flags and segments in fetch' do td = TestDataV2.data_source