<commit_before>require 'spec_helper'

module FeatureFlagger
  RSpec.describe Manager do
    describe 'detached_feature_keys' do
      let(:redis) { FakeRedis::Redis.new }
      let(:storage) { Storage::Redis.new(redis) }

      before do
        FeatureFlagger.configure do |config|
          config.storage = storage
        end
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_1', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_2', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_3', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_b', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_d', 0)

        filepath = File.expand_path('../../fixtures/rollout_example.yml', __FILE__)
        FeatureFlagger.config.yaml_filepath = filepath
      end

      it 'returns all detached feature keys' do
        expect(described_class.detached_feature_keys).to match_array([
          'other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_3',
          'other_feature_flagger_dummy_class:feature_d'
        ])
      end
    end

    describe 'cleanup_detached' do
      context "detached feature key" do
        let(:redis) { FakeRedis::Redis.new }
        let(:storage) { Storage::Redis.new(redis) }
        let(:feature_key) { 'other_feature_flagger_dummy_class:feature_d' }

        before do
          FeatureFlagger.configure do |config|<commit_msg>Introduce failing scenario<commit_after>require 'spec_helper'

module FeatureFlagger
  RSpec.describe Manager do
    describe 'detached_feature_keys' do
      let(:redis) { FakeRedis::Redis.new }
      let(:storage) { Storage::Redis.new(redis) }

      before do
        FeatureFlagger.configure do |config|
          config.storage = storage
        end

        filepath = File.expand_path('../../fixtures/rollout_example.yml', __FILE__)
        FeatureFlagger.config.yaml_filepath = filepath

        # All good here
        FeatureFlagger.control.release_to_all('feature_flagger_dummy_class:email_marketing:behavior_score')
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_1', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_2', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_b', 0)

        # Detached keys
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_3', 0)
        FeatureFlagger.control.release('other_feature_flagger_dummy_class:feature_d', 0)
      end

      it 'returns all detached feature keys' do
        expect(described_class.detached_feature_keys).to match_array([
          'other_feature_flagger_dummy_class:feature_a:feature_a_1:feature_a_1_3',
          'other_feature_flagger_dummy_class:feature_d'
        ])
      end
    end

    describe 'cleanup_detached' do
      context "detached feature key" do
        let(:redis) { FakeRedis::Redis.new }
        let(:storage) { Storage::Redis.new(redis) }
        let(:feature_key) { 'other_feature_flagger_dummy_class:feature_d' }

        before do
          FeatureFlagger.configure do |config|
{'fraction_non_alphanumeric': 0.08928046989720999, 'fraction_numerical': 0.00998531571218796, 'mean_word_length': 3.790436005625879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6871033', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1063, 'n_words': 147}