diff --git a/app/models/api_namespace.rb b/app/models/api_namespace.rb index 8d1bf3a29..6080c27cf 100755 --- a/app/models/api_namespace.rb +++ b/app/models/api_namespace.rb @@ -45,6 +45,10 @@ class ApiNamespace < ApplicationRecord has_many :error_api_actions, dependent: :destroy accepts_nested_attributes_for :error_api_actions, allow_destroy: true + ransacker :properties do |_parent| + Arel.sql("api_namespaces.properties::text") + end + REGISTERED_PLUGINS = { subdomain_events: { slug: 'subdomain_events', diff --git a/app/views/comfy/admin/api_namespaces/_search_filters.haml b/app/views/comfy/admin/api_namespaces/_search_filters.haml index 1212c5229..83734d112 100644 --- a/app/views/comfy/admin/api_namespaces/_search_filters.haml +++ b/app/views/comfy/admin/api_namespaces/_search_filters.haml @@ -1,7 +1,7 @@ = search_form_for objects, url: path do |f| .form-group - = f.label "Name", class: 'col-form-label' - = f.search_field :properties_cont, value: params[:q][:name_cont], class: 'form-control' + = f.label "Name or Properties", class: 'col-form-label' + = f.search_field :properties_or_name_cont, value: params[:q][:properties_or_name_cont], class: 'form-control', placeholder: 'Enter the value of name or properties you want to search' .text-center = f.submit class: 'btn btn-primary my-2' = link_to "Clear Search", request.path, class:"cancel-button" \ No newline at end of file diff --git a/test/controllers/admin/comfy/api_namespaces_controller_test.rb b/test/controllers/admin/comfy/api_namespaces_controller_test.rb index 37bc26cb3..3bab92fcf 100755 --- a/test/controllers/admin/comfy/api_namespaces_controller_test.rb +++ b/test/controllers/admin/comfy/api_namespaces_controller_test.rb @@ -684,6 +684,40 @@ class Comfy::Admin::ApiNamespacesControllerTest < ActionDispatch::IntegrationTes assert_select "a[href='#{edit_comfy_admin_cms_site_layout_path(site_id: layout.site.id, id: layout.id)}']", { count: 1 } end + test "#index: should show only the api-namespaces with provided properties" do + plugin_subdomain_events = api_namespaces(:plugin_subdomain_events) + namespace_with_all_types = api_namespaces(:namespace_with_all_types) + monitoring_target_incident = api_namespaces(:monitoring_target_incident) + + sign_in(@user) + get api_namespaces_url, params: {q: {properties_or_name_cont: 'latency'}} + assert_response :success + + @controller.view_assigns['api_namespaces'].each do |api_namespace| + assert_match 'latency', api_namespace.properties.to_s + end + + refute_includes @controller.view_assigns['api_namespaces'], plugin_subdomain_events + refute_includes @controller.view_assigns['api_namespaces'], namespace_with_all_types + end + + test "#index: should show only the api-namespaces with provided name" do + plugin_subdomain_events = api_namespaces(:plugin_subdomain_events) + namespace_with_all_types = api_namespaces(:namespace_with_all_types) + monitoring_target_incident = api_namespaces(:monitoring_target_incident) + + sign_in(@user) + get api_namespaces_url, params: {q: {properties_or_name_cont: 'subdomain_events'}} + assert_response :success + + @controller.view_assigns['api_namespaces'].each do |api_namespace| + assert_match 'subdomain_events', api_namespace.name + end + + refute_includes @controller.view_assigns['api_namespaces'], namespace_with_all_types + refute_includes @controller.view_assigns['api_namespaces'], monitoring_target_incident + end + test "#index: Rendering tab should include documentation on form snippet and API HTML renderer snippets" do sign_in(@user) @api_namespace.has_form = "1"