diff --git a/.changeset/local-properties-align.md b/.changeset/local-properties-align.md new file mode 100644 index 0000000..0876bba --- /dev/null +++ b/.changeset/local-properties-align.md @@ -0,0 +1,6 @@ +--- +"posthog-ruby": patch +"posthog-rails": patch +--- + +Align local `is_set` and `is_not_set` evaluation with partial property context. diff --git a/lib/posthog/feature_flags.rb b/lib/posthog/feature_flags.rb index ef2a65e..7c6f12e 100644 --- a/lib/posthog/feature_flags.rb +++ b/lib/posthog/feature_flags.rb @@ -614,7 +614,6 @@ def self.semver_wildcard_bounds(value) def self.match_property(property, property_values, cohort_properties = {}) # only looks for matches where key exists in property_values - # doesn't support operator is_not_set PostHog::Utils.symbolize_keys! property PostHog::Utils.symbolize_keys! property_values @@ -629,7 +628,7 @@ def self.match_property(property, property_values, cohort_properties = {}) if !property_values.key?(key) raise InconclusiveMatchError, "Property #{key} not found in property_values" elsif operator == 'is_not_set' - raise InconclusiveMatchError, 'Operator is_not_set not supported' + return false end override_value = property_values[key] diff --git a/spec/posthog/feature_flag_spec.rb b/spec/posthog/feature_flag_spec.rb index ab7f9ec..5d965c9 100644 --- a/spec/posthog/feature_flag_spec.rb +++ b/spec/posthog/feature_flag_spec.rb @@ -1439,8 +1439,12 @@ module PostHog expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 'value' })).to be true expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 'value2' })).to be true - expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be true expect(FeatureFlagsPoller.match_property(property_a, { 'key' => nil })).to be true + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => false })).to be true + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 0 })).to be true + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be true + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => [] })).to be true + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => {} })).to be true expect do FeatureFlagsPoller.match_property(property_a, { 'key2' => 'value' }) @@ -1448,6 +1452,19 @@ module PostHog expect { FeatureFlagsPoller.match_property(property_a, {}) }.to raise_error(InconclusiveMatchError) end + it 'with operator is_not_set' do + property_a = { 'key' => 'key', 'value' => 'is_not_set', 'operator' => 'is_not_set' } + + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => nil })).to be false + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => false })).to be false + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 0 })).to be false + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be false + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => [] })).to be false + expect(FeatureFlagsPoller.match_property(property_a, { 'key' => {} })).to be false + + expect { FeatureFlagsPoller.match_property(property_a, {}) }.to raise_error(InconclusiveMatchError) + end + it 'with operator icontains' do property_a = { 'key' => 'key', 'value' => 'vaLuE', 'operator' => 'icontains' }