Sha256: 8c0438ab2f024f958b47e2791f2a5a8b8b9f74cf32de388d37b162b99dd34e15

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe RubyPgExtras::IndexInfo do
  subject(:result) do
    RubyPgExtras::IndexInfo.call
  end

  describe "call" do
    context "stubbed cases" do
      before do
        expect(RubyPgExtras).to receive(:indexes) {
          [
            { "schemaname" => "public", "indexname" => "index_users_on_api_auth_token", "tablename" => "users", "columns" => "api_auth_token, column2" },
            { "schemaname" => "public", "indexname" => "index_teams_on_slack_id", "tablename" => "teams", "columns" => "slack_id" },
          ]
        }

        expect(RubyPgExtras).to receive(:index_size) {
          [
            { "name" => "index_users_on_api_auth_token", "size" => "1744 kB" },
            { "name" => "index_teams_on_slack_id", "size" => "500 kB" },
          ]
        }

        expect(RubyPgExtras).to receive(:null_indexes) {
          [
            { "oid" => 16803, "index" => "index_users_on_api_auth_token", "index_size" => "1744 kB", "unique" => true, "indexed_column" => "api_auth_token", "null_frac" => "25.00%", "expected_saving" => "300 kB" },
          ]
        }

        expect(RubyPgExtras).to receive(:index_scans) {
          [
            { "schemaname" => "public", "table" => "users", "index" => "index_users_on_api_auth_token", "index_size" => "1744 kB", "index_scans" => 0 },
            { "schemaname" => "public", "table" => "teams", "index" => "index_teams_on_slack_id", "index_size" => "500 kB", "index_scans" => 0 },
          ]
        }
      end

      it "works" do
        expect {
          RubyPgExtras::IndexInfoPrint.call(result)
        }.not_to raise_error
      end
    end

    context "real data" do
      it "works" do
        expect {
          RubyPgExtras::IndexInfoPrint.call(result)
        }.not_to raise_error
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-pg-extras-5.4.5 spec/index_info_spec.rb
ruby-pg-extras-5.4.4 spec/index_info_spec.rb
ruby-pg-extras-5.4.3 spec/index_info_spec.rb
ruby-pg-extras-5.4.2 spec/index_info_spec.rb
ruby-pg-extras-5.4.1 spec/index_info_spec.rb
ruby-pg-extras-5.4.0 spec/index_info_spec.rb