Skip to content

Commit 6b2d009

Browse files
committed
create a failing test
1 parent 0680a4a commit 6b2d009

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

spec/features/ajax_params_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,52 @@
5050
expect(response.body).to have_selector('.searchable-select-input' \
5151
"[data-ajax-url*='#{url_matcher}']")
5252
end
53+
54+
context 'when using belongs_to' do
55+
before(:each) do
56+
ActiveAdminHelpers.setup do
57+
58+
ActiveAdmin.register(OptionType)
59+
60+
ActiveAdmin.register(Product) do
61+
62+
ActiveAdmin.register(OptionValue) do
63+
belongs_to :option_type
64+
searchable_select_options(scope: lambda do |params|
65+
OptionValue.where(
66+
option_type_id: params[:option_type_id]
67+
)
68+
end,
69+
text_attribute: :value)
70+
end
71+
72+
ActiveAdmin.register(Variant) do
73+
belongs_to :product
74+
75+
form do |f|
76+
f.input(:option_value,
77+
as: :searchable_select,
78+
ajax: {
79+
resource: OptionValue,
80+
path_params: {
81+
option_type_id: f.object.product.option_type_id
82+
}
83+
})
84+
end
85+
end
86+
end
87+
end
88+
89+
it 'pre-select items in the associations' do
90+
option_type = OptionType.create
91+
product = Product.create(option_type: option_type)
92+
option_value = OptionValue.create(option_type: option_type, value: 'Red')
93+
variant = Variant.create(product: product, option_value: option_value)
94+
95+
get "/admin/products/#{product.id}/variants/#{variant.id}/edit"
96+
97+
expect(response.body).to have_selector('.searchable-select-input option[selected]',
98+
count: 1)
99+
end
100+
end
53101
end

0 commit comments

Comments
 (0)