Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 5ad4a1c

Browse files
committed
Add minimum specs
1 parent e81ea34 commit 5ad4a1c

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

spec/dummy/app/admin/posts.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
# frozen_string_literal: true
22

33
ActiveAdmin.register Post do
4+
permit_params :author_id, :title, :description, :category, :dt, :position, :published, tag_ids: []
5+
6+
index do
7+
selectable_column
8+
id_column
9+
column :title
10+
column :author
11+
column :published
12+
column :created_at
13+
actions
14+
end
15+
16+
show do
17+
attributes_table do
18+
row :author
19+
row :title
20+
row :description
21+
row :category
22+
row :dt
23+
row :position
24+
row :published
25+
row :tags
26+
row :created_at
27+
row :updated_at
28+
end
29+
active_admin_comments
30+
end
31+
32+
form do |f|
33+
f.inputs 'Post' do
34+
f.input :author, as: :selectize
35+
f.input :title
36+
f.input :description
37+
f.input :category
38+
f.input :dt
39+
f.input :position
40+
f.input :published
41+
end
42+
43+
f.inputs 'Tags' do
44+
f.input :tags, as: :selectize
45+
end
46+
47+
f.actions
48+
end
449
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
//= require active_admin/base
2+
3+
//= require activeadmin/selectize/selectize
4+
//= require activeadmin/selectize_input

spec/dummy/app/assets/stylesheets/active_admin.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// $sidebar-width: 242px;
99

1010
// Active Admin's got SASS!
11-
@import "active_admin/mixins";
12-
@import "active_admin/base";
11+
@import 'active_admin/mixins';
12+
@import 'active_admin/base';
13+
14+
@import 'activeadmin/selectize_input';
1315

1416
// Overriding any non-variable SASS must be done after the fact.
1517
// For example, to change the default status-tag color:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe 'Selectize inputs', type: :system do
4+
let(:authors) do
5+
3.times.map do |i|
6+
Author.create!(email: "some_email_#{i}@example.com", name: "John #{i}", age: 30 + i * 3)
7+
end
8+
end
9+
let(:post) { Post.create!(title: 'Test', author: authors.last) }
10+
let(:tags) do
11+
3.times.map do |i|
12+
Tag.create!(name: "A tag #{i}")
13+
end
14+
end
15+
16+
before do
17+
post.tags << tags.last
18+
end
19+
20+
after do
21+
post.destroy
22+
authors.each(&:destroy)
23+
tags.each(&:destroy)
24+
end
25+
26+
context 'with a single value selectize input' do
27+
let(:hidden_input) { '#post_author_input [data-selectize-input]' }
28+
let(:selectize_control) { '#post_author_input .selectize-control.single' }
29+
let(:selectize_input) { '#post_author_input .selectize-input' }
30+
31+
it 'includes the hidden select and the selectize-input element' do
32+
visit "/admin/posts/#{post.id}/edit"
33+
34+
expect(page).to have_select('post[author_id]', visible: false, selected: authors.last.name)
35+
expect(page).to have_css(selectize_input)
36+
end
37+
38+
it 'updates the entity association' do
39+
visit "/admin/posts/#{post.id}/edit"
40+
41+
find(selectize_input).click
42+
find("#{selectize_control} .selectize-dropdown-content", text: 'John 1').click
43+
find('[type="submit"]').click
44+
expect(page).to have_content('was successfully updated')
45+
expect(post.reload.author).to eq(authors.find { |item| item.name == 'John 1' })
46+
end
47+
end
48+
49+
context 'with a multiple values selectize input' do
50+
let(:hidden_input) { '#post_tags_input [data-selectize-input]' }
51+
let(:selectize_control) { '#post_tags_input .selectize-control.multi' }
52+
let(:selectize_input) { '#post_tags_input .selectize-input' }
53+
54+
it 'includes the hidden select and the selectize-input element' do
55+
visit "/admin/posts/#{post.id}/edit"
56+
57+
expect(page).to have_select('post[tag_ids][]', visible: false, selected: tags.last.name)
58+
expect(page).to have_css(selectize_input)
59+
end
60+
61+
it 'updates the entity association' do
62+
visit "/admin/posts/#{post.id}/edit"
63+
64+
find(selectize_input).click
65+
find('#post_tags_input .option', text: 'A tag 1').click
66+
scroll_to(find('#post_submit_action'))
67+
find('[type="submit"]').click
68+
expect(page).to have_content('was successfully updated')
69+
expect(post.reload.tags).to include(tags.find { |item| item.name == 'A tag 1' })
70+
end
71+
end
72+
end

0 commit comments

Comments
 (0)