Skip to content

Commit

Permalink
Merge #63
Browse files Browse the repository at this point in the history
63: Add support for class descendants r=curquiza a=jitingcn



Co-authored-by: 寂听 <[email protected]>
Co-authored-by: Jiting <[email protected]>
  • Loading branch information
bors[bot] and jitingcn authored Aug 26, 2021
2 parents 75b4498 + 5b7b8c2 commit 3061596
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/meilisearch/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def get_model_classes
elsif Rails.application
Rails.application.eager_load!
end
MeiliSearch.instance_variable_get :@included_in
klasses = MeiliSearch.instance_variable_get(:@included_in)
(klasses + klasses.map{ |klass| klass.descendants }.flatten).uniq
end

def clear_all_indexes
Expand Down
8 changes: 7 additions & 1 deletion spec/utilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ def self.model_name

meilisearch
end

class DummyChild < Dummy
end

class DummyGrandChild < DummyChild
end
end

after(:each) do
MeiliSearch.instance_variable_set :@included_in, @included_in
end

it "should get the models where MeiliSearch module was included" do
(MeiliSearch::Utilities.get_model_classes - [Dummy]).should == []
(MeiliSearch::Utilities.get_model_classes - [Dummy, DummyChild, DummyGrandChild]).should == []
end

end

0 comments on commit 3061596

Please sign in to comment.