Skip to content

Commit

Permalink
Add MiqAeMethod scopes for name, domain, and method search
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jul 25, 2024
1 parent 82217ec commit 3356960
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/miq_ae_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class MiqAeMethod < ApplicationRecord
AVAILABLE_SCOPES = ["class", "instance"]
validates_inclusion_of :scope, :in => AVAILABLE_SCOPES

# finds by name or namespace. not domain
# @param [nil,String] search
scope :name_path_search, lambda { |search|
search.present? ? where(arel_table[:relative_path].matches("%#{search}%")) : where({})
}

def self.available_languages
AVAILABLE_LANGUAGES
end
Expand Down
17 changes: 17 additions & 0 deletions spec/models/miq_ae_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,21 @@
expect(keys.exclude?('options')).to be_truthy
expect(keys.exclude?('embedded_methods')).to be_truthy
end

describe ".domain_search" do
it "matches by id" do
m1 = FactoryBot.create(:miq_ae_method, "name" => "match", :class_id => sub_class.id)
FactoryBot.create(:miq_ae_method, "name" => "nope", :class_id => sys_class.id)

expect(MiqAeMethod.domain_search(domain.id)).to eq([m1])
expect(MiqAeMethod.domain_search([domain.id])).to eq([m1])
end

it "searches all when blank" do
m1 = FactoryBot.create(:miq_ae_method, "name" => "match", :class_id => sub_class.id)
m2 = FactoryBot.create(:miq_ae_method, "name" => "nope", :class_id => sys_class.id)

expect(MiqAeMethod.domain_search(nil)).to match_array([m1, m2])
end
end
end

0 comments on commit 3356960

Please sign in to comment.