activeadmin-searchable_select 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adbee989dd2ce2851dce0565e4eb04e02b7d63dd164fb3bfb491f7b3840eddf9
4
- data.tar.gz: 01f9cf36616ed6ccdb22e956f6f43dfd1a3d44cf52a18f9957433b384bfe893d
3
+ metadata.gz: c6d4c7d8435c3adb952ee4da5da0956da99d127077bbcbc1ac532fe302adf6bd
4
+ data.tar.gz: 5bbf85c4d97ba8f06798705c25a44dc0e7bb78394d816cf9953b9292ed64f957
5
5
  SHA512:
6
- metadata.gz: 00ca17e82f7a964c1b50425e2d62a16a49bdb06c041879d05ad6a98e5f520b9f8a324d888b6e26299c6b994199c8e44a402c44a2e303ac1ce6c743c9a5336675
7
- data.tar.gz: da3c49a990ca32f3ae6fcbe126eaeb80d144a772a8340ed45d7e40aac5de94440e57035196223af055f69d3eb8cee1377f1fa7cc794d543ede2e4efc964ed414
6
+ metadata.gz: 8e62b205e6502858dc107a0264e51dc91b45246e6d4215ec458cc6886f451ebbc44a5f5fbdfce7c36c43ddc816896572d0e5430e91dcfbb9119c92a1afa1550d
7
+ data.tar.gz: b3af3cd5a33b0af6b88b791a758574531b1ff8e9b21acc153c0b81156c66807b3091027c3058809a8681d0c2073ad6ba526461d835dea6f4661b9bc501bcc274
@@ -1,27 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Version 1.0.2
3
+ ### Version 1.1.0
4
4
 
5
- 2018-02-08
5
+ 2019-01-18
6
6
 
7
- [Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/v1.0.1...v1.0.2)
7
+ [Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/1-0-stable...v1.1.0)
8
8
 
9
- - Use the namespace for the active admin resource.
10
- ([#4](https://github.com/codevise/activeadmin-searchable_select/pull/4))
11
- - Make end to end specs less brittle
12
- ([#5](https://github.com/codevise/activeadmin-searchable_select/pull/5))
9
+ - Allow for multi-select filters
10
+ ([#11](https://github.com/codevise/activeadmin-searchable_select/pull/11))
13
11
 
14
- ### Version 1.0.1
15
-
16
- 2018-01-19
17
-
18
- [Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/v1.0.0...v1.0.1)
19
-
20
- - Use zero based pagination parameter
21
- ([#2](https://github.com/codevise/activeadmin-searchable_select/pull/2))
22
-
23
- ### Version 1.0.0
24
-
25
- 2017-10-23
26
-
27
- - Initial release.
12
+ See
13
+ [1-0-stable branch](https://github.com/codevise/activeadmin-searchable_select/blob/1-0-stable/CHANGELOG.md)
14
+ for previous changes.
data/README.md CHANGED
@@ -50,6 +50,15 @@ This also works for filters:
50
50
  end
51
51
  ```
52
52
 
53
+ By default, you can only select one at a time for a filter. You can
54
+ specify a multi-select with:
55
+
56
+ ```ruby
57
+ ActiveAdmin.register Product do
58
+ filter(:category, as: :searchable_select, multiple: true)
59
+ end
60
+ ```
61
+
53
62
  ### Fetching Options via Ajax
54
63
 
55
64
  For large collections, rendering the whole set of options can be to
@@ -57,23 +57,23 @@ module ActiveAdmin
57
57
  end
58
58
 
59
59
  def selected_value_collection
60
- [selected_value_option].compact
61
- end
62
-
63
- def selected_value_option
64
- option_for_record(selected_record) if selected_record
60
+ selected_records.collect { |s| option_for_record(s) }
65
61
  end
66
62
 
67
63
  def option_for_record(record)
68
64
  [option_collection.display_text(record), record.id]
69
65
  end
70
66
 
71
- def selected_record
72
- @selected_record ||=
73
- selected_value && option_collection_scope.find_by_id(selected_value)
67
+ def selected_records
68
+ @selected_records ||=
69
+ if selected_values
70
+ option_collection_scope.where(id: selected_values)
71
+ else
72
+ []
73
+ end
74
74
  end
75
75
 
76
- def selected_value
76
+ def selected_values
77
77
  @object.send(input_name) if @object
78
78
  end
79
79
 
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SearchableSelect
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
@@ -188,4 +188,54 @@ RSpec.describe 'filter input', type: :request do
188
188
  text: 'Travel')
189
189
  end
190
190
  end
191
+
192
+ describe 'with the multiple option set to true' do
193
+ before(:each) do
194
+ ActiveAdminHelpers.setup do
195
+ ActiveAdmin.register(Category) do
196
+ searchable_select_options(scope: Category, text_attribute: :name)
197
+ end
198
+
199
+ ActiveAdmin.register(Post) do
200
+ filter(:category,
201
+ as: :searchable_select,
202
+ ajax: true,
203
+ multiple: true)
204
+ end
205
+ end
206
+ end
207
+
208
+ it 'renders select input with searchable-select-input css class and the multiple attribute' do
209
+ get '/admin/posts'
210
+
211
+ expect(response.body).to have_selector("select.searchable-select-input[multiple='multiple']")
212
+ end
213
+
214
+ it 'does not render options statically' do
215
+ Category.create!(name: 'Travel')
216
+
217
+ get '/admin/posts'
218
+
219
+ expect(response.body).not_to have_selector('.searchable-select-input option',
220
+ text: 'Travel')
221
+ end
222
+
223
+ it 'sets data-ajax-url attribute' do
224
+ get '/admin/posts'
225
+
226
+ expect(response.body).to have_selector('.searchable-select-input[data-ajax-url]')
227
+ end
228
+
229
+ it 'renders the filter for multiple values selected' do
230
+ category1 = Category.create!(name: 'Travel')
231
+ category2 = Category.create!(name: 'Leisure')
232
+
233
+ get "/admin/posts?q[category_id_in][]=#{category1.id}&q[category_id_in][]=#{category2.id}"
234
+
235
+ expect(response.body).to have_selector('.searchable-select-input option[selected]',
236
+ text: 'Travel')
237
+ expect(response.body).to have_selector('.searchable-select-input option[selected]',
238
+ text: 'Leisure')
239
+ end
240
+ end
191
241
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-searchable_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codevise Solutions Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler