File tree Expand file tree Collapse file tree
lib/capybara/active_admin/selectors Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def table_header_selector
3232 def table_cell_selector ( column = nil )
3333 return 'td.col' if column . nil?
3434
35- column = column . to_s . gsub ( ' ' , '_' ) . downcase
35+ column = column . to_s . downcase . gsub ( /[^a-z0-9 \s ]/ , '' ) . gsub ( / \s +/ , '_' ) . squeeze ( '_' )
3636 "td.col.col-#{ column } "
3737 end
3838
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . describe Capybara ::ActiveAdmin ::Selectors ::Table do
4+ subject ( :helper ) do
5+ Class . new { include Capybara ::ActiveAdmin ::Selectors ::Table } . new
6+ end
7+
8+ describe '#table_cell_selector' do
9+ it 'returns generic selector when column is nil' do
10+ expect ( helper . table_cell_selector ) . to eq ( 'td.col' )
11+ end
12+
13+ it 'converts spaces to underscores' do
14+ expect ( helper . table_cell_selector ( 'Full Name' ) ) . to eq ( 'td.col.col-full_name' )
15+ end
16+
17+ it 'downcases the column name' do
18+ expect ( helper . table_cell_selector ( 'ID' ) ) . to eq ( 'td.col.col-id' )
19+ end
20+
21+ it 'strips slashes from column name' do
22+ expect ( helper . table_cell_selector ( 'Country / Region' ) ) . to eq ( 'td.col.col-country_region' )
23+ end
24+
25+ it 'strips other special characters from column name' do
26+ expect ( helper . table_cell_selector ( 'Price (USD)' ) ) . to eq ( 'td.col.col-price_usd' )
27+ end
28+ end
29+ end
You can’t perform that action at this time.
0 commit comments