activeadmin-tom_select 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.actrc +20 -0
- data/.claude/commands/fix-tests.md +203 -0
- data/.github/workflows/ci.yml +174 -0
- data/.github/workflows/npm-publish.yml +50 -0
- data/.gitignore +35 -0
- data/.npmignore +58 -0
- data/.rspec +1 -0
- data/.rubocop.yml +75 -0
- data/.yardopts +2 -0
- data/AGENTS.md +39 -0
- data/Appraisals +9 -0
- data/CHANGELOG.md +64 -0
- data/CLAUDE.md +157 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +368 -0
- data/LICENSE.txt +25 -0
- data/README.md +483 -0
- data/Rakefile +4 -0
- data/activeadmin-tom_select.gemspec +43 -0
- data/bin/rspec +17 -0
- data/config/database.yml +16 -0
- data/docs/activeadmin-4-detailed-reference.md +932 -0
- data/docs/activeadmin-4-gem-migration-guide.md +313 -0
- data/docs/combustion.md +213 -0
- data/docs/fail.png +0 -0
- data/docs/guide-update-your-app.md +283 -0
- data/docs/normal.png +0 -0
- data/docs/propshaft-readme.md +320 -0
- data/docs/propshaft-upgrade.md +484 -0
- data/docs/setup-activeadmin-app.md +552 -0
- data/docs/setup-activeadmin-gem.md +535 -0
- data/docs/tailwind/blog-page.md +341 -0
- data/docs/tailwind/upgrade-guide-enhanced.md +438 -0
- data/docs/tailwind/upgrade-guide.md +416 -0
- data/docs/tailwind-4/active_admin.rake +38 -0
- data/docs/tailwind-4/active_admin.tailwind.css +415 -0
- data/docs/tailwind-4/tailwind-active_admin.config.js +18 -0
- data/docs/test-app-change.md +154 -0
- data/docs/test-environment-fixes.md +58 -0
- data/docs/update-tom-select.md +184 -0
- data/docs/upload-system.md +225 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile +10 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +377 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile +10 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +372 -0
- data/lefthook.yml +17 -0
- data/lib/activeadmin/inputs/filters/searchable_select_input.rb +19 -0
- data/lib/activeadmin/inputs/searchable_select_input.rb +16 -0
- data/lib/activeadmin/tom_select/engine.rb +17 -0
- data/lib/activeadmin/tom_select/option_collection.rb +128 -0
- data/lib/activeadmin/tom_select/resource_dsl_extension.rb +56 -0
- data/lib/activeadmin/tom_select/resource_extension.rb +10 -0
- data/lib/activeadmin/tom_select/select_input_extension.rb +168 -0
- data/lib/activeadmin/tom_select/version.rb +5 -0
- data/lib/activeadmin/tom_select.rb +20 -0
- data/lib/activeadmin-tom_select.rb +5 -0
- data/lib/generators/active_admin/tom_select/install/install_generator.rb +180 -0
- data/npm-package/package-lock.json +51 -0
- data/npm-package/package.json +43 -0
- data/npm-package/src/index.js +153 -0
- data/npm-package/src/tom-select-tailwind.css +392 -0
- data/sonar-project.properties +25 -0
- data/spec/features/ajax_params_spec.rb +31 -0
- data/spec/features/asset_pipeline_diagnostic_spec.rb +155 -0
- data/spec/features/end_to_end_spec.rb +273 -0
- data/spec/features/filter_input_spec.rb +144 -0
- data/spec/features/form_input_spec.rb +122 -0
- data/spec/features/inline_ajax_setting_spec.rb +26 -0
- data/spec/features/input_errors_spec.rb +76 -0
- data/spec/features/input_html_options_spec.rb +30 -0
- data/spec/features/options_dsl_spec.rb +230 -0
- data/spec/features/production_build_spec.rb +108 -0
- data/spec/internal/.node-version +1 -0
- data/spec/internal/Gemfile +43 -0
- data/spec/internal/Gemfile.lock +333 -0
- data/spec/internal/Procfile.dev +3 -0
- data/spec/internal/README.md +24 -0
- data/spec/internal/Rakefile +6 -0
- data/spec/internal/app/admin/categories.rb +26 -0
- data/spec/internal/app/admin/dashboard.rb +29 -0
- data/spec/internal/app/admin/option_types.rb +19 -0
- data/spec/internal/app/admin/option_values.rb +30 -0
- data/spec/internal/app/admin/posts.rb +27 -0
- data/spec/internal/app/admin/products.rb +22 -0
- data/spec/internal/app/admin/rgb_colors.rb +25 -0
- data/spec/internal/app/admin/tag_names.rb +21 -0
- data/spec/internal/app/admin/test_ajax_params_category.rb +10 -0
- data/spec/internal/app/admin/test_ajax_params_post.rb +20 -0
- data/spec/internal/app/admin/test_form_post_class.rb +7 -0
- data/spec/internal/app/admin/test_form_post_custom.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource_custom.rb +12 -0
- data/spec/internal/app/admin/test_inline_ajax_post.rb +9 -0
- data/spec/internal/app/admin/test_input_html_post.rb +11 -0
- data/spec/internal/app/admin/test_posts_display_text.rb +9 -0
- data/spec/internal/app/admin/test_posts_filter.rb +9 -0
- data/spec/internal/app/admin/test_posts_named.rb +9 -0
- data/spec/internal/app/admin/test_posts_pagination.rb +9 -0
- data/spec/internal/app/admin/test_posts_payload_lambda.rb +11 -0
- data/spec/internal/app/admin/test_posts_payload_proc.rb +9 -0
- data/spec/internal/app/admin/test_posts_scope_lambda.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_params.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_user.rb +8 -0
- data/spec/internal/app/admin/test_posts_text_attr.rb +5 -0
- data/spec/internal/app/admin/users.rb +23 -0
- data/spec/internal/app/admin/variants.rb +31 -0
- data/spec/internal/app/assets/config/manifest.js +2 -0
- data/spec/internal/app/assets/images/.keep +0 -0
- data/spec/internal/app/assets/stylesheets/active_admin.tailwind.css +16 -0
- data/spec/internal/app/assets/stylesheets/application.tailwind.css +15 -0
- data/spec/internal/app/controllers/application_controller.rb +9 -0
- data/spec/internal/app/controllers/concerns/.keep +0 -0
- data/spec/internal/app/helpers/application_helper.rb +2 -0
- data/spec/internal/app/javascript/active_admin.js +19 -0
- data/spec/internal/app/javascript/application.js +2 -0
- data/spec/internal/app/jobs/application_job.rb +7 -0
- data/spec/internal/app/mailers/application_mailer.rb +4 -0
- data/spec/internal/app/models/admin_user.rb +9 -0
- data/spec/internal/app/models/application_record.rb +3 -0
- data/spec/internal/app/models/article.rb +12 -0
- data/spec/internal/app/models/category.rb +12 -0
- data/spec/internal/app/models/color.rb +9 -0
- data/spec/internal/app/models/concerns/.keep +0 -0
- data/spec/internal/app/models/internal/tag_name.rb +14 -0
- data/spec/internal/app/models/internal_tag_name.rb +11 -0
- data/spec/internal/app/models/option_type.rb +12 -0
- data/spec/internal/app/models/option_value.rb +4 -0
- data/spec/internal/app/models/post.rb +15 -0
- data/spec/internal/app/models/product.rb +12 -0
- data/spec/internal/app/models/rgb_color.rb +16 -0
- data/spec/internal/app/models/tag.rb +12 -0
- data/spec/internal/app/models/tagging.rb +12 -0
- data/spec/internal/app/models/user.rb +12 -0
- data/spec/internal/app/models/variant.rb +12 -0
- data/spec/internal/app/views/layouts/application.html.erb +28 -0
- data/spec/internal/app/views/layouts/mailer.html.erb +13 -0
- data/spec/internal/app/views/layouts/mailer.text.erb +1 -0
- data/spec/internal/app/views/pwa/manifest.json.erb +22 -0
- data/spec/internal/app/views/pwa/service-worker.js +26 -0
- data/spec/internal/bin/bundle +117 -0
- data/spec/internal/bin/dev +11 -0
- data/spec/internal/bin/rackup +27 -0
- data/spec/internal/bin/rails +4 -0
- data/spec/internal/bin/rake +4 -0
- data/spec/internal/bin/setup +37 -0
- data/spec/internal/config/application.rb +50 -0
- data/spec/internal/config/boot.rb +3 -0
- data/spec/internal/config/credentials.yml.enc +1 -0
- data/spec/internal/config/database.yml +32 -0
- data/spec/internal/config/environment.rb +5 -0
- data/spec/internal/config/environments/development.rb +63 -0
- data/spec/internal/config/environments/production.rb +86 -0
- data/spec/internal/config/environments/test.rb +50 -0
- data/spec/internal/config/initializers/active_admin.rb +54 -0
- data/spec/internal/config/initializers/assets.rb +8 -0
- data/spec/internal/config/initializers/content_security_policy.rb +25 -0
- data/spec/internal/config/initializers/devise.rb +315 -0
- data/spec/internal/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/internal/config/initializers/inflections.rb +16 -0
- data/spec/internal/config/initializers/searchable_select.rb +6 -0
- data/spec/internal/config/locales/devise.en.yml +65 -0
- data/spec/internal/config/locales/en.yml +31 -0
- data/spec/internal/config/master.key +1 -0
- data/spec/internal/config/puma.rb +38 -0
- data/spec/internal/config/routes.rb +17 -0
- data/spec/internal/config.ru +6 -0
- data/spec/internal/db/schema.rb +174 -0
- data/spec/internal/db/seeds.rb +167 -0
- data/spec/internal/esbuild.config.js +34 -0
- data/spec/internal/lib/tasks/.keep +0 -0
- data/spec/internal/lib/tasks/active_admin.rake +55 -0
- data/spec/internal/log/.keep +0 -0
- data/spec/internal/package-lock.json +1954 -0
- data/spec/internal/package.json +21 -0
- data/spec/internal/public/400.html +114 -0
- data/spec/internal/public/404.html +114 -0
- data/spec/internal/public/406-unsupported-browser.html +114 -0
- data/spec/internal/public/422.html +114 -0
- data/spec/internal/public/500.html +114 -0
- data/spec/internal/public/icon.png +0 -0
- data/spec/internal/public/icon.svg +3 -0
- data/spec/internal/public/robots.txt +1 -0
- data/spec/internal/script/.keep +0 -0
- data/spec/internal/storage/.keep +0 -0
- data/spec/internal/tailwind.config.js +23 -0
- data/spec/internal/vendor/.keep +0 -0
- data/spec/internal/yarn.lock +824 -0
- data/spec/rails_helper.rb +62 -0
- data/spec/spec_helper.rb +138 -0
- data/spec/support/active_admin_helpers.rb +17 -0
- data/spec/support/capybara.rb +8 -0
- data/spec/support/models.rb +11 -0
- data/spec/support/pluck_polyfill.rb +12 -0
- data/spec/support/reset_settings.rb +5 -0
- metadata +497 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
require 'support/models'
|
4
|
+
require 'support/pluck_polyfill'
|
5
|
+
|
6
|
+
RSpec.describe 'searchable_select_options dsl', type: :request do
|
7
|
+
describe 'with text_attribute option' do
|
8
|
+
# Using static TestPostTextAttr admin
|
9
|
+
describe 'creates JSON endpoint that' do
|
10
|
+
it 'returns options for searchable select' do
|
11
|
+
Post.create!(title: 'A post')
|
12
|
+
|
13
|
+
get '/admin/test_post_text_attrs/all_options'
|
14
|
+
|
15
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A post',
|
16
|
+
id: kind_of(Numeric))],
|
17
|
+
pagination: { more: false, current: 1 })
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports filtering via term parameter' do
|
21
|
+
Post.create!(title: 'A post')
|
22
|
+
Post.create!(title: 'Other post')
|
23
|
+
Post.create!(title: 'Not matched')
|
24
|
+
|
25
|
+
get '/admin/test_post_text_attrs/all_options?term=post'
|
26
|
+
titles = json_response[:results].pluck(:text)
|
27
|
+
|
28
|
+
expect(titles).to eq(['A post', 'Other post'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'with separate filter option' do
|
34
|
+
# Using static TestPostFilter admin
|
35
|
+
describe 'creates JSON endpoint that' do
|
36
|
+
it 'returns options for searchable select' do
|
37
|
+
Post.create!(title: 'A post')
|
38
|
+
|
39
|
+
get '/admin/test_post_filters/all_options'
|
40
|
+
|
41
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A post',
|
42
|
+
id: kind_of(Numeric))],
|
43
|
+
pagination: { more: false, current: 1 })
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'supports filtering via term parameter' do
|
47
|
+
Post.create!(title: 'Post')
|
48
|
+
Post.create!(title: 'Not matched')
|
49
|
+
|
50
|
+
get '/admin/test_post_filters/all_options?term=Post'
|
51
|
+
titles = json_response[:results].pluck(:text)
|
52
|
+
|
53
|
+
expect(titles).to eq(['Post'])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'with separate display_text option' do
|
59
|
+
# Using static TestPostDisplayText admin
|
60
|
+
describe 'creates JSON endpoint that' do
|
61
|
+
it 'returns options for searchable select' do
|
62
|
+
Post.create!(title: 'A post')
|
63
|
+
|
64
|
+
get '/admin/test_post_display_texts/all_options'
|
65
|
+
|
66
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A POST',
|
67
|
+
id: kind_of(Numeric))],
|
68
|
+
pagination: { more: false, current: 1 })
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'supports filtering via term parameter' do
|
72
|
+
Post.create!(title: 'A post')
|
73
|
+
Post.create!(title: 'Not matched')
|
74
|
+
|
75
|
+
get '/admin/test_post_display_texts/all_options?term=post'
|
76
|
+
titles = json_response[:results].pluck(:text)
|
77
|
+
|
78
|
+
expect(titles).to eq(['A POST'])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'pagination' do
|
84
|
+
# Using static TestPostPagination admin
|
85
|
+
it 'limits results and indicates that more results are available' do
|
86
|
+
Post.create!(title: 'A post')
|
87
|
+
Post.create!(title: 'Other post')
|
88
|
+
Post.create!(title: 'Yet another post')
|
89
|
+
|
90
|
+
get '/admin/test_post_paginations/all_options'
|
91
|
+
|
92
|
+
expect(json_response[:results].size).to eq(2)
|
93
|
+
expect(json_response[:pagination][:more]).to eq(true)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'allows passing page param' do
|
97
|
+
Post.create!(title: 'A post')
|
98
|
+
Post.create!(title: 'Other post')
|
99
|
+
Post.create!(title: 'Yet another post')
|
100
|
+
|
101
|
+
# Page 1 is now the first page (1-based pagination)
|
102
|
+
# With per_page: 2, should return first 2 posts
|
103
|
+
get '/admin/test_post_paginations/all_options?page=1'
|
104
|
+
|
105
|
+
expect(json_response[:results].size).to eq(2)
|
106
|
+
expect(json_response[:pagination][:more]).to eq(true)
|
107
|
+
expect(json_response[:pagination][:current]).to eq(1)
|
108
|
+
|
109
|
+
# Page 2 should have the last post
|
110
|
+
get '/admin/test_post_paginations/all_options?page=2'
|
111
|
+
|
112
|
+
expect(json_response[:results].size).to eq(1)
|
113
|
+
expect(json_response[:pagination][:more]).to eq(false)
|
114
|
+
expect(json_response[:pagination][:current]).to eq(2)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'with additional_payload' do
|
119
|
+
context 'as lambda' do
|
120
|
+
# Using static TestPostPayloadLambda admin
|
121
|
+
let!(:post) { Post.create!(title: 'A post', published: false) }
|
122
|
+
|
123
|
+
subject { get '/admin/test_post_payload_lambdas/all_options' }
|
124
|
+
|
125
|
+
it 'returns options with our additional attribute' do
|
126
|
+
subject
|
127
|
+
expect(json_response).to match(
|
128
|
+
results: [{ text: 'A post', id: post.id, published: false }],
|
129
|
+
pagination: { more: false, current: 1 }
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'as Proc' do
|
135
|
+
# Using static TestPostPayloadProc admin
|
136
|
+
let!(:post) { Post.create!(title: 'A post', published: false) }
|
137
|
+
|
138
|
+
subject { get '/admin/test_post_payload_procs/all_options' }
|
139
|
+
|
140
|
+
it 'returns options with our additional attribute' do
|
141
|
+
subject
|
142
|
+
expect(json_response).to match(
|
143
|
+
results: [{ text: 'A post', id: post.id, published: false }],
|
144
|
+
pagination: { more: false, current: 1 }
|
145
|
+
)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'allows passing lambda as scope' do
|
151
|
+
# Using static TestPostScopeLambda admin
|
152
|
+
Post.create!(title: 'Draft')
|
153
|
+
Post.create!(title: 'Published post', published: true)
|
154
|
+
|
155
|
+
get '/admin/test_post_scope_lambdas/all_options'
|
156
|
+
titles = json_response[:results].pluck(:text)
|
157
|
+
|
158
|
+
expect(titles).to eq(['Published post'])
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'allows passing lambda as scope that uses view helpers' do
|
162
|
+
# Using static TestPostScopeUser admin
|
163
|
+
user = User.create!
|
164
|
+
Post.create!(title: 'By current user', user: user)
|
165
|
+
Post.create!(title: 'By other user', user: User.create!)
|
166
|
+
|
167
|
+
ApplicationController.current_user = user
|
168
|
+
get '/admin/test_post_scope_users/all_options'
|
169
|
+
titles = json_response[:results].pluck(:text)
|
170
|
+
|
171
|
+
expect(titles).to eq(['By current user'])
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'allows passing lambda that takes params argument' do
|
175
|
+
# Using static TestPostScopeParams admin
|
176
|
+
user = User.create!
|
177
|
+
Post.create!(title: 'By given user', user: user)
|
178
|
+
Post.create!(title: 'By other user', user: User.create!)
|
179
|
+
|
180
|
+
get "/admin/test_post_scope_params/all_options?user=#{user.id}"
|
181
|
+
titles = json_response[:results].pluck(:text)
|
182
|
+
|
183
|
+
expect(titles).to eq(['By given user'])
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'allows passing name prefix for collection action' do
|
187
|
+
# Using static TestPostNamed admin
|
188
|
+
Post.create!(title: 'A post')
|
189
|
+
|
190
|
+
get '/admin/test_post_nameds/some_options'
|
191
|
+
|
192
|
+
expect(json_response).to include(results: array_including(a_hash_including(text: 'A post')))
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'fails with helpful message if scope option is missing' do
|
196
|
+
expect do
|
197
|
+
ActiveAdminHelpers.setup do
|
198
|
+
ActiveAdmin.register(Post) do
|
199
|
+
searchable_select_options(text_attribute: :title)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end.to raise_error(/Missing option: scope/)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'fails with helpful message if display_text are missing' do
|
206
|
+
expect do
|
207
|
+
ActiveAdminHelpers.setup do
|
208
|
+
ActiveAdmin.register(Post) do
|
209
|
+
searchable_select_options(scope: Post,
|
210
|
+
filter: ->(_term, scope) { scope })
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end.to raise_error(/Missing option: display_text/)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'fails with helpful message if filter option is missing' do
|
217
|
+
expect do
|
218
|
+
ActiveAdminHelpers.setup do
|
219
|
+
ActiveAdmin.register(Post) do
|
220
|
+
searchable_select_options(scope: Post,
|
221
|
+
display_text: ->(_term, scope) { scope })
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end.to raise_error(/Missing option: filter/)
|
225
|
+
end
|
226
|
+
|
227
|
+
def json_response
|
228
|
+
JSON.parse(response.body).with_indifferent_access
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'support/models'
|
3
|
+
require 'support/capybara'
|
4
|
+
require 'support/active_admin_helpers'
|
5
|
+
|
6
|
+
RSpec.describe 'production build compatibility', type: :feature do
|
7
|
+
# Using static admin files configured with searchable_select
|
8
|
+
|
9
|
+
describe 'tom-select initialization', js: true do
|
10
|
+
it 'initializes tom-select on searchable select inputs' do
|
11
|
+
visit '/admin/posts'
|
12
|
+
|
13
|
+
# Wait for page to load
|
14
|
+
expect(page).to have_css('.searchable-select-input')
|
15
|
+
|
16
|
+
# Check that Tom Select wrapper is created
|
17
|
+
expect(page).to have_css('.ts-wrapper', wait: 5)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'basic functionality without JavaScript', js: false do
|
22
|
+
it 'renders searchable select as a regular select' do
|
23
|
+
Category.create(name: 'Books')
|
24
|
+
Category.create(name: 'Movies')
|
25
|
+
|
26
|
+
visit '/admin/posts/new'
|
27
|
+
|
28
|
+
# Should have a select input with the searchable-select-input class
|
29
|
+
expect(page).to have_css('select.searchable-select-input')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'ajax functionality', js: true do
|
34
|
+
it 'loads options via ajax when clicked' do
|
35
|
+
Category.create(name: 'Technology')
|
36
|
+
Category.create(name: 'Science')
|
37
|
+
|
38
|
+
visit '/admin/posts'
|
39
|
+
|
40
|
+
# Open the filter select - click the first tom-select control
|
41
|
+
find('.ts-control', match: :first).click
|
42
|
+
|
43
|
+
# Wait for ajax to load options
|
44
|
+
expect(page).to have_css('.ts-dropdown .option', text: 'Technology', wait: 5)
|
45
|
+
expect(page).to have_css('.ts-dropdown .option', text: 'Science')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'filters options based on search term' do
|
49
|
+
Category.create(name: 'Ruby Programming')
|
50
|
+
Category.create(name: 'Python Programming')
|
51
|
+
Category.create(name: 'JavaScript')
|
52
|
+
|
53
|
+
visit '/admin/posts'
|
54
|
+
|
55
|
+
# Open the filter select - click the first tom-select control
|
56
|
+
find('.ts-control', match: :first).click
|
57
|
+
|
58
|
+
# Type in search box (Tom Select uses different structure) - be more specific
|
59
|
+
find('.ts-control input', match: :first).set('Ruby')
|
60
|
+
|
61
|
+
# Should only show matching option
|
62
|
+
expect(page).to have_css('.ts-dropdown .option', text: 'Ruby Programming', wait: 5)
|
63
|
+
expect(page).not_to have_css('.ts-dropdown .option', text: 'Python Programming')
|
64
|
+
expect(page).not_to have_css('.ts-dropdown .option', text: 'JavaScript')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'form submission', js: true do
|
69
|
+
it 'submits selected value correctly' do
|
70
|
+
category = Category.create(name: 'Test Category')
|
71
|
+
|
72
|
+
visit '/admin/posts/new'
|
73
|
+
|
74
|
+
fill_in 'Title', with: 'Test Post'
|
75
|
+
|
76
|
+
# Wait for Tom Select to initialize and select category using Tom Select
|
77
|
+
sleep 0.5 # Allow time for Tom Select to initialize
|
78
|
+
within '#post_category_input' do
|
79
|
+
find('.ts-control').click
|
80
|
+
end
|
81
|
+
find('.ts-dropdown .option', text: 'Test Category').click
|
82
|
+
|
83
|
+
click_button 'Create Post'
|
84
|
+
|
85
|
+
# Verify the post was created with the correct category
|
86
|
+
post = Post.last
|
87
|
+
expect(post).to be_present
|
88
|
+
expect(post.title).to eq('Test Post')
|
89
|
+
expect(post.category).to eq(category)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'preselected values', js: true do
|
94
|
+
it 'shows preselected value when editing' do
|
95
|
+
category = Category.create(name: 'Selected Category')
|
96
|
+
post = Post.create(title: 'Test', category: category)
|
97
|
+
|
98
|
+
visit "/admin/posts/#{post.id}/edit"
|
99
|
+
|
100
|
+
# Check that the selected value is displayed
|
101
|
+
within '#post_category_input' do
|
102
|
+
within '.ts-control' do
|
103
|
+
expect(page).to have_content('Selected Category')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
22.13.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
4
|
+
gem 'rails', '~> 8.0.2', '>= 8.0.2.1'
|
5
|
+
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
|
6
|
+
gem 'propshaft'
|
7
|
+
# Use sqlite3 as the database for Active Record
|
8
|
+
gem 'sqlite3', '>= 2.1'
|
9
|
+
# Use the Puma web server [https://github.com/puma/puma]
|
10
|
+
gem 'puma', '>= 5.0'
|
11
|
+
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
|
12
|
+
gem 'jsbundling-rails'
|
13
|
+
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
|
14
|
+
gem 'cssbundling-rails'
|
15
|
+
|
16
|
+
# ActiveAdmin and dependencies
|
17
|
+
gem 'activeadmin', '~> 4.0.0.beta'
|
18
|
+
gem 'devise'
|
19
|
+
|
20
|
+
# Our gem under test
|
21
|
+
gem 'activeadmin-tom_select', path: '../..'
|
22
|
+
|
23
|
+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
24
|
+
# gem "bcrypt", "~> 3.1.7"
|
25
|
+
|
26
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
27
|
+
gem 'tzinfo-data', platforms: %i[windows jruby]
|
28
|
+
|
29
|
+
group :development, :test do
|
30
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
31
|
+
gem 'debug', platforms: %i[mri windows], require: 'debug/prelude'
|
32
|
+
|
33
|
+
# Testing gems
|
34
|
+
gem 'capybara', '~> 3.39'
|
35
|
+
gem 'capybara-playwright-driver', '~> 0.5'
|
36
|
+
gem 'database_cleaner-active_record', '~> 2.1'
|
37
|
+
gem 'rspec-rails', '~> 6.0'
|
38
|
+
end
|
39
|
+
|
40
|
+
group :development do
|
41
|
+
# Use console on exceptions pages [https://github.com/rails/web-console]
|
42
|
+
gem 'web-console'
|
43
|
+
end
|