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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def selected_values
end

def option_collection_scope
option_collection.scope(template, ajax_params)
option_collection.scope(template, path_params.merge(ajax_params))
end

def option_collection
Expand Down
48 changes: 48 additions & 0 deletions spec/features/ajax_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,52 @@
expect(response.body).to have_selector('.searchable-select-input' \
"[data-ajax-url*='#{url_matcher}']")
end

context 'when using belongs_to' do
before(:each) do
ActiveAdminHelpers.setup do

ActiveAdmin.register(OptionType)

ActiveAdmin.register(Product) do

ActiveAdmin.register(OptionValue) do
belongs_to :option_type
searchable_select_options(scope: lambda do |params|
OptionValue.where(
option_type_id: params[:option_type_id]
)
end,
text_attribute: :value)
end

ActiveAdmin.register(Variant) do
belongs_to :product

form do |f|
f.input(:option_value,
as: :searchable_select,
ajax: {
resource: OptionValue,
path_params: {
option_type_id: f.object.product.option_type_id
}
})
end
end
end
end

it 'pre-select items in the associations' do
option_type = OptionType.create
product = Product.create(option_type: option_type)
option_value = OptionValue.create(option_type: option_type, value: 'Red')
variant = Variant.create(product: product, option_value: option_value)

get "/admin/products/#{product.id}/variants/#{variant.id}/edit"

expect(response.body).to have_selector('.searchable-select-input option[selected]',
count: 1)
end
end
end