Skip to content

Commit 432c58e

Browse files
Copilotsenid231
andcommitted
Fix row class generation for labels containing slashes (e.g. USA/UAH)
Agent-Logs-Url: https://github.com/activeadmin-plugins/capybara_active_admin/sessions/9bdfb67e-494b-4593-9e0f-2b41c37fbe56 Co-authored-by: senid231 <8393857+senid231@users.noreply.github.com>
1 parent ccfc5a3 commit 432c58e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lib/capybara/active_admin/selectors/attributes_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def attributes_table_selector(model: nil, id: nil)
1818
def attributes_row_selector(label = nil)
1919
return 'tr.row > td' if label.nil?
2020

21-
label = label.to_s.gsub(' ', '_').downcase
21+
label = label.to_s.gsub(/[\s\/]/, '_').downcase
2222
"tr.row.row-#{label} > td"
2323
end
2424
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Capybara::ActiveAdmin::Selectors::AttributesTable do
4+
subject(:helper) do
5+
Class.new { include Capybara::ActiveAdmin::Selectors::AttributesTable }.new
6+
end
7+
8+
describe '#attributes_row_selector' do
9+
it 'returns a generic row selector when no label given' do
10+
expect(helper.attributes_row_selector).to eq('tr.row > td')
11+
end
12+
13+
it 'builds selector from a simple label' do
14+
expect(helper.attributes_row_selector('Full name')).to eq('tr.row.row-full_name > td')
15+
end
16+
17+
it 'replaces slash with underscore to match ActiveAdmin class generation' do
18+
expect(helper.attributes_row_selector('USA/UAH')).to eq('tr.row.row-usa_uah > td')
19+
end
20+
21+
it 'replaces spaces and slashes with underscores' do
22+
expect(helper.attributes_row_selector('A/B C')).to eq('tr.row.row-a_b_c > td')
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)