Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix] can't search by name in API #index (#1275) #1276

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/api_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions app/views/comfy/admin/api_namespaces/_search_filters.haml
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions test/controllers/admin/comfy/api_namespaces_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down