lint settings_helper

pull/10460/head
ulferts 3 years ago
parent 923b715dee
commit 36baf76bc1
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 37
      app/helpers/settings_helper.rb
  2. 2
      spec/helpers/settings_helper_spec.rb

@ -56,7 +56,7 @@ module SettingsHelper
}, },
{ {
name: 'repositories', name: 'repositories',
controller:'/admin/settings/repositories_settings', controller: '/admin/settings/repositories_settings',
label: :label_repository_plural label: :label_repository_plural
} }
] ]
@ -85,7 +85,7 @@ module SettingsHelper
hidden + hidden +
choices.map do |choice| choices.map do |choice|
setting_multiselect_choice(setting, choice, options) setting_multiselect_choice(setting, choice, options)
end.join.html_safe end.join.html_safe # rubocop:disable Rails/OutputSafety
end end
end end
@ -194,10 +194,10 @@ module SettingsHelper
private private
def wrap_field_outer(options, &block) def wrap_field_outer(options, &block)
if options[:label] != false if options[:label] == false
content_tag(:span, class: 'form--field-container', &block)
else
block.call block.call
else
content_tag(:span, class: 'form--field-container', &block)
end end
end end
@ -210,7 +210,7 @@ module SettingsHelper
hidden_field_tag("settings[#{setting}][]", '') + hidden_field_tag("settings[#{setting}][]", '') +
I18n.t("setting_#{setting}") I18n.t("setting_#{setting}")
end end
end.join.html_safe end.join.html_safe # rubocop:disable Rails/OutputSafety
end end
end end
@ -221,17 +221,21 @@ module SettingsHelper
exceptions = Array(choice[:except]).compact exceptions = Array(choice[:except]).compact
content_tag(:tr, class: 'form--matrix-row') do content_tag(:tr, class: 'form--matrix-row') do
content_tag(:td, caption, class: 'form--matrix-cell') + content_tag(:td, caption, class: 'form--matrix-cell') +
settings.map do |setting| settings_matrix_tds(settings, exceptions, value)
content_tag(:td, class: 'form--matrix-checkbox-cell') do
unless exceptions.include?(setting)
styled_check_box_tag("settings[#{setting}][]", value,
Setting.send(setting).include?(value),
disabled_setting_option(setting).merge(id: "#{setting}_#{value}"))
end
end
end.join.html_safe
end end
end.join.html_safe end.join.html_safe # rubocop:disable Rails/OutputSafety
end
def settings_matrix_tds(settings, exceptions, value)
settings.map do |setting|
content_tag(:td, class: 'form--matrix-checkbox-cell') do
unless exceptions.include?(setting)
styled_check_box_tag("settings[#{setting}][]", value,
Setting.send(setting).include?(value),
disabled_setting_option(setting).merge(id: "#{setting}_#{value}"))
end
end
end.join.html_safe # rubocop:disable Rails/OutputSafety
end end
def setting_multiselect_choice(setting, choice, options) def setting_multiselect_choice(setting, choice, options)
@ -244,7 +248,6 @@ module SettingsHelper
content_tag(:label, class: 'form--label-with-check-box') do content_tag(:label, class: 'form--label-with-check-box') do
styled_check_box_tag("settings[#{setting}][]", value, styled_check_box_tag("settings[#{setting}][]", value,
Setting.send(setting).include?(value), choice_options) + text.to_s Setting.send(setting).include?(value), choice_options) + text.to_s
end end
end end

@ -115,7 +115,7 @@ describe SettingsHelper, type: :helper do
end end
it 'is disabled and has no hidden field' do it 'is disabled and has no hidden field' do
expect(output).not_to have_selector 'input[type="hidden"][value="''"]', visible: :all expect(output).not_to have_selector 'input[type="hidden"][value=""]', visible: :all
expect(output).to have_selector 'input[type="checkbox"][disabled="disabled"].form--check-box', count: 3 expect(output).to have_selector 'input[type="checkbox"][disabled="disabled"].form--check-box', count: 3
end end
end end

Loading…
Cancel
Save