Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/capybara/active_admin/selectors/attributes_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def attributes_table_selector(model: nil, id: nil)
def attributes_row_selector(label = nil)
return 'tr.row > td' if label.nil?

label = label.to_s.gsub(' ', '_').downcase
label = label.to_s.gsub(/[\s\/]/, '_').downcase
"tr.row.row-#{label} > td"
end
end
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/selectors/attributes_table_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

RSpec.describe Capybara::ActiveAdmin::Selectors::AttributesTable do
subject(:helper) do
Class.new { include Capybara::ActiveAdmin::Selectors::AttributesTable }.new
end

describe '#attributes_row_selector' do
it 'returns a generic row selector when no label given' do
expect(helper.attributes_row_selector).to eq('tr.row > td')
end

it 'builds selector from a simple label' do
expect(helper.attributes_row_selector('Full name')).to eq('tr.row.row-full_name > td')
end

it 'replaces slash with underscore to match ActiveAdmin class generation' do
expect(helper.attributes_row_selector('USA/UAH')).to eq('tr.row.row-usa_uah > td')
end

it 'replaces spaces and slashes with underscores' do
expect(helper.attributes_row_selector('A/B C')).to eq('tr.row.row-a_b_c > td')
end
end
end
Loading