Skip to content

Commit 9b9500c

Browse files
authored
Merge pull request #364 from platanus/selec2-tags-fix
fix(select): tags option not working with active_admin_form_for
2 parents 7fc8d77 + 862b47d commit 9b9500c

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
### ### 1.8.2
5+
### Unreleased
6+
7+
##### Fixed
8+
9+
* `tags` option not working with `active_admin_form_for` [#364](https://github.com/platanus/activeadmin_addons/pull/364)
10+
11+
### 1.8.2
612

713
##### Fixed
814
* Removes vendor directory from build to reduce gem size
915

10-
### 1.8.0
16+
### 1.8.0 and 1.8.1
17+
18+
Versions 1.8.0 and 1.8.1 were yanked by what was described in version 1.8.2. Sorry for the inconvenience.
19+
Related issues:
20+
- https://github.com/platanus/activeadmin_addons/issues/357
21+
- https://github.com/platanus/activeadmin_addons/issues/362
1122

1223
##### Added
1324
* Added date time picker filter [#333](https://github.com/platanus/activeadmin_addons/pull/333)

app/inputs/active_admin/inputs/select_input.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ def input_html_options
44
end
55

66
def raw_collection
7-
field_value = object.send(method)
7+
field_value = begin
8+
object.send(method)
9+
rescue NoMethodError
10+
nil
11+
end
812

913
@options[:tags].present? && field_value.present? ? (super.to_a << field_value).uniq : super
1014
end

spec/features/inputs/select2_spec.rb

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,55 @@
2525
let(:invoice) { create_invoice }
2626
let(:selection) { '#444' }
2727

28-
before do
29-
register_form(Invoice) do |f|
30-
f.input :number, as: :select, collection: ["#111", "#222", "#333"], tags: true
28+
context "with AA form" do
29+
before do
30+
register_form(Invoice) do |f|
31+
f.input :number, as: :select, collection: ["#111", "#222", "#333"], tags: true
32+
end
3133
end
32-
end
3334

34-
context 'when entering option not in collection' do
35-
before { visit edit_admin_invoice_path(invoice) }
35+
context 'when entering option not in collection' do
36+
before { visit edit_admin_invoice_path(invoice) }
3637

37-
it "adds new option", js: true do
38-
expect_select2_options_count_to_eq(4)
39-
fill_select2_input(selection)
40-
expect_select2_options_count_to_eq(5)
38+
it "adds new option", js: true do
39+
expect_select2_options_count_to_eq(4)
40+
fill_select2_input(selection)
41+
expect_select2_options_count_to_eq(5)
42+
end
43+
end
44+
45+
context 'when initial value is not in inputs collection' do
46+
before do
47+
invoice.update!(number: selection)
48+
visit edit_admin_invoice_path(invoice)
49+
end
50+
51+
it "includes initial value as option", js: true do
52+
expect_select2_options_count_to_eq(5)
53+
end
4154
end
4255
end
4356

44-
context 'when initial value is not in inputs collection' do
57+
context "with custom form" do
4558
before do
46-
invoice.update!(number: selection)
47-
visit edit_admin_invoice_path(invoice)
59+
register_page(Invoice) do
60+
config.filters = false
61+
sidebar 'Filters' do
62+
active_admin_form_for(:q) do |f|
63+
f.input :number, as: :select, collection: ["#111", "#222", "#333"], tags: true
64+
end
65+
end
66+
end
4867
end
4968

50-
it "includes initial value as option", js: true do
51-
expect_select2_options_count_to_eq(5)
69+
context 'when entering option not in collection' do
70+
before { visit admin_invoices_path }
71+
72+
it "adds new option", js: true do
73+
expect_select2_options_count_to_eq(4)
74+
fill_select2_input(selection)
75+
expect_select2_options_count_to_eq(5)
76+
end
5277
end
5378
end
5479
end

0 commit comments

Comments
 (0)