Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Removing old Rails checks #381

Merged
merged 1 commit into from Jan 17, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 7 additions & 18 deletions lib/bootstrap_form/form_builder.rb
Expand Up @@ -68,20 +68,10 @@ def file_field_with_bootstrap(name, options = {})

bootstrap_method_alias :file_field

if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0")
def select_with_bootstrap(method, choices = nil, options = {}, html_options = {}, &block)
form_group_builder(method, options, html_options) do
prepend_and_append_input(options) do
select_without_bootstrap(method, choices, options, html_options, &block)
end
end
end
else
def select_with_bootstrap(method, choices, options = {}, html_options = {})
form_group_builder(method, options, html_options) do
prepend_and_append_input(options) do
select_without_bootstrap(method, choices, options, html_options)
end
def select_with_bootstrap(method, choices = nil, options = {}, html_options = {}, &block)
form_group_builder(method, options, html_options) do
prepend_and_append_input(options) do
select_without_bootstrap(method, choices, options, html_options, &block)
end
end
end
Expand Down Expand Up @@ -149,7 +139,7 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_
content_tag(:div, class: div_class.compact.join(" ")) do
checkbox_html.concat(label(label_name, html, class: ["custom-control-label", label_class].compact.join(" ")))
end
else
else
disabled_class = " disabled" if options[:disabled]
if options[:inline]
label_class = " #{label_class}" if label_class
Expand Down Expand Up @@ -185,7 +175,7 @@ def radio_button_with_bootstrap(name, value, *args)
content_tag(:div, class: div_class.compact.join(" ")) do
radio_html.concat(label(name, html, value: value, class: ["custom-control-label", label_class].compact.join(" ")))
end
else
else
if options[:inline]
label_class = " #{label_class}" if label_class
label(name, html, class: "radio-inline#{disabled_class}#{label_class}", value: value)
Expand Down Expand Up @@ -465,8 +455,7 @@ def get_help_text_by_i18n_key(name)
if object

if object.class.respond_to?(:model_name)
# ActiveModel::Naming 3.X.X does not support .name; it is supported as of 4.X.X
partial_scope = object.class.model_name.respond_to?(:name) ? object.class.model_name.name : object.class.model_name
partial_scope = object.class.model_name.name
else
partial_scope = object.class.name
end
Expand Down
30 changes: 14 additions & 16 deletions test/bootstrap_selects_test.rb
Expand Up @@ -98,23 +98,21 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prepend: 'Before', append: 'After')
end

if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0")
test "selects with block use block as content" do
expected = <<-HTML.strip_heredoc
<div class="form-group">
<label class="" for="user_status">Status</label>
<select class="form-control" name="user[status]" id="user_status">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
HTML
select = @builder.select(:status) do
content_tag(:option) { 'Option 1' } +
content_tag(:option) { 'Option 2' }
end
assert_equivalent_xml expected, select
test "selects with block use block as content" do
expected = <<-HTML.strip_heredoc
<div class="form-group">
<label class="" for="user_status">Status</label>
<select class="form-control" name="user[status]" id="user_status">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
HTML
select = @builder.select(:status) do
content_tag(:option) { 'Option 1' } +
content_tag(:option) { 'Option 2' }
end
assert_equivalent_xml expected, select
end

test "selects render labels properly" do
Expand Down