├── .github
└── workflows
│ └── main.yaml
├── .gitignore
├── .rspec
├── .ruby-version
├── CODE_OF_CONDUCT.md
├── Gemfile
├── Gemfile.lock
├── LICENSE.txt
├── README.md
├── Rakefile
├── activeadmin-ajax_filter.gemspec
├── app
└── assets
│ ├── javascripts
│ └── activeadmin-ajax_filter.js.coffee
│ └── stylesheets
│ └── activeadmin-ajax_filter.scss
├── bin
├── console
└── setup
├── lib
├── active_admin
│ ├── ajax_filter.rb
│ ├── ajax_filter
│ │ ├── engine.rb
│ │ └── version.rb
│ └── inputs
│ │ ├── ajax_core.rb
│ │ ├── ajax_select_input.rb
│ │ └── filters
│ │ └── ajax_select_input.rb
└── activeadmin-ajax_filter.rb
├── spec
├── active_admin
│ └── inputs
│ │ └── ajax_core_spec.rb
├── dummy
│ ├── README.rdoc
│ ├── Rakefile
│ ├── app
│ │ ├── admin
│ │ │ ├── categories.rb
│ │ │ ├── dashboard.rb
│ │ │ ├── items.rb
│ │ │ ├── subcategories.rb
│ │ │ └── tags.rb
│ │ ├── assets
│ │ │ ├── config
│ │ │ │ └── manifest.js
│ │ │ ├── images
│ │ │ │ └── .keep
│ │ │ ├── javascripts
│ │ │ │ ├── active_admin.js.coffee
│ │ │ │ └── application.js
│ │ │ └── stylesheets
│ │ │ │ ├── active_admin.scss
│ │ │ │ └── application.css
│ │ ├── controllers
│ │ │ ├── application_controller.rb
│ │ │ └── concerns
│ │ │ │ └── .keep
│ │ ├── decorators
│ │ │ └── subcategory_decorator.rb
│ │ ├── helpers
│ │ │ └── application_helper.rb
│ │ ├── mailers
│ │ │ └── .keep
│ │ ├── models
│ │ │ ├── .keep
│ │ │ ├── category.rb
│ │ │ ├── concerns
│ │ │ │ └── .keep
│ │ │ ├── item.rb
│ │ │ ├── subcategory.rb
│ │ │ └── tag.rb
│ │ └── views
│ │ │ └── layouts
│ │ │ └── application.html.erb
│ ├── bin
│ │ ├── bundle
│ │ ├── rails
│ │ ├── rake
│ │ └── setup
│ ├── config.ru
│ ├── config
│ │ ├── application.rb
│ │ ├── boot.rb
│ │ ├── cable.yml
│ │ ├── database.yml
│ │ ├── environment.rb
│ │ ├── environments
│ │ │ ├── development.rb
│ │ │ ├── production.rb
│ │ │ └── test.rb
│ │ ├── initializers
│ │ │ ├── active_admin.rb
│ │ │ ├── backtrace_silencers.rb
│ │ │ ├── content_security_policy.rb
│ │ │ ├── cookies_serializer.rb
│ │ │ ├── filter_parameter_logging.rb
│ │ │ ├── inflections.rb
│ │ │ ├── mime_types.rb
│ │ │ ├── new_framework_defaults_7_0.rb
│ │ │ ├── permissions_policy.rb
│ │ │ ├── session_store.rb
│ │ │ └── wrap_parameters.rb
│ │ ├── locales
│ │ │ └── en.yml
│ │ ├── routes.rb
│ │ ├── secrets.yml
│ │ └── storage.yml
│ ├── db
│ │ ├── migrate
│ │ │ ├── 20150910072150_create_active_admin_comments.rb
│ │ │ ├── 20150910072505_initial_schema.rb
│ │ │ └── 20200418135023_create_tags.rb
│ │ └── schema.rb
│ ├── lib
│ │ └── assets
│ │ │ └── .keep
│ ├── log
│ │ └── .keep
│ └── public
│ │ ├── 404.html
│ │ ├── 422.html
│ │ ├── 500.html
│ │ └── favicon.ico
├── factories
│ ├── categories.rb
│ ├── items.rb
│ ├── subcategories.rb
│ └── tags.rb
├── features
│ └── ajax_form_input_spec.rb
├── rails_helper.rb
├── spec_helper.rb
└── support
│ ├── factory_girl.rb
│ ├── selectize_helpers.rb
│ └── wait_for_ajax.rb
└── test_app
└── blog
├── .gitattributes
├── .gitignore
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── admin
│ ├── admin_users.rb
│ ├── categories.rb
│ ├── dashboard.rb
│ ├── items.rb
│ ├── subcategories.rb
│ └── tags.rb
├── assets
│ ├── config
│ │ └── manifest.js
│ ├── images
│ │ └── .keep
│ ├── javascripts
│ │ └── active_admin.js
│ └── stylesheets
│ │ ├── active_admin.scss
│ │ └── application.css
├── channels
│ └── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
├── controllers
│ ├── application_controller.rb
│ └── concerns
│ │ └── .keep
├── decorators
│ └── subcategory_decorator.rb
├── helpers
│ └── application_helper.rb
├── jobs
│ └── application_job.rb
├── mailers
│ └── application_mailer.rb
├── models
│ ├── admin_user.rb
│ ├── application_record.rb
│ ├── category.rb
│ ├── concerns
│ │ └── .keep
│ ├── item.rb
│ ├── subcategory.rb
│ └── tag.rb
└── views
│ ├── admin
│ └── subcategories
│ │ └── panel.html.arb
│ └── layouts
│ ├── application.html.erb
│ ├── mailer.html.erb
│ └── mailer.text.erb
├── bin
├── bundle
├── rails
├── rake
└── setup
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── active_admin.rb
│ ├── assets.rb
│ ├── content_security_policy.rb
│ ├── devise.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ └── permissions_policy.rb
├── locales
│ ├── devise.en.yml
│ └── en.yml
├── puma.rb
├── routes.rb
└── storage.yml
├── db
├── migrate
│ ├── 20230425060437_devise_create_admin_users.rb
│ ├── 20230425060439_create_active_admin_comments.rb
│ ├── 20230425060707_initial_schema.rb
│ └── 20230425060708_create_tags.rb
├── schema.rb
└── seeds.rb
├── lib
├── assets
│ └── .keep
└── tasks
│ └── .keep
├── log
└── .keep
├── public
├── 404.html
├── 422.html
├── 500.html
├── apple-touch-icon-precomposed.png
├── apple-touch-icon.png
├── favicon.ico
└── robots.txt
├── storage
└── .keep
├── test
├── application_system_test_case.rb
├── channels
│ └── application_cable
│ │ └── connection_test.rb
├── controllers
│ └── .keep
├── fixtures
│ ├── admin_users.yml
│ └── files
│ │ └── .keep
├── helpers
│ └── .keep
├── integration
│ └── .keep
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ └── admin_user_test.rb
├── system
│ └── .keep
└── test_helper.rb
├── tmp
├── .keep
├── pids
│ └── .keep
└── storage
│ └── .keep
└── vendor
└── .keep
/.github/workflows/main.yaml:
--------------------------------------------------------------------------------
1 | name: Tests
2 | on:
3 | push:
4 | branches:
5 | - master
6 | pull_request:
7 | branches:
8 | - master
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 |
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | ruby-version: ['2.7', '3.0', '3.1']
18 |
19 | steps:
20 | - uses: actions/checkout@v3
21 | - name: Set up Ruby ${{ matrix.ruby-version }}
22 | uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
23 | with:
24 | ruby-version: ${{ matrix.ruby-version }}
25 | bundler-cache: true
26 |
27 | - run: bundle install --retry=3
28 | - run: bundle exec rake dummy:prepare
29 | - run: bundle exec rspec
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /pkg/
7 | /spec/reports/
8 | /spec/dummy/tmp/
9 | /spec/dummy/public/assets
10 | /spec/dummy/.sass-cache
11 | /spec/dummy/log/*.log
12 | /tmp/
13 | .DS_Store
14 | *.sqlite3
15 | *.gem
16 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --require rails_helper
3 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.7.2
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4 |
5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6 |
7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8 |
9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10 |
11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12 |
13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
14 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # Specify your gem's dependencies in activeadmin-ajax_filter.gemspec
4 | gemspec
5 | gem 'sprockets-rails'
6 | gem 'draper', group: 'test'
7 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: .
3 | specs:
4 | activeadmin-ajax_filter (0.7.0)
5 | activeadmin (>= 1.0)
6 | coffee-rails (>= 4.1.0)
7 | rails (>= 7.0)
8 | selectize-rails (>= 0.12.6)
9 |
10 | GEM
11 | remote: https://rubygems.org/
12 | specs:
13 | actioncable (7.0.4.3)
14 | actionpack (= 7.0.4.3)
15 | activesupport (= 7.0.4.3)
16 | nio4r (~> 2.0)
17 | websocket-driver (>= 0.6.1)
18 | actionmailbox (7.0.4.3)
19 | actionpack (= 7.0.4.3)
20 | activejob (= 7.0.4.3)
21 | activerecord (= 7.0.4.3)
22 | activestorage (= 7.0.4.3)
23 | activesupport (= 7.0.4.3)
24 | mail (>= 2.7.1)
25 | net-imap
26 | net-pop
27 | net-smtp
28 | actionmailer (7.0.4.3)
29 | actionpack (= 7.0.4.3)
30 | actionview (= 7.0.4.3)
31 | activejob (= 7.0.4.3)
32 | activesupport (= 7.0.4.3)
33 | mail (~> 2.5, >= 2.5.4)
34 | net-imap
35 | net-pop
36 | net-smtp
37 | rails-dom-testing (~> 2.0)
38 | actionpack (7.0.4.3)
39 | actionview (= 7.0.4.3)
40 | activesupport (= 7.0.4.3)
41 | rack (~> 2.0, >= 2.2.0)
42 | rack-test (>= 0.6.3)
43 | rails-dom-testing (~> 2.0)
44 | rails-html-sanitizer (~> 1.0, >= 1.2.0)
45 | actiontext (7.0.4.3)
46 | actionpack (= 7.0.4.3)
47 | activerecord (= 7.0.4.3)
48 | activestorage (= 7.0.4.3)
49 | activesupport (= 7.0.4.3)
50 | globalid (>= 0.6.0)
51 | nokogiri (>= 1.8.5)
52 | actionview (7.0.4.3)
53 | activesupport (= 7.0.4.3)
54 | builder (~> 3.1)
55 | erubi (~> 1.4)
56 | rails-dom-testing (~> 2.0)
57 | rails-html-sanitizer (~> 1.1, >= 1.2.0)
58 | activeadmin (2.13.1)
59 | arbre (~> 1.2, >= 1.2.1)
60 | formtastic (>= 3.1, < 5.0)
61 | formtastic_i18n (~> 0.4)
62 | inherited_resources (~> 1.7)
63 | jquery-rails (~> 4.2)
64 | kaminari (~> 1.0, >= 1.2.1)
65 | railties (>= 6.1, < 7.1)
66 | ransack (>= 2.1.1, < 4)
67 | activejob (7.0.4.3)
68 | activesupport (= 7.0.4.3)
69 | globalid (>= 0.3.6)
70 | activemodel (7.0.4.3)
71 | activesupport (= 7.0.4.3)
72 | activemodel-serializers-xml (1.0.2)
73 | activemodel (> 5.x)
74 | activesupport (> 5.x)
75 | builder (~> 3.1)
76 | activerecord (7.0.4.3)
77 | activemodel (= 7.0.4.3)
78 | activesupport (= 7.0.4.3)
79 | activestorage (7.0.4.3)
80 | actionpack (= 7.0.4.3)
81 | activejob (= 7.0.4.3)
82 | activerecord (= 7.0.4.3)
83 | activesupport (= 7.0.4.3)
84 | marcel (~> 1.0)
85 | mini_mime (>= 1.1.0)
86 | activesupport (7.0.4.3)
87 | concurrent-ruby (~> 1.0, >= 1.0.2)
88 | i18n (>= 1.6, < 2)
89 | minitest (>= 5.1)
90 | tzinfo (~> 2.0)
91 | addressable (2.4.0)
92 | arbre (1.5.0)
93 | activesupport (>= 3.0.0, < 7.1)
94 | ruby2_keywords (>= 0.0.2, < 1.0)
95 | builder (3.2.4)
96 | capybara (2.7.1)
97 | addressable
98 | mime-types (>= 1.16)
99 | nokogiri (>= 1.3.3)
100 | rack (>= 1.0.0)
101 | rack-test (>= 0.5.4)
102 | xpath (~> 2.0)
103 | cliver (0.3.2)
104 | codeclimate-test-reporter (0.4.8)
105 | simplecov (>= 0.7.1, < 1.0.0)
106 | coderay (1.1.2)
107 | coffee-rails (5.0.0)
108 | coffee-script (>= 2.2.0)
109 | railties (>= 5.2.0)
110 | coffee-script (2.4.1)
111 | coffee-script-source
112 | execjs
113 | coffee-script-source (1.12.2)
114 | concurrent-ruby (1.2.2)
115 | crass (1.0.6)
116 | database_cleaner (1.8.3)
117 | date (3.3.3)
118 | diff-lcs (1.3)
119 | docile (1.4.0)
120 | draper (4.0.0)
121 | actionpack (>= 5.0)
122 | activemodel (>= 5.0)
123 | activemodel-serializers-xml (>= 1.0)
124 | activesupport (>= 5.0)
125 | request_store (>= 1.0)
126 | erubi (1.12.0)
127 | execjs (2.8.1)
128 | factory_girl (4.5.0)
129 | activesupport (>= 3.0.0)
130 | factory_girl_rails (4.5.0)
131 | factory_girl (~> 4.5.0)
132 | railties (>= 3.0.0)
133 | ffi (1.15.5)
134 | formtastic (4.0.0)
135 | actionpack (>= 5.2.0)
136 | formtastic_i18n (0.7.0)
137 | globalid (1.1.0)
138 | activesupport (>= 5.0)
139 | has_scope (0.8.1)
140 | actionpack (>= 5.2)
141 | activesupport (>= 5.2)
142 | i18n (1.12.0)
143 | concurrent-ruby (~> 1.0)
144 | inherited_resources (1.13.1)
145 | actionpack (>= 5.2, < 7.1)
146 | has_scope (~> 0.6)
147 | railties (>= 5.2, < 7.1)
148 | responders (>= 2, < 4)
149 | jquery-rails (4.5.1)
150 | rails-dom-testing (>= 1, < 3)
151 | railties (>= 4.2.0)
152 | thor (>= 0.14, < 2.0)
153 | kaminari (1.2.2)
154 | activesupport (>= 4.1.0)
155 | kaminari-actionview (= 1.2.2)
156 | kaminari-activerecord (= 1.2.2)
157 | kaminari-core (= 1.2.2)
158 | kaminari-actionview (1.2.2)
159 | actionview
160 | kaminari-core (= 1.2.2)
161 | kaminari-activerecord (1.2.2)
162 | activerecord
163 | kaminari-core (= 1.2.2)
164 | kaminari-core (1.2.2)
165 | launchy (2.4.3)
166 | addressable (~> 2.3)
167 | loofah (2.20.0)
168 | crass (~> 1.0.2)
169 | nokogiri (>= 1.5.9)
170 | mail (2.8.1)
171 | mini_mime (>= 0.1.1)
172 | net-imap
173 | net-pop
174 | net-smtp
175 | marcel (1.0.2)
176 | method_source (1.0.0)
177 | mime-types (3.4.1)
178 | mime-types-data (~> 3.2015)
179 | mime-types-data (3.2023.0218.1)
180 | mini_mime (1.1.2)
181 | mini_portile2 (2.8.1)
182 | minitest (5.18.0)
183 | net-imap (0.3.4)
184 | date
185 | net-protocol
186 | net-pop (0.1.2)
187 | net-protocol
188 | net-protocol (0.2.1)
189 | timeout
190 | net-smtp (0.3.3)
191 | net-protocol
192 | nio4r (2.5.9)
193 | nokogiri (1.14.3)
194 | mini_portile2 (~> 2.8.0)
195 | racc (~> 1.4)
196 | phantomjs (2.1.1.0)
197 | poltergeist (1.10.0)
198 | capybara (~> 2.1)
199 | cliver (~> 0.3.1)
200 | websocket-driver (>= 0.2.0)
201 | pry (0.13.1)
202 | coderay (~> 1.1)
203 | method_source (~> 1.0)
204 | racc (1.6.2)
205 | rack (2.2.6.4)
206 | rack-test (2.1.0)
207 | rack (>= 1.3)
208 | rails (7.0.4.3)
209 | actioncable (= 7.0.4.3)
210 | actionmailbox (= 7.0.4.3)
211 | actionmailer (= 7.0.4.3)
212 | actionpack (= 7.0.4.3)
213 | actiontext (= 7.0.4.3)
214 | actionview (= 7.0.4.3)
215 | activejob (= 7.0.4.3)
216 | activemodel (= 7.0.4.3)
217 | activerecord (= 7.0.4.3)
218 | activestorage (= 7.0.4.3)
219 | activesupport (= 7.0.4.3)
220 | bundler (>= 1.15.0)
221 | railties (= 7.0.4.3)
222 | rails-dom-testing (2.0.3)
223 | activesupport (>= 4.2.0)
224 | nokogiri (>= 1.6)
225 | rails-html-sanitizer (1.5.0)
226 | loofah (~> 2.19, >= 2.19.1)
227 | railties (7.0.4.3)
228 | actionpack (= 7.0.4.3)
229 | activesupport (= 7.0.4.3)
230 | method_source
231 | rake (>= 12.2)
232 | thor (~> 1.0)
233 | zeitwerk (~> 2.5)
234 | rake (12.3.3)
235 | ransack (3.2.1)
236 | activerecord (>= 6.1.5)
237 | activesupport (>= 6.1.5)
238 | i18n
239 | request_store (1.5.0)
240 | rack (>= 1.4)
241 | responders (3.1.0)
242 | actionpack (>= 5.2)
243 | railties (>= 5.2)
244 | rspec (3.9.0)
245 | rspec-core (~> 3.9.0)
246 | rspec-expectations (~> 3.9.0)
247 | rspec-mocks (~> 3.9.0)
248 | rspec-core (3.9.1)
249 | rspec-support (~> 3.9.1)
250 | rspec-expectations (3.9.1)
251 | diff-lcs (>= 1.2.0, < 2.0)
252 | rspec-support (~> 3.9.0)
253 | rspec-mocks (3.9.1)
254 | diff-lcs (>= 1.2.0, < 2.0)
255 | rspec-support (~> 3.9.0)
256 | rspec-rails (3.9.1)
257 | actionpack (>= 3.0)
258 | activesupport (>= 3.0)
259 | railties (>= 3.0)
260 | rspec-core (~> 3.9.0)
261 | rspec-expectations (~> 3.9.0)
262 | rspec-mocks (~> 3.9.0)
263 | rspec-support (~> 3.9.0)
264 | rspec-support (3.9.2)
265 | ruby2_keywords (0.0.5)
266 | sassc (2.4.0)
267 | ffi (~> 1.9)
268 | sassc-rails (2.1.2)
269 | railties (>= 4.0.0)
270 | sassc (>= 2.0)
271 | sprockets (> 3.0)
272 | sprockets-rails
273 | tilt
274 | selectize-rails (0.12.6)
275 | simplecov (0.22.0)
276 | docile (~> 1.1)
277 | simplecov-html (~> 0.11)
278 | simplecov_json_formatter (~> 0.1)
279 | simplecov-html (0.12.3)
280 | simplecov_json_formatter (0.1.4)
281 | sprockets (4.2.0)
282 | concurrent-ruby (~> 1.0)
283 | rack (>= 2.2.4, < 4)
284 | sprockets-rails (3.4.2)
285 | actionpack (>= 5.2)
286 | activesupport (>= 5.2)
287 | sprockets (>= 3.0.0)
288 | sqlite3 (1.6.2)
289 | mini_portile2 (~> 2.8.0)
290 | temping (3.3.0)
291 | activerecord (>= 3.1)
292 | activesupport (>= 3.1)
293 | thor (1.2.1)
294 | tilt (2.1.0)
295 | timeout (0.3.2)
296 | tzinfo (2.0.6)
297 | concurrent-ruby (~> 1.0)
298 | webrick (1.8.1)
299 | websocket-driver (0.7.5)
300 | websocket-extensions (>= 0.1.0)
301 | websocket-extensions (0.1.5)
302 | xpath (2.0.0)
303 | nokogiri (~> 1.3)
304 | zeitwerk (2.6.7)
305 |
306 | PLATFORMS
307 | ruby
308 |
309 | DEPENDENCIES
310 | activeadmin-ajax_filter!
311 | bundler (~> 1.10)
312 | capybara (~> 2.1)
313 | codeclimate-test-reporter (~> 0.4)
314 | database_cleaner (~> 1.5)
315 | draper
316 | factory_girl_rails
317 | launchy (~> 2.4.3)
318 | phantomjs (~> 2.1.1)
319 | poltergeist (~> 1.10.0)
320 | pry
321 | rake (~> 12)
322 | rspec (~> 3.3, >= 3.3.0)
323 | rspec-rails (~> 3.3)
324 | sassc-rails
325 | selectize-rails (>= 0.11.2)
326 | sprockets-rails
327 | sqlite3 (~> 1.4)
328 | temping (~> 3.3, >= 3.3.0)
329 | webrick
330 |
331 | BUNDLED WITH
332 | 1.17.2
333 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Alex Emelyanov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://badge.fury.io/rb/activeadmin-ajax_filter)
2 | [](https://github.com/holyketzer/activeadmin-ajax_filter/actions)
3 | [](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter)
4 |
5 | # Activeadmin::AjaxFilter
6 |
7 | This gem extends ActiveAdmin so that your can use filters with AJAX-powered input.
8 |
9 |
10 |
11 |
12 | ## Prerequisites and notes
13 |
14 | This extension assumes that you're using [Active Admin](https://github.com/activeadmin/activeadmin) with [Ransack](https://github.com/activerecord-hackery/ransack). And for AJAX input it uses [selectize-rails](https://github.com/manuelvanrijn/selectize-rails)
15 |
16 | Versions:
17 | * `0.7.0` - Rails 7, minimum Ruby version `2.7`
18 | * `0.6.0` - Rails 6, minimum Ruby version `2.7`
19 | * `0.5.0` - Rails 5, minimum Ruby version `2.5`
20 | * `0.4.5` - could break you build due to issue with `sprockets` version major update, now it's yanked, use `0.4.6` instead. If you on `sprockets >= 4` and `rails >= 5` use version `0.5.0`
21 |
22 | ## Installation
23 |
24 | Add this line to your application's Gemfile:
25 |
26 | ```ruby
27 | gem 'activeadmin-ajax_filter'
28 | ```
29 |
30 | And then execute:
31 |
32 | $ bundle
33 |
34 | Or install it yourself as:
35 |
36 | $ gem install activeadmin-ajax_filter
37 |
38 | ## Usage
39 |
40 | Include this line in your JavaScript code (active_admin.js)
41 |
42 | ```js
43 | //= require selectize
44 | //= require activeadmin-ajax_filter
45 | ```
46 |
47 | Include this line in your CSS code (active_admin.scss)
48 |
49 | ```scss
50 | @import "selectize";
51 | @import "selectize.default";
52 | @import "activeadmin-ajax_filter";
53 | ```
54 |
55 | Include `ActiveAdmin::AjaxFilter` module to the ActiveAdmin relation resource for which you want to support filtering and add `ajax_select` filter to main resource. For example:
56 |
57 | ```ruby
58 | # Relation-resource
59 | ActiveAdmin.register User do
60 | include ActiveAdmin::AjaxFilter
61 | # ...
62 | end
63 |
64 | # Main resource
65 | # As a filter
66 | ActiveAdmin.register Invoice do
67 | filter :user, as: :ajax_select, data: {
68 | url: :filter_admin_users_path,
69 | search_fields: [:email, :customer_uid],
70 | limit: 7,
71 | }
72 | # ...
73 | end
74 |
75 | # As a form input
76 | ActiveAdmin.register Invoice do
77 | form do |f|
78 | f.input :language # used by ajax_search_fields
79 | f.input :user, as: :ajax_select, data: {
80 | url: filter_admin_users_path,
81 | search_fields: [:name],
82 | static_ransack: { active_eq: true },
83 | ajax_search_fields: [:language_id],
84 | }
85 | # ...
86 | end
87 | end
88 | ```
89 |
90 | You can use next parameters in `data` hash:
91 |
92 | * `search_fields` - fields by which AJAX search will be performed, **required**
93 | * `display_fields` - fields which will be displayed in drop down list during search, first field will be displayed for selected option
94 | * `limit` - count of the items which will be requested by AJAX, by default `5`
95 | * `value_field` - value field for html select element, by default `id`
96 | * `ordering` - sort string like `email ASC, customer_uid DESC`, by default it uses first value of `search_fields` with `ASC` direction
97 | * `ransack` - ransack query which will be applied, by default it's builded from `search_fields` with `or` and `contains` clauses, e.g.: `email_or_customer_uid_cont`
98 | * `url` - url for AJAX query by default is builded from field name. For inputs you can use url helpers, but on filters level url helpers isn't available, so if you need them you can pass symbols and it will be evaluated as url path (e.g. `:filter_admin_users_path`). `String` with relative path (like `/admin/users/filter`) can be used for both inputs and filters.
99 | * `ajax_search_fields` - array of field names. `ajax_select` input depends on `ajax_search_fields` values: e.g. you can scope user by languages.
100 | * `static_ransack` - hash of ransack predicates which will be applied statically and independently from current input field value
101 | * `min_chars_count_to_request` - minimal count of chars in the input field to make an AJAX request
102 | * `placeholder` - input field placeholder.
103 | * `close_after_select` - close search results drop-down after selected a value. Default is `false`.
104 |
105 | ### Filter by belongs_to relation fields
106 |
107 | ```ruby
108 | class Patient < ApplicationRecord
109 | belongs_to :user
110 | # ...
111 | end
112 |
113 | f.input :patient, as: :ajax_select, collection: [], data: {
114 | display_fields: ['id', 'user.name'],
115 | search_fields: ['user.name'],
116 | ordering: 'id ASC',
117 | url: :filter_admin_patients_path
118 | }
119 | ```
120 | Ordering by related fields doesn't work, e.g. this will not work: `ordering: 'user.name ASC'`
121 |
122 |
123 | ## Caveats
124 |
125 | ### Ransack _cont on Integer column
126 |
127 | Due to issue with Ransack and Postgres it's not possbile to make searches like `id_cont` because `id` is a `Integer` type (more here https://github.com/activerecord-hackery/ransack/issues/85)
128 |
129 | The way to handle it find with another predicate like:
130 |
131 | ```ruby
132 | filter :user_id, as: :ajax_select, collection: [], data: {
133 | url: '/admin/users/filter',
134 | display_fields: [:full_name, :phone],
135 | ransack: 'id_eq', # !!! predicate is ovewritten to `eq` by default it's `cont`
136 | search_fields: ['id'],
137 | }
138 | ```
139 |
140 | ## Development
141 |
142 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
143 |
144 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
145 |
146 | ## Contributing
147 |
148 | Bug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-ajax_filter. This project is intended to be a safe, welcoming space for collaboration.
149 |
150 | ## License
151 |
152 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
153 |
154 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'bundler/gem_tasks'
2 |
3 |
4 | require 'rspec/core/rake_task'
5 | RSpec::Core::RakeTask.new(:spec)
6 | task default: ['dummy:prepare', :spec]
7 |
8 | require 'rake/clean'
9 | CLEAN.include 'spec/dummy/db/*sqlite3', 'spec/dummy/log/*', 'spec/dummy/public/assets/*', 'spec/dummy/tmp/**/*'
10 |
11 | namespace :dummy do
12 | desc 'Setup dummy app database'
13 | task :prepare do
14 | # File.expand_path is executed directory of generated Rails app
15 | rakefile = File.expand_path('Rakefile', dummy_path)
16 | command = "rake -f '%s' db:schema:load RAILS_ENV=test" % rakefile
17 | sh(command) unless ENV['DISABLE_CREATE']
18 | end
19 |
20 | def dummy_path
21 | rel_path = ENV['DUMMY_APP_PATH'] || 'spec/dummy'
22 | if @current_path.to_s.include?(rel_path)
23 | @current_path
24 | else
25 | @current_path = File.expand_path(rel_path)
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/activeadmin-ajax_filter.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path('../lib', __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require 'active_admin/ajax_filter/version'
5 |
6 | Gem::Specification.new do |gem|
7 | gem.name = 'activeadmin-ajax_filter'
8 | gem.version = ActiveAdmin::AjaxFilter::VERSION
9 | gem.authors = ['Alex Emelyanov']
10 | gem.email = ['holyketzer@gmail.com']
11 |
12 | gem.summary = 'AJAX filters for ActiveAdmin'
13 | gem.description = 'Allows to define form inputs and filters by relation for ActiveAdmin resource pages using Ransacker to dynamicaly load items while user is typing symbols in filter'
14 | gem.homepage = 'https://github.com/holyketzer/activeadmin-ajax_filter'
15 | gem.license = 'MIT'
16 |
17 | gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18 | gem.bindir = 'exe'
19 | gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
20 | gem.require_paths = ['lib']
21 |
22 | gem.add_dependency 'activeadmin', '>= 1.0'
23 | gem.add_dependency 'rails', '>= 7.0'
24 | gem.add_dependency 'coffee-rails', '>= 4.1.0'
25 | gem.add_dependency 'selectize-rails', '>= 0.12.6'
26 | # gem.add_dependency 'has_scope', '>= 0.6.0' # Force Ruby 2.1.5 support
27 | gem.add_development_dependency 'sassc-rails'
28 | gem.add_development_dependency 'bundler', '~> 1.10'
29 | gem.add_development_dependency 'rake', '~> 12'
30 | gem.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
31 | gem.add_development_dependency 'rspec-rails', '~> 3.3'
32 | gem.add_development_dependency 'factory_girl_rails'
33 | gem.add_development_dependency 'sqlite3', '~> 1.4'
34 | gem.add_development_dependency 'temping', '~> 3.3', '>= 3.3.0'
35 | gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
36 | gem.add_development_dependency 'capybara', '~> 2.1'
37 | gem.add_development_dependency 'phantomjs', '~> 2.1.1'
38 | gem.add_development_dependency 'poltergeist', '~> 1.10.0'
39 | gem.add_development_dependency 'selectize-rails', '>= 0.11.2'
40 | gem.add_development_dependency 'database_cleaner', '~> 1.5'
41 | gem.add_development_dependency 'launchy', '~> 2.4.3'
42 | gem.add_development_dependency 'pry'
43 | gem.add_development_dependency 'webrick'
44 | end
45 |
--------------------------------------------------------------------------------
/app/assets/javascripts/activeadmin-ajax_filter.js.coffee:
--------------------------------------------------------------------------------
1 | $ ->
2 | unique = (array) ->
3 | array.filter (item, i, array) ->
4 | i == array.indexOf(item)
5 |
6 | apply_filter_ajax_select = () ->
7 | $('.filter_ajax_select select, .ajax_select select').each (_, select) ->
8 | select = $(select)
9 | valueField = select.data('value-field')
10 | closeAfterSelect = select.data('close-after-select') || false
11 | display_fields = select.data('display-fields').split(' ')
12 | searchFields = select.data('search-fields').split(' ')
13 | staticRansack = select.data('static-ransack')
14 | minCharsCountToRequest = select.data('min-chars-count-to-request') || 1
15 | placeholder = select.data('placeholder') || ''
16 |
17 | ajaxFields = select.data('ajax-search-fields')
18 | if ajaxFields
19 | ajaxFields = ajaxFields.split(' ')
20 | else
21 | ajaxFields = []
22 |
23 | ordering = select.data('ordering')
24 | url = select.data('url')
25 |
26 | loadOptions = (q, callback) ->
27 | $.ajax
28 | url: url
29 | type: 'GET'
30 | dataType: 'json'
31 | data:
32 | q: q
33 | limit: select.data('limit')
34 | order: ordering
35 | searchFields: searchFields
36 | error: ->
37 | callback()
38 | success: (res) ->
39 | callback(res)
40 |
41 | relatedInput = (field) ->
42 | $("[name*=#{field}]", select.parents('fieldset'))
43 |
44 | isCircularAjaxSearchLink = (initial_input_id, field) ->
45 | input = relatedInput(field)
46 | if input.length
47 | (input.data('ajax-search-fields') or '').split(' ').some (ajaxField) ->
48 | ajaxField.length > 0 && relatedInput(ajaxField).attr('id') == initial_input_id
49 |
50 | select.selectize
51 | valueField: valueField
52 | labelField: display_fields[0]
53 | closeAfterSelect: closeAfterSelect
54 | placeholder: placeholder
55 | searchField: searchFields
56 | sortField: ordering.split(',').map (clause)->
57 | c = clause.trim().split(' ')
58 | { field: c[0], direction: c[1] }
59 | options: []
60 | create: false
61 | render:
62 | option: (item, escape) ->
63 | html = unique(display_fields.concat(searchFields)).map (field, index)->
64 | value = escape(item[field])
65 |
66 | if index == 0
67 | klass = 'primary'
68 | else
69 | klass = 'secondary'
70 |
71 | "#{value}"
72 |
73 | "
#{html.join('')}
"
74 |
75 | load: (query, callback) ->
76 | if query.length && query.length >= minCharsCountToRequest
77 | q = {}
78 | q[select.data('ransack')] = query
79 |
80 | ajaxFields.forEach (field) ->
81 | q["#{field}_eq"] = relatedInput(field).val()
82 | # clear cache because it wrong with changing values of ajaxFields
83 | select.loadedSearches = {}
84 |
85 | for ransack, value of staticRansack
86 | q[ransack] = value
87 |
88 | loadOptions(q, callback)
89 | else
90 | callback()
91 |
92 | onInitialize: ->
93 | selectize = this
94 | selectedValue = select.data('selected-value')
95 | selectedRansack = "#{valueField}_in"
96 |
97 | if selectedValue
98 | q = {}
99 | q[selectedRansack] = String(selectedValue).split(' ')
100 |
101 | loadOptions(q, (res)->
102 | if res && res.length
103 | for item in res
104 | selectize.addOption(item)
105 | selectize.addItem(item[valueField])
106 | )
107 |
108 | ajaxFields.forEach (field) ->
109 | if !isCircularAjaxSearchLink(selectize.$input.attr('id'), field)
110 | relatedInput(field).change ->
111 | selectize.clearOptions()
112 |
113 | # apply ajax filter to all static inputs
114 | apply_filter_ajax_select()
115 |
116 | # apply ajax filter on inputs inside has_many entries
117 | $("form.formtastic .has_many_add").click ->
118 | setTimeout((-> apply_filter_ajax_select()), 0)
119 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/activeadmin-ajax_filter.scss:
--------------------------------------------------------------------------------
1 | .filter_ajax_select .selectize-dropdown {
2 | .item {
3 | border-bottom: light-gray 1px solid;
4 | }
5 |
6 | .primary {
7 | font-weight: bold;
8 | }
9 |
10 | .primary, .secondary {
11 | display: block;
12 | }
13 | }
14 |
15 | .ajax_select {
16 | .selectize-input {
17 | width: 70%;
18 | }
19 |
20 | .selectize-dropdown {
21 | .item {
22 | border-bottom: light-gray 1px solid;
23 | }
24 |
25 | .primary {
26 | font-weight: bold;
27 | }
28 |
29 | .primary, .secondary {
30 | display: block;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require "bundler/setup"
4 | require "activeadmin/ajax_filter"
5 |
6 | # You can add fixtures and/or initialization code here to make experimenting
7 | # with your gem easier. You can also use a different console, if you like.
8 |
9 | # (If you use this, don't forget to add pry to your Gemfile!)
10 | # require "pry"
11 | # Pry.start
12 |
13 | require "irb"
14 | IRB.start
15 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 |
5 | bundle install
6 |
7 | # Do any other automated setup that you need to do here
8 |
--------------------------------------------------------------------------------
/lib/active_admin/ajax_filter.rb:
--------------------------------------------------------------------------------
1 | require 'active_admin'
2 | require 'active_admin/ajax_filter/engine'
3 | require 'active_admin/ajax_filter/version'
4 | require 'active_admin/inputs/ajax_core'
5 | require 'active_admin/inputs/ajax_select_input'
6 | require 'active_admin/inputs/filters/ajax_select_input'
7 |
8 | module ActiveAdmin
9 | module AjaxFilter
10 | class << self
11 | # @param [ActiveAdmin::DSL] dsl
12 | # @return [void]
13 | #
14 | def included(dsl)
15 | dsl.instance_eval do
16 | collection_action :filter, method: :get do
17 | scope = find_collection(except: [:pagination, :collection_decorator])
18 | .order(params[:order])
19 | .limit(params[:limit] || 10)
20 | .distinct
21 |
22 | search_fields = Array(params[:searchFields])
23 |
24 | related_table_search_fields = search_fields
25 | .select { |f| f.include?('.') }
26 | .map { |f| f.split('.') }
27 |
28 | related_table_search_fields.each do |related_table, _|
29 | scope = scope.preload(related_table)
30 | end
31 |
32 | res = apply_collection_decorator(scope).map do |item|
33 | item_json = item.as_json
34 |
35 | related_table_search_fields.each do |related_table, search_field|
36 | item_json[related_table + '.' + search_field] = item.send(related_table).send(search_field)
37 | end
38 |
39 | item_json
40 | end
41 |
42 | render plain: res.to_json
43 | end
44 | end
45 | end
46 | end
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/lib/active_admin/ajax_filter/engine.rb:
--------------------------------------------------------------------------------
1 | require 'rails/engine'
2 |
3 | module ActiveAdmin
4 | module AjaxFilter
5 | # Including an Engine tells Rails that this gem contains assets
6 | class Engine < ::Rails::Engine
7 | require 'selectize-rails'
8 | end
9 | end
10 | end
--------------------------------------------------------------------------------
/lib/active_admin/ajax_filter/version.rb:
--------------------------------------------------------------------------------
1 | module ActiveAdmin
2 | module AjaxFilter
3 | VERSION = '0.7.0'
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/lib/active_admin/inputs/ajax_core.rb:
--------------------------------------------------------------------------------
1 | module ActiveAdmin
2 | module Inputs
3 | module AjaxCore
4 | DEFAULT_LIMIT = 5
5 |
6 | def pluck_column
7 | klass.reorder("#{method} asc").limit(collection_limit).uniq.pluck(method)
8 | end
9 |
10 | def input_html_options
11 | super.merge(
12 | 'data-limit' => collection_limit,
13 | 'data-value-field' => value_field,
14 | 'data-display-fields' => display_fields,
15 | 'data-search-fields' => search_fields,
16 | 'data-ajax-search-fields' => ajax_search_fields,
17 | 'data-ordering' => ordering,
18 | 'data-ransack' => ransack,
19 | 'data-static-ransack' => static_ransack,
20 | 'data-selected-value' => selected_value,
21 | 'data-url' => url,
22 | 'data-min-chars-count-to-request' => min_chars_count_to_request,
23 | 'data-placeholder' => placeholder,
24 | 'data-close-after-select' => close_after_select
25 | )
26 | end
27 |
28 | def ajax_data
29 | options[:data] || {}
30 | end
31 |
32 | def collection_limit
33 | ajax_data[:limit] || DEFAULT_LIMIT
34 | end
35 |
36 | def collection_from_association
37 | super.try(:limit, collection_limit).try(:ransack, static_ransack).try(:result)
38 | end
39 |
40 | def value_field
41 | ajax_data[:value_field] || :id
42 | end
43 |
44 | def display_fields
45 | ajax_data[:display_fields] || search_fields.take(1)
46 | end
47 |
48 | def search_fields
49 | ajax_data[:search_fields] || raise(ArgumentError, 'search_fields in required')
50 | end
51 |
52 | def ajax_search_fields
53 | ajax_data[:ajax_search_fields]
54 | end
55 |
56 | def ordering
57 | ajax_data[:ordering] || "#{display_fields.first} ASC"
58 | end
59 |
60 | def ransack
61 | ajax_data[:ransack] || "#{ransackify(search_fields).join('_or_')}_cont"
62 | end
63 |
64 | def static_ransack
65 | ajax_data.fetch(:static_ransack, {}).to_json
66 | end
67 |
68 | def min_chars_count_to_request
69 | ajax_data[:min_chars_count_to_request] || 1
70 | end
71 |
72 | def placeholder
73 | ajax_data[:placeholder]
74 | end
75 |
76 | def close_after_select
77 | ajax_data[:close_after_select] || false
78 | end
79 |
80 | def ransackify(field_names)
81 | # Map fields refer to related tables user.name -> user_name
82 | field_names.map { |f| f.to_s.sub('.', '_') }
83 | end
84 |
85 | def url
86 | case (url = ajax_data[:url])
87 | when nil then "#{method.to_s.pluralize}/filter"
88 | when Symbol then Rails.application.routes.url_helpers.send(url)
89 | else url
90 | end
91 | end
92 |
93 | def selected_value
94 | if @object
95 | @object.try(:send, input_name)
96 | end
97 | end
98 | end
99 | end
100 | end
101 |
--------------------------------------------------------------------------------
/lib/active_admin/inputs/ajax_select_input.rb:
--------------------------------------------------------------------------------
1 | module ActiveAdmin
2 | module Inputs
3 | class AjaxSelectInput < ::Formtastic::Inputs::SelectInput
4 | include ActiveAdmin::Inputs::AjaxCore
5 | end
6 | end
7 | end
--------------------------------------------------------------------------------
/lib/active_admin/inputs/filters/ajax_select_input.rb:
--------------------------------------------------------------------------------
1 | module ActiveAdmin
2 | module Inputs
3 | module Filters
4 | class AjaxSelectInput < SelectInput
5 | include ActiveAdmin::Inputs::AjaxCore
6 | end
7 | end
8 | end
9 | end
--------------------------------------------------------------------------------
/lib/activeadmin-ajax_filter.rb:
--------------------------------------------------------------------------------
1 | require 'active_admin/ajax_filter'
--------------------------------------------------------------------------------
/spec/active_admin/inputs/ajax_core_spec.rb:
--------------------------------------------------------------------------------
1 | require 'active_admin/inputs/ajax_core'
2 |
3 | RSpec.describe ActiveAdmin::Inputs::AjaxCore do
4 | before(:each) do
5 | Temping.create(:record) do
6 | with_columns do |t|
7 | t.string :name
8 | t.string :email
9 | end
10 | end
11 | end
12 |
13 | class StubFilter < ActiveAdmin::Inputs::Filters::SelectInput
14 | include ActiveAdmin::Inputs::AjaxCore
15 | end
16 |
17 | let(:builder) { nil }
18 | let(:template) { nil }
19 | let(:object) { nil }
20 | let(:object_name) { nil }
21 | let(:method) { :device }
22 | let(:options) { { data: data } }
23 | let(:data) { nil }
24 |
25 | let(:filter) { StubFilter.new(builder, template, object, object_name, method, options) }
26 |
27 | describe '#ajax_data' do
28 | subject { filter.ajax_data }
29 |
30 | context 'no data in options' do
31 | it 'should use empty hash' do
32 | is_expected.to eq Hash.new
33 | end
34 | end
35 |
36 | context 'data in options' do
37 | let(:data) { { x: 1 } }
38 |
39 | it 'should use data from options' do
40 | is_expected.to eq data
41 | end
42 | end
43 | end
44 |
45 | describe '#collection_limit' do
46 | subject { filter.collection_limit }
47 |
48 | context 'no limit in data' do
49 | it 'should use default value' do
50 | is_expected.to eq described_class::DEFAULT_LIMIT
51 | end
52 | end
53 |
54 | context 'limit in data' do
55 | let(:data) { { limit: 11 } }
56 |
57 | it 'should use explicit value' do
58 | is_expected.to eq 11
59 | end
60 | end
61 | end
62 |
63 | describe '#value_field' do
64 | subject { filter.value_field }
65 |
66 | context 'no value_field in data' do
67 | it 'should use default value' do
68 | is_expected.to eq :id
69 | end
70 | end
71 |
72 | context 'value_field in data' do
73 | let(:data) { { value_field: :name } }
74 |
75 | it 'should use explicit value' do
76 | is_expected.to eq :name
77 | end
78 | end
79 | end
80 |
81 | describe '#search_fields' do
82 | subject { filter.search_fields }
83 |
84 | context 'no search_fields in data' do
85 | it 'should raise error' do
86 | expect { subject }.to raise_error(ArgumentError)
87 | end
88 | end
89 |
90 | context 'search_fields in data' do
91 | let(:data) { { search_fields: [:name, :email] } }
92 |
93 | it 'should use explicit value' do
94 | is_expected.to eq [:name, :email]
95 | end
96 | end
97 | end
98 |
99 | describe '#ordering' do
100 | subject { filter.ordering }
101 |
102 | context 'no ordering in data' do
103 | let(:data) { { search_fields: [:name, :email] }}
104 |
105 | it 'should use first value from search_fields' do
106 | is_expected.to eq 'name ASC'
107 | end
108 | end
109 |
110 | context 'ordering in data' do
111 | let(:data) { { ordering: 'email DESC' } }
112 |
113 | it 'should use explicit value' do
114 | is_expected.to eq 'email DESC'
115 | end
116 | end
117 | end
118 |
119 | describe '#ransack' do
120 | subject { filter.ransack }
121 |
122 | context 'no ransack in data' do
123 | let(:data) { { search_fields: [:name, :email] } }
124 |
125 | it 'should build ransack from search_fields' do
126 | is_expected.to eq 'name_or_email_cont'
127 | end
128 | end
129 |
130 | context 'ransack in data' do
131 | let(:data) { { ransack: :uid_eq } }
132 |
133 | it 'should use explicit value' do
134 | is_expected.to eq :uid_eq
135 | end
136 | end
137 | end
138 |
139 | describe '#url' do
140 | subject { filter.url }
141 |
142 | context 'no ransack in data' do
143 | it 'should build url from filter name' do
144 | is_expected.to eq 'devices/filter'
145 | end
146 | end
147 |
148 | context 'url is a string' do
149 | let(:data) { { url: '/admin/invoices/filter' } }
150 |
151 | it 'should use explicit value' do
152 | is_expected.to eq '/admin/invoices/filter'
153 | end
154 | end
155 |
156 | context 'url is a symbol' do
157 |
158 | let(:data) { { url: :path_helper } }
159 | let(:path) { 'some_path' }
160 |
161 | before do
162 | allow(Rails.application.routes).to receive(:url_helpers).and_return(double(path_helper: path))
163 | end
164 |
165 | it 'should eval lambda' do
166 | is_expected.to eq path
167 | end
168 | end
169 | end
170 |
171 | describe '#selected_value' do
172 | subject { filter.selected_value }
173 |
174 | let(:input_name) { :user_id }
175 | let(:value) { 12 }
176 |
177 | before do
178 | allow(filter).to receive(:input_name).and_return(input_name)
179 | filter.instance_variable_set('@object', double(input_name => value))
180 | end
181 |
182 | it { expect(subject).to eq value }
183 | end
184 |
185 | describe '#input_html_options' do
186 | subject { filter.input_html_options }
187 |
188 | before do
189 | allow_any_instance_of(ActiveAdmin::Inputs::Filters::SelectInput).to receive(:input_html_options).and_return(base_options)
190 | end
191 |
192 | let(:base_options) { { base_option: 1 } }
193 | let(:data) { { search_fields: [:name, :email] } }
194 |
195 | it do
196 | expect(subject).to include(base_options)
197 | expect(subject).to include('data-limit' => filter.collection_limit)
198 | expect(subject).to include('data-value-field' => filter.value_field)
199 | expect(subject).to include('data-search-fields' => filter.search_fields)
200 | expect(subject).to include('data-ordering' => filter.ordering)
201 | expect(subject).to include('data-ransack' => filter.ransack)
202 | expect(subject).to include('data-selected-value' => filter.selected_value)
203 | expect(subject).to include('data-url' => filter.url)
204 | end
205 | end
206 |
207 | context 'recrods in DB more than limit' do
208 | let(:limit) { described_class::DEFAULT_LIMIT }
209 | let!(:records) { (limit + 1).times { |i| Record.create!(name: "name-#{i}", email: "email-#{i}") } }
210 |
211 | describe '#pluck_column' do
212 | subject { filter.pluck_column }
213 |
214 | before do
215 | allow(filter).to receive(:klass).and_return(Record)
216 | end
217 |
218 | let(:method) { :name }
219 |
220 | it { expect(subject.count).to eq limit }
221 | end
222 |
223 | describe '#collection_from_association' do
224 | subject { filter.collection_from_association }
225 |
226 | before do
227 | allow_any_instance_of(ActiveAdmin::Inputs::Filters::SelectInput).to receive(:collection_from_association).and_return(Record.all)
228 | end
229 |
230 | it { expect(subject.count).to eq limit }
231 | end
232 | end
233 | end
--------------------------------------------------------------------------------
/spec/dummy/README.rdoc:
--------------------------------------------------------------------------------
1 | == README
2 |
3 | This README would normally document whatever steps are necessary to get the
4 | application up and running.
5 |
6 | Things you may want to cover:
7 |
8 | * Ruby version
9 |
10 | * System dependencies
11 |
12 | * Configuration
13 |
14 | * Database creation
15 |
16 | * Database initialization
17 |
18 | * How to run the test suite
19 |
20 | * Services (job queues, cache servers, search engines, etc.)
21 |
22 | * Deployment instructions
23 |
24 | * ...
25 |
26 |
27 | Please feel free to use a different markup language if you do not plan to run
28 | rake doc:app.
29 |
--------------------------------------------------------------------------------
/spec/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/admin/categories.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.register Category do
2 | include ActiveAdmin::AjaxFilter
3 |
4 | permit_params :id, :name
5 | config.sort_order = 'id_asc'
6 | config.per_page = 3
7 | end
--------------------------------------------------------------------------------
/spec/dummy/app/admin/dashboard.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.register_page 'Dashboard' do
2 | menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
3 |
4 | content title: proc { I18n.t('active_admin.dashboard') } do
5 | div class: 'blank_slate_container', id: 'dashboard_default_message' do
6 | span class: 'blank_slate' do
7 | span I18n.t('active_admin.dashboard_welcome.welcome')
8 | small I18n.t('active_admin.dashboard_welcome.call_to_action')
9 | end
10 | end
11 |
12 | # Here is an example of a simple dashboard with columns and panels.
13 | #
14 | # columns do
15 | # column do
16 | # panel "Recent Posts" do
17 | # ul do
18 | # Post.recent(5).map do |post|
19 | # li link_to(post.title, admin_post_path(post))
20 | # end
21 | # end
22 | # end
23 | # end
24 |
25 | # column do
26 | # panel "Info" do
27 | # para "Welcome to ActiveAdmin."
28 | # end
29 | # end
30 | # end
31 | end # content
32 | end
33 |
--------------------------------------------------------------------------------
/spec/dummy/app/admin/items.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.register Item do
2 | permit_params :id, :name, :subcategory_id, tag_ids: []
3 | config.sort_order = 'id_asc'
4 |
5 | form do |f|
6 | f.semantic_errors(*f.object.errors.attribute_names)
7 |
8 | f.inputs do
9 | f.input :name
10 |
11 | f.input :subcategory, as: :ajax_select, data: {
12 | search_fields: [:name],
13 | url: '/admin/subcategories/filter',
14 | limit: Subcategory::AJAX_LIMIT
15 | }
16 |
17 | f.input :tags, as: :ajax_select, data: {
18 | search_fields: ['name'],
19 | url: '/admin/tags/filter'
20 | }
21 | end
22 |
23 |
24 | f.actions
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/spec/dummy/app/admin/subcategories.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.register Subcategory do
2 | include ActiveAdmin::AjaxFilter
3 | decorate_with SubcategoryDecorator.name
4 |
5 | permit_params :id, :name, :category_id
6 | config.sort_order = 'id_asc'
7 | config.per_page = 3
8 | end
--------------------------------------------------------------------------------
/spec/dummy/app/admin/tags.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.register Tag do
2 | include ActiveAdmin::AjaxFilter
3 |
4 | permit_params :id, :name, :subcategory_id
5 | config.sort_order = 'id_asc'
6 |
7 | form do |f|
8 | f.semantic_errors(*f.object.errors.attribute_names)
9 |
10 | f.inputs do
11 | f.input :name
12 | f.input :subcategory, as: :ajax_select, data: {
13 | search_fields: ['category.name'],
14 | ordering: 'name ASC',
15 | url: '/admin/subcategories/filter',
16 | limit: Subcategory::AJAX_LIMIT
17 | }
18 | end
19 |
20 | f.actions
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../javascripts .js
3 | //= link_directory ../stylesheets .css
4 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/holyketzer/activeadmin-ajax_filter/5c633426a15ab4828e7736ee248da7d7e24f3442/spec/dummy/app/assets/images/.keep
--------------------------------------------------------------------------------
/spec/dummy/app/assets/javascripts/active_admin.js.coffee:
--------------------------------------------------------------------------------
1 | #= require active_admin/base
2 | #= require selectize
3 | #= require activeadmin-ajax_filter
--------------------------------------------------------------------------------
/spec/dummy/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require_tree .
14 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/stylesheets/active_admin.scss:
--------------------------------------------------------------------------------
1 | @import "selectize";
2 | @import "selectize.default";
3 | @import "activeadmin-ajax_filter";
4 |
5 | @import "active_admin/mixins";
6 | @import "active_admin/base";
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 | end
6 |
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/holyketzer/activeadmin-ajax_filter/5c633426a15ab4828e7736ee248da7d7e24f3442/spec/dummy/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/spec/dummy/app/decorators/subcategory_decorator.rb:
--------------------------------------------------------------------------------
1 | require 'draper'
2 |
3 | class SubcategoryDecorator < Draper::Decorator
4 | delegate_all
5 | end
6 |
--------------------------------------------------------------------------------
/spec/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/spec/dummy/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/holyketzer/activeadmin-ajax_filter/5c633426a15ab4828e7736ee248da7d7e24f3442/spec/dummy/app/mailers/.keep
--------------------------------------------------------------------------------
/spec/dummy/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/holyketzer/activeadmin-ajax_filter/5c633426a15ab4828e7736ee248da7d7e24f3442/spec/dummy/app/models/.keep
--------------------------------------------------------------------------------
/spec/dummy/app/models/category.rb:
--------------------------------------------------------------------------------
1 | class Category < ActiveRecord::Base
2 | validates :name, presence: true
3 |
4 | has_many :subcategories
5 | has_many :items, through: :subcategories
6 | end
--------------------------------------------------------------------------------
/spec/dummy/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/holyketzer/activeadmin-ajax_filter/5c633426a15ab4828e7736ee248da7d7e24f3442/spec/dummy/app/models/concerns/.keep
--------------------------------------------------------------------------------
/spec/dummy/app/models/item.rb:
--------------------------------------------------------------------------------
1 | class Item < ActiveRecord::Base
2 | validates :name, presence: true
3 |
4 | belongs_to :subcategory
5 | has_and_belongs_to_many :tags
6 | end
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/models/subcategory.rb:
--------------------------------------------------------------------------------
1 | class Subcategory < ActiveRecord::Base
2 | AJAX_LIMIT = 3
3 |
4 | validates :name, presence: true
5 |
6 | belongs_to :category
7 | has_many :items
8 | end
9 |
--------------------------------------------------------------------------------
/spec/dummy/app/models/tag.rb:
--------------------------------------------------------------------------------
1 | class Tag < ActiveRecord::Base
2 | validates :name, presence: true
3 |
4 | belongs_to :subcategory
5 | has_and_belongs_to_many :items
6 | end
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dummy
5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/spec/dummy/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path("../config/application", __dir__)
3 | require_relative "../config/boot"
4 | require "rails/commands"
5 |
--------------------------------------------------------------------------------
/spec/dummy/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative "../config/boot"
3 | require "rake"
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/spec/dummy/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require "fileutils"
3 |
4 | # path to your application root.
5 | APP_ROOT = File.expand_path("..", __dir__)
6 |
7 | def system!(*args)
8 | system(*args) || abort("\n== Command #{args} failed ==")
9 | end
10 |
11 | FileUtils.chdir APP_ROOT do
12 | # This script is a way to set up or update your development environment automatically.
13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14 | # Add necessary setup steps to this file.
15 |
16 | puts "== Installing dependencies =="
17 | system! "gem install bundler --conservative"
18 | system("bundle check") || system!("bundle install")
19 |
20 | # puts "\n== Copying sample files =="
21 | # unless File.exist?("config/database.yml")
22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23 | # end
24 |
25 | puts "\n== Preparing database =="
26 | system! "bin/rails db:prepare"
27 |
28 | puts "\n== Removing old logs and tempfiles =="
29 | system! "bin/rails log:clear tmp:clear"
30 |
31 | puts "\n== Restarting application server =="
32 | system! "bin/rails restart"
33 | end
34 |
--------------------------------------------------------------------------------
/spec/dummy/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/spec/dummy/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative "boot"
2 |
3 | require "rails/all"
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module Dummy
10 | class Application < Rails::Application
11 | # Initialize configuration defaults for originally generated Rails version.
12 | config.load_defaults 7.0
13 |
14 | # Configuration for the application, engines, and railties goes here.
15 | #
16 | # These settings can be overridden in specific environments using the files
17 | # in config/environments, which are processed later.
18 | #
19 | # config.time_zone = "Central Time (US & Canada)"
20 | # config.eager_load_paths << Rails.root.join("extras")
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/spec/dummy/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
2 |
3 | require "bundler/setup" # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/spec/dummy/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: test
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: dummy_production
11 |
--------------------------------------------------------------------------------
/spec/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/spec/dummy/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative "application"
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # In the development environment your application's code is reloaded any time
7 | # it changes. This slows down response time but is perfect for development
8 | # since you don't have to restart the web server when you make code changes.
9 | config.cache_classes = false
10 |
11 | # Do not eager load code on boot.
12 | config.eager_load = false
13 |
14 | # Show full error reports.
15 | config.consider_all_requests_local = true
16 |
17 | # Enable server timing
18 | config.server_timing = true
19 |
20 | # Enable/disable caching. By default caching is disabled.
21 | # Run rails dev:cache to toggle caching.
22 | if Rails.root.join("tmp/caching-dev.txt").exist?
23 | config.action_controller.perform_caching = true
24 | config.action_controller.enable_fragment_cache_logging = true
25 |
26 | config.cache_store = :memory_store
27 | config.public_file_server.headers = {
28 | "Cache-Control" => "public, max-age=#{2.days.to_i}"
29 | }
30 | else
31 | config.action_controller.perform_caching = false
32 |
33 | config.cache_store = :null_store
34 | end
35 |
36 | # Store uploaded files on the local file system (see config/storage.yml for options).
37 | config.active_storage.service = :local
38 |
39 | # Don't care if the mailer can't send.
40 | config.action_mailer.raise_delivery_errors = false
41 |
42 | config.action_mailer.perform_caching = false
43 |
44 | # Print deprecation notices to the Rails logger.
45 | config.active_support.deprecation = :log
46 |
47 | # Raise exceptions for disallowed deprecations.
48 | config.active_support.disallowed_deprecation = :raise
49 |
50 | # Tell Active Support which deprecation messages to disallow.
51 | config.active_support.disallowed_deprecation_warnings = []
52 |
53 | # Raise an error on page load if there are pending migrations.
54 | config.active_record.migration_error = :page_load
55 |
56 | # Highlight code that triggered database queries in logs.
57 | config.active_record.verbose_query_logs = true
58 |
59 | # Suppress logger output for asset requests.
60 | # config.assets.quiet = true
61 |
62 | # Raises error for missing translations.
63 | # config.i18n.raise_on_missing_translations = true
64 |
65 | # Annotate rendered view with file names.
66 | # config.action_view.annotate_rendered_view_with_filenames = true
67 |
68 | # Uncomment if you wish to allow Action Cable access from any origin.
69 | # config.action_cable.disable_request_forgery_protection = true
70 | end
71 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # Code is not reloaded between requests.
7 | config.cache_classes = true
8 |
9 | # Eager load code on boot. This eager loads most of Rails and
10 | # your application in memory, allowing both threaded web servers
11 | # and those relying on copy on write to perform better.
12 | # Rake tasks automatically ignore this option for performance.
13 | config.eager_load = true
14 |
15 | # Full error reports are disabled and caching is turned on.
16 | config.consider_all_requests_local = false
17 | config.action_controller.perform_caching = true
18 |
19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21 | # config.require_master_key = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
26 |
27 | # Compress CSS using a preprocessor.
28 | # config.assets.css_compressor = :sass
29 |
30 | # Do not fallback to assets pipeline if a precompiled asset is missed.
31 | # config.assets.compile = false
32 |
33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
34 | # config.asset_host = "http://assets.example.com"
35 |
36 | # Specifies the header that your server uses for sending files.
37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
39 |
40 | # Store uploaded files on the local file system (see config/storage.yml for options).
41 | config.active_storage.service = :local
42 |
43 | # Mount Action Cable outside main process or domain.
44 | # config.action_cable.mount_path = nil
45 | # config.action_cable.url = "wss://example.com/cable"
46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
47 |
48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
49 | # config.force_ssl = true
50 |
51 | # Include generic and useful information about system operation, but avoid logging too much
52 | # information to avoid inadvertent exposure of personally identifiable information (PII).
53 | config.log_level = :info
54 |
55 | # Prepend all log lines with the following tags.
56 | config.log_tags = [ :request_id ]
57 |
58 | # Use a different cache store in production.
59 | # config.cache_store = :mem_cache_store
60 |
61 | # Use a real queuing backend for Active Job (and separate queues per environment).
62 | # config.active_job.queue_adapter = :resque
63 | # config.active_job.queue_name_prefix = "dummy_production"
64 |
65 | config.action_mailer.perform_caching = false
66 |
67 | # Ignore bad email addresses and do not raise email delivery errors.
68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
69 | # config.action_mailer.raise_delivery_errors = false
70 |
71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
72 | # the I18n.default_locale when a translation cannot be found).
73 | config.i18n.fallbacks = true
74 |
75 | # Don't log any deprecations.
76 | config.active_support.report_deprecations = false
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = ::Logger::Formatter.new
80 |
81 | # Use a different logger for distributed setups.
82 | # require "syslog/logger"
83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
84 |
85 | if ENV["RAILS_LOG_TO_STDOUT"].present?
86 | logger = ActiveSupport::Logger.new(STDOUT)
87 | logger.formatter = config.log_formatter
88 | config.logger = ActiveSupport::TaggedLogging.new(logger)
89 | end
90 |
91 | # Do not dump schema after migrations.
92 | config.active_record.dump_schema_after_migration = false
93 | end
94 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | # The test environment is used exclusively to run your application's
4 | # test suite. You never need to work with it otherwise. Remember that
5 | # your test database is "scratch space" for the test suite and is wiped
6 | # and recreated between test runs. Don't rely on the data there!
7 |
8 | Rails.application.configure do
9 | # Settings specified here will take precedence over those in config/application.rb.
10 |
11 | # Turn false under Spring and add config.action_view.cache_template_loading = true.
12 | config.cache_classes = true
13 |
14 | # Eager loading loads your whole application. When running a single test locally,
15 | # this probably isn't necessary. It's a good idea to do in a continuous integration
16 | # system, or in some way before deploying your code.
17 | config.eager_load = ENV["CI"].present?
18 |
19 | # Configure public file server for tests with Cache-Control for performance.
20 | config.public_file_server.enabled = true
21 | config.public_file_server.headers = {
22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}"
23 | }
24 |
25 | # Show full error reports and disable caching.
26 | config.consider_all_requests_local = true
27 | config.action_controller.perform_caching = false
28 | config.cache_store = :null_store
29 |
30 | # Raise exceptions instead of rendering exception templates.
31 | config.action_dispatch.show_exceptions = false
32 |
33 | # Disable request forgery protection in test environment.
34 | config.action_controller.allow_forgery_protection = false
35 |
36 | # Store uploaded files on the local file system in a temporary directory.
37 | config.active_storage.service = :test
38 |
39 | config.action_mailer.perform_caching = false
40 |
41 | # Tell Action Mailer not to deliver emails to the real world.
42 | # The :test delivery method accumulates sent emails in the
43 | # ActionMailer::Base.deliveries array.
44 | config.action_mailer.delivery_method = :test
45 |
46 | # Print deprecation notices to the stderr.
47 | config.active_support.deprecation = :stderr
48 |
49 | # Raise exceptions for disallowed deprecations.
50 | config.active_support.disallowed_deprecation = :raise
51 |
52 | # Tell Active Support which deprecation messages to disallow.
53 | config.active_support.disallowed_deprecation_warnings = []
54 |
55 | # Raises error for missing translations.
56 | # config.i18n.raise_on_missing_translations = true
57 |
58 | # Annotate rendered view with file names.
59 | # config.action_view.annotate_rendered_view_with_filenames = true
60 | end
61 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/active_admin.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.setup do |config|
2 | # == Site Title
3 | #
4 | # Set the title that is displayed on the main layout
5 | # for each of the active admin pages.
6 | #
7 | config.site_title = 'Dummy'
8 |
9 | # Set the link url for the title. For example, to take
10 | # users to your main site. Defaults to no link.
11 | #
12 | # config.site_title_link = "/"
13 |
14 | # Set an optional image to be displayed for the header
15 | # instead of a string (overrides :site_title)
16 | #
17 | # Note: Aim for an image that's 21px high so it fits in the header.
18 | #
19 | # config.site_title_image = "logo.png"
20 |
21 | # == Default Namespace
22 | #
23 | # Set the default namespace each administration resource
24 | # will be added to.
25 | #
26 | # eg:
27 | # config.default_namespace = :hello_world
28 | #
29 | # This will create resources in the HelloWorld module and
30 | # will namespace routes to /hello_world/*
31 | #
32 | # To set no namespace by default, use:
33 | # config.default_namespace = false
34 | #
35 | # Default:
36 | # config.default_namespace = :admin
37 | #
38 | # You can customize the settings for each namespace by using
39 | # a namespace block. For example, to change the site title
40 | # within a namespace:
41 | #
42 | # config.namespace :admin do |admin|
43 | # admin.site_title = "Custom Admin Title"
44 | # end
45 | #
46 | # This will ONLY change the title for the admin section. Other
47 | # namespaces will continue to use the main "site_title" configuration.
48 |
49 | # == User Authentication
50 | #
51 | # Active Admin will automatically call an authentication
52 | # method in a before filter of all controller actions to
53 | # ensure that there is a currently logged in admin user.
54 | #
55 | # This setting changes the method which Active Admin calls
56 | # within the application controller.
57 | # config.authentication_method = :authenticate_admin_user!
58 |
59 | # == User Authorization
60 | #
61 | # Active Admin will automatically call an authorization
62 | # method in a before filter of all controller actions to
63 | # ensure that there is a user with proper rights. You can use
64 | # CanCanAdapter or make your own. Please refer to documentation.
65 | # config.authorization_adapter = ActiveAdmin::CanCanAdapter
66 |
67 | # In case you prefer Pundit over other solutions you can here pass
68 | # the name of default policy class. This policy will be used in every
69 | # case when Pundit is unable to find suitable policy.
70 | # config.pundit_default_policy = "MyDefaultPunditPolicy"
71 |
72 | # You can customize your CanCan Ability class name here.
73 | # config.cancan_ability_class = "Ability"
74 |
75 | # You can specify a method to be called on unauthorized access.
76 | # This is necessary in order to prevent a redirect loop which happens
77 | # because, by default, user gets redirected to Dashboard. If user
78 | # doesn't have access to Dashboard, he'll end up in a redirect loop.
79 | # Method provided here should be defined in application_controller.rb.
80 | # config.on_unauthorized_access = :access_denied
81 |
82 | # == Current User
83 | #
84 | # Active Admin will associate actions with the current
85 | # user performing them.
86 | #
87 | # This setting changes the method which Active Admin calls
88 | # (within the application controller) to return the currently logged in user.
89 | # config.current_user_method = :current_admin_user
90 |
91 | # == Logging Out
92 | #
93 | # Active Admin displays a logout link on each screen. These
94 | # settings configure the location and method used for the link.
95 | #
96 | # This setting changes the path where the link points to. If it's
97 | # a string, the strings is used as the path. If it's a Symbol, we
98 | # will call the method to return the path.
99 | #
100 | # Default:
101 | config.logout_link_path = :destroy_admin_user_session_path
102 |
103 | # This setting changes the http method used when rendering the
104 | # link. For example :get, :delete, :put, etc..
105 | #
106 | # Default:
107 | # config.logout_link_method = :get
108 |
109 | # == Root
110 | #
111 | # Set the action to call for the root path. You can set different
112 | # roots for each namespace.
113 | #
114 | # Default:
115 | # config.root_to = 'dashboard#index'
116 |
117 | # == Admin Comments
118 | #
119 | # This allows your users to comment on any resource registered with Active Admin.
120 | #
121 | # You can completely disable comments:
122 | # config.comments = false
123 | #
124 | # You can disable the menu item for the comments index page:
125 | # config.show_comments_in_menu = false
126 | #
127 | # You can change the name under which comments are registered:
128 | # config.comments_registration_name = 'AdminComment'
129 | #
130 | # You can change the order for the comments and you can change the column
131 | # to be used for ordering
132 | # config.comments_order = 'created_at ASC'
133 |
134 | # == Batch Actions
135 | #
136 | # Enable and disable Batch Actions
137 | #
138 | config.batch_actions = true
139 |
140 | # == Controller Filters
141 | #
142 | # You can add before, after and around filters to all of your
143 | # Active Admin resources and pages from here.
144 | #
145 | # config.before_filter :do_something_awesome
146 |
147 | # == Localize Date/Time Format
148 | #
149 | # Set the localize format to display dates and times.
150 | # To understand how to localize your app with I18n, read more at
151 | # https://github.com/svenfuchs/i18n/blob/master/lib%2Fi18n%2Fbackend%2Fbase.rb#L52
152 | #
153 | # config.localize_format = :long
154 |
155 | # == Setting a Favicon
156 | #
157 | # config.favicon = 'favicon.ico'
158 |
159 | # == Meta Tags
160 | #
161 | # Add additional meta tags to the head element of active admin pages.
162 | #
163 | # Add tags to all pages logged in users see:
164 | # config.meta_tags = { author: 'My Company' }
165 |
166 | # By default, sign up/sign in/recover password pages are excluded
167 | # from showing up in search engine results by adding a robots meta
168 | # tag. You can reset the hash of meta tags included in logged out
169 | # pages:
170 | # config.meta_tags_for_logged_out_pages = {}
171 |
172 | # == Removing Breadcrumbs
173 | #
174 | # Breadcrumbs are enabled by default. You can customize them for individual
175 | # resources or you can disable them globally from here.
176 | #
177 | # config.breadcrumb = false
178 |
179 | # == Register Stylesheets & Javascripts
180 | #
181 | # We recommend using the built in Active Admin layout and loading
182 | # up your own stylesheets / javascripts to customize the look
183 | # and feel.
184 | #
185 | # To load a stylesheet:
186 | # config.register_stylesheet 'my_stylesheet.css'
187 | #
188 | # You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
189 | # config.register_stylesheet 'my_print_stylesheet.css', media: :print
190 | #
191 | # To load a javascript file:
192 | # config.register_javascript 'my_javascript.js'
193 |
194 | # == CSV options
195 | #
196 | # Set the CSV builder separator
197 | # config.csv_options = { col_sep: ';' }
198 | #
199 | # Force the use of quotes
200 | # config.csv_options = { force_quotes: true }
201 |
202 | # == Menu System
203 | #
204 | # You can add a navigation menu to be used in your application, or configure a provided menu
205 | #
206 | # To change the default utility navigation to show a link to your website & a logout btn
207 | #
208 | # config.namespace :admin do |admin|
209 | # admin.build_menu :utility_navigation do |menu|
210 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
211 | # admin.add_logout_button_to_menu menu
212 | # end
213 | # end
214 | #
215 | # If you wanted to add a static menu item to the default menu provided:
216 | #
217 | # config.namespace :admin do |admin|
218 | # admin.build_menu :default do |menu|
219 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
220 | # end
221 | # end
222 |
223 | # == Download Links
224 | #
225 | # You can disable download links on resource listing pages,
226 | # or customize the formats shown per namespace/globally
227 | #
228 | # To disable/customize for the :admin namespace:
229 | #
230 | # config.namespace :admin do |admin|
231 | #
232 | # # Disable the links entirely
233 | # admin.download_links = false
234 | #
235 | # # Only show XML & PDF options
236 | # admin.download_links = [:xml, :pdf]
237 | #
238 | # # Enable/disable the links based on block
239 | # # (for example, with cancan)
240 | # admin.download_links = proc { can?(:view_download_links) }
241 | #
242 | # end
243 |
244 | # == Pagination
245 | #
246 | # Pagination is enabled by default for all resources.
247 | # You can control the default per page count for all resources here.
248 | #
249 | # config.default_per_page = 30
250 | #
251 | # You can control the max per page count too.
252 | #
253 | # config.max_per_page = 10_000
254 |
255 | # == Filters
256 | #
257 | # By default the index screen includes a "Filters" sidebar on the right
258 | # hand side with a filter for each attribute of the registered model.
259 | # You can enable or disable them for all resources here.
260 | #
261 | # config.filters = true
262 | end
263 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Define an application-wide content security policy.
4 | # See the Securing Rails Applications Guide for more information:
5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header
6 |
7 | # Rails.application.configure do
8 | # config.content_security_policy do |policy|
9 | # policy.default_src :self, :https
10 | # policy.font_src :self, :https, :data
11 | # policy.img_src :self, :https, :data
12 | # policy.object_src :none
13 | # policy.script_src :self, :https
14 | # policy.style_src :self, :https
15 | # # Specify URI for violation reports
16 | # # policy.report_uri "/csp-violation-report-endpoint"
17 | # end
18 | #
19 | # # Generate session nonces for permitted importmap and inline scripts
20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21 | # config.content_security_policy_nonce_directives = %w(script-src)
22 | #
23 | # # Report violations without enforcing the policy.
24 | # # config.content_security_policy_report_only = true
25 | # end
26 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of
4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
5 | # notations and behaviors.
6 | Rails.application.config.filter_parameters += [
7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
8 | ]
9 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, "\\1en"
8 | # inflect.singular /^(ox)en/i, "\\1"
9 | # inflect.irregular "person", "people"
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym "RESTful"
16 | # end
17 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/new_framework_defaults_7_0.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file eases your Rails 7.0 framework defaults upgrade.
4 | #
5 | # Uncomment each configuration one by one to switch to the new default.
6 | # Once your application is ready to run with all new defaults, you can remove
7 | # this file and set the `config.load_defaults` to `7.0`.
8 | #
9 | # Read the Guide for Upgrading Ruby on Rails for more info on each option.
10 | # https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
11 |
12 | # `button_to` view helper will render `