Commit 9ccbc6f6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

New JsDuck::Class#invalidate_search_cache! method.

To go along with #find_members.
parent 9c204761
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -344,6 +344,19 @@ module JsDuck
      ms
    end

    # Clears the search cache.
    # This is used by InheritDoc after transforming configs into properties.
    # This is also REALLY BAD - try to get rid of it.
    def invalidate_search_cache!
      @map_by_id = nil
      @global_map_by_id = nil
      @global_map_by_name = nil

      parent.invalidate_search_cache! if parent

      mixins.each {|mix| mix.invalidate_search_cache! }
    end


    # Returns all members of class, including the inherited and mixed in ones
    def all_members
+77 −0
Original line number Diff line number Diff line
@@ -164,6 +164,83 @@ describe JsDuck::Class do
    end
  end

  describe "when #find_members called before" do
    let (:parent) do
      make_class({
        :name => "ParentClass",
        :members => [
          {:name => "oldName"},
        ]
      });
    end

    let (:child) do
      make_class({
        :name => "ChildClass",
        :extends => "ParentClass",
        :members => [
          {:name => "oldName"},
        ]
      });
    end

    before do
      classes = {}

      classes["ParentClass"] = parent
      parent.relations = classes

      classes["ChildClass"] = child
      child.relations = classes

      child.find_members(:name => "oldName")

      child
    end

    describe "then after changing child member name" do
      before do
        child[:members][0][:name] = "changedName"
        child[:members][0][:id] = "property-changedName"
      end

      it "the new member can't be found" do
        child.find_members(:name => "changedName").length.should == 0
      end

      describe "and after calling #invalidate_search_cache!" do
        before do
          child.invalidate_search_cache!
        end

        it "the new member is now findable" do
          child.find_members(:name => "changedName").length.should == 1
        end
      end
    end

    describe "then after changing parent member tagname" do
      before do
        parent[:members][0][:tagname] = :method
        parent[:members][0][:id] = "method-oldName"
      end

      it "the new member can't be found" do
        child.find_members(:tagname => :method).length.should == 0
      end

      describe "and after calling #invalidate_search_cache!" do
        before do
          child.invalidate_search_cache!
        end

        it "the new member is now findable" do
          child.find_members(:tagname => :method).length.should == 1
        end
      end
    end
  end

  describe "#members" do

    before do