Skip to content
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
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AllCops:
TargetRubyVersion: 2.3
Exclude:
- 'bin/**/*'

# The default of 80 characters is a little to narrow.
Metrics/LineLength:
Expand Down
8 changes: 5 additions & 3 deletions lib/activeadmin/searchable_select/select_input_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def collection_from_options

def ajax_url
return unless options[:ajax]
template.polymorphic_path([template.active_admin_namespace.route_prefix, ajax_resource_class],
action: option_collection.collection_action_name,
**ajax_params)
[ajax_resource.route_collection_path,
'/',
option_collection.collection_action_name,
'?',
ajax_params.to_query].join
end

def all_options_collection
Expand Down
106 changes: 69 additions & 37 deletions spec/features/end_to_end_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,92 @@
require 'support/active_admin_helpers'

RSpec.describe 'end to end', type: :feature, js: true do
before(:each) do
ActiveAdminHelpers.setup do
ActiveAdmin.register(Category) do
searchable_select_options(scope: Category, text_attribute: :name)
end
context 'class name without namespaces' do
before(:each) do
ActiveAdminHelpers.setup do
ActiveAdmin.register(Category) do
searchable_select_options(scope: Category, text_attribute: :name)
end

ActiveAdmin.register(Post) do
filter(:category, as: :searchable_select, ajax: true)
ActiveAdmin.register(Post) do
filter(:category, as: :searchable_select, ajax: true)

form do |f|
f.input(:category, as: :searchable_select, ajax: true)
form do |f|
f.input(:category, as: :searchable_select, ajax: true)
end
end
end

ActiveAdmin.setup {}
ActiveAdmin.setup {}
end
end
end

describe 'index page with searchable select filter' do
it 'loads filter input options' do
Category.create(name: 'Music')
Category.create(name: 'Travel')
describe 'index page with searchable select filter' do
it 'loads filter input options' do
Category.create(name: 'Music')
Category.create(name: 'Travel')

visit '/admin/posts'
visit '/admin/posts'

expand_select_box
wait_for_ajax
expand_select_box
wait_for_ajax

expect(select_box_items).to eq(%w(Music Travel))
end
expect(select_box_items).to eq(%w(Music Travel))
end

it 'allows filtering options by term' do
Category.create(name: 'Music')
Category.create(name: 'Travel')

visit '/admin/posts'

expand_select_box
enter_search_term('T')
wait_for_ajax

expect(select_box_items).to eq(%w(Travel))
end

it 'loads more items when scrolling down' do
15.times { |i| Category.create(name: "Category #{i}") }
visit '/admin/posts'

it 'allows filtering options by term' do
Category.create(name: 'Music')
Category.create(name: 'Travel')
expand_select_box
wait_for_ajax
scroll_select_box_list
wait_for_ajax

visit '/admin/posts'
expect(select_box_items.size).to eq(15)
end
end
end

expand_select_box
enter_search_term('T')
wait_for_ajax
context 'class name with namespace' do
before(:each) do
ActiveAdminHelpers.setup do
ActiveAdmin.register RGB::Color, as: 'color' do
searchable_select_options scope: RGB::Color, text_attribute: :code
end

expect(select_box_items).to eq(%w(Travel))
ActiveAdmin.register Internal::TagName, as: 'Tag Name' do
filter :color, as: :searchable_select, ajax: { resource: RGB::Color }
end

ActiveAdmin.setup {}
end
end

it 'loads more items when scrolling down' do
15.times { |i| Category.create(name: "Category #{i}") }
visit '/admin/posts'
describe 'index page with searchable select filter' do
it 'loads filter input options' do
RGB::Color.create(code: '#eac112', description: 'Orange')
RGB::Color.create(code: '#19bf25', description: 'Green')

expand_select_box
wait_for_ajax
scroll_select_box_list
wait_for_ajax
visit '/admin/tag_names'

expect(select_box_items.size).to eq(15)
expand_select_box
wait_for_ajax

expect(select_box_items).to eq(%w(#eac112 #19bf25))
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
t.boolean :published
end

create_table(:rgb_colors, force: true) do |t|
t.string :code
t.text :description
end

create_table(:internal_tag_names, force: true) do |t|
t.string :name
t.text :description
t.integer :color_id
end

create_table(:users, force: true) do |t|
t.string :name
end
Expand Down
14 changes: 14 additions & 0 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ class Post < ActiveRecord::Base
scope(:published, -> { where(published: true) })
end

module RGB
class Color < ActiveRecord::Base
self.table_name = :rgb_colors
has_many :tags, class_name: 'Internal::TagName'
end
end

module Internal
class TagName < ActiveRecord::Base
self.table_name = :internal_tag_names
belongs_to :color, class_name: 'RGB::Color', foreign_key: :color_id
end
end

RSpec.configure do |config|
config.after do
DatabaseCleaner.strategy = :truncation
Expand Down