require 'rails_helper'

describe InstallationController, type: :request do

  describe "consul.json" do
    let(:test_feature_settings) do
      {
        'disabled_feature' => nil,
        'enabled_feature' => 't'
      }
    end

    let(:seeds_feature_settings) { Setting.where("key LIKE 'feature.%'") }

    before do
      @current_feature_settings = seeds_feature_settings.pluck(:key, :value).to_h
      seeds_feature_settings.destroy_all
      test_feature_settings.each { |feature_name, feature_value| Setting["feature.#{feature_name}"] = feature_value }
    end

    after do
      test_feature_settings.keys.each { |feature_name| Setting.find_by(key: "feature.#{feature_name}").destroy }
      @current_feature_settings.each { |feature_name, feature_value| Setting[feature_name] = feature_value }
    end

    specify "with query string inside query params" do
      get '/consul.json'

      expect(response).to have_http_status(:ok)
      expect(JSON.parse(response.body)['release']).not_to be_empty
      expect(JSON.parse(response.body)['features']).to eq(test_feature_settings)
    end
  end
end

require 'rails_helper'

describe InstallationController, type: :request do

  describe "consul.json" do
    let(:test_feature_settings) do
      {
        'disabled_feature' => nil,
        'enabled_feature' => 't'
      }
    end

    let(:seeds_feature_settings) { Setting.where("key LIKE 'feature.%'") }

    before do
      @current_feature_settings = seeds_feature_settings.pluck(:key, :value).to_h
      seeds_feature_settings.destroy_all
      test_feature_settings.each do |feature_name, feature_value|
        Setting["feature.#{feature_name}"] = feature_value
      end
    end

    after do
      test_feature_settings.each_key do |feature_name|
        Setting.find_by(key: "feature.#{feature_name}").destroy
      end
      @current_feature_settings.each do |feature_name, feature_value|
        Setting[feature_name] = feature_value
      end
    end

    specify "with query string inside query params" do
      get '/consul.json'

      expect(response).to have_http_status(:ok)
      expect(JSON.parse(response.body)['release']).not_to be_empty
      expect(JSON.parse(response.body)['features']).to eq(test_feature_settings)
    end
  end
end

Improve performance swapping keys.each for each_key, plus line lenght comply
Improve performance swapping keys.each for each_key, plus line lenght comply
