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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "rails", BootstrapForm::REQUIRED_RAILS_VERSION
gem "sprockets-rails", require: "sprockets/railtie"
gem "sqlite3", "~> 1.4"
gem "sqlite3", ">= 1.4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find you needed to change this? There was some dependency issue for Rails 7.1 and earlier where we have to keep SQLite back at 1.4, but if it caused you problems, leave it in. If it didn't actually break anything, let's leave it the way it was, and we'll take it out when we drop support for Rails 7.1.

Copy link
Contributor Author

@walterdavis walterdavis Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, but possibly just because I am unsure how to route around this problem in my local environment. I kept getting the "you have already activated sqlite [much higher version]" when I ran the tests, both with and without bundle exec. I can take it back out and just not run the tests here... (edit: To be clear, the tests just would not run at all if I left the gemfile alone.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have both 7.1.x and 8.0.x (rails) installed locally, under ruby 3.2.8.

waltd@Max bootstrap_form % gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.6.9
  - RUBY VERSION: 3.2.8 (2025-03-26 patchlevel 263) [arm64-darwin24]
  - INSTALLATION DIRECTORY: /Users/waltd/.rvm/gems/ruby-3.2.8
  - USER INSTALLATION DIRECTORY: /Users/waltd/.gem/ruby/3.2.0
  - CREDENTIALS FILE: /Users/waltd/.gem/credentials
  - RUBY EXECUTABLE: /Users/waltd/.rvm/rubies/ruby-3.2.8/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /Users/waltd/.rvm/gems/ruby-3.2.8/bin
  - SPEC CACHE DIRECTORY: /Users/waltd/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/waltd/.rvm/rubies/ruby-3.2.8/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - arm64-darwin-24
  - GEM PATHS:
     - /Users/waltd/.rvm/gems/ruby-3.2.8
     - /Users/waltd/.rvm/rubies/ruby-3.2.8/lib/ruby/gems/3.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
     - :benchmark => false
     - :sources => ["http://rubygems.org/"]
  - REMOTE SOURCES:
     - http://rubygems.org/
  - SHELL PATH:
     - /Users/waltd/.rvm/gems/ruby-3.2.8/bin
     - /Users/waltd/.rvm/gems/ruby-3.2.8@global/bin
     - /Users/waltd/.rvm/rubies/ruby-3.2.8/bin
     - /Users/waltd/.pyenv/shims
     - /Users/waltd/.pyenv/bin
     - /opt/homebrew/opt/postgresql@12/bin
     - /Users/waltd/.yarn/bin
     - /Users/waltd/.config/yarn/global/node_modules/.bin
     - /Users/waltd/.nvm/versions/node/v22.1.0/bin
     - /opt/homebrew/bin
     - /opt/homebrew/sbin
     - /usr/local/bin
     - /System/Cryptexes/App/usr/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
     - /Library/Apple/usr/bin
     - /Users/waltd/.rvm/bin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder. That was it. Something else already activated a later version. But for some reason we wanted to keep earlier versions of Rails on 1.4. Let's go with what you have and then I'll fix this when we drop Rails 7.1.

4 changes: 2 additions & 2 deletions demo/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class User < ApplicationRecord
validates :status, presence: true, if: -> { age > 42 }
validates :misc, presence: true, unless: -> { feet == 5 }

has_one :address
has_one :address, dependent: nil
accepts_nested_attributes_for :address

has_rich_text(:life_story)

def always
def always # rubocop:disable Naming/PredicateMethod
true
end

Expand Down
6 changes: 3 additions & 3 deletions lib/bootstrap_form/inputs/collection_check_boxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def field_name(method, *methods, multiple: false, index: @options[:index])
def field_name_shim(object_name, method_name, *method_names, multiple: false, index: nil)
names = method_names.map! { |name| "[#{name}]" }.join
if object_name.blank?
"#{method_name}#{names}#{multiple ? '[]' : ''}"
"#{method_name}#{names}#{'[]' if multiple}"
elsif index
"#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? '[]' : ''}"
"#{object_name}[#{index}][#{method_name}]#{names}#{'[]' if multiple}"
else
"#{object_name}[#{method_name}]#{names}#{multiple ? '[]' : ''}"
"#{object_name}[#{method_name}]#{names}#{'[]' if multiple}"
Comment on lines +37 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if these were RuboCop changes, and then I saw your other e-mail. If there are extensive RuboCop changes, I suggest a separate PR, but since the scope is limited, it's fine to be here.

More context: We could freeze RuboCop to certain rules, etc., but honestly I don't have time to do a proper job of maintaining this gem, let alone adding additional tasks around RuboCop, so we just fix style things as they come up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might think about turning off the auto-correct, then. That would show the findings, and make it more deliberate to fix them in a given patch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I'll look into that. I'm not even sure why auto-correct is the default, now that you mention it.

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/inputs/file_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module FileField
def file_field_with_bootstrap(name, options={})
options = options.reverse_merge(control_class: "form-control")
form_group_builder(name, options) do
input_with_error(name) do
prepend_and_append_input(name, options) do
file_field_without_bootstrap(name, options)
end
end
Expand Down
45 changes: 45 additions & 0 deletions test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,51 @@ class BootstrapFormGroupTest < ActionView::TestCase
assert_equivalent_html expected, bootstrap_form_for(@user) { |f| f.text_field :email, prepend: "$", append: ".00" }
end

test "file field with prepend text" do
expected = <<~HTML
<div class="mb-3">
<label class="form-label" for="user_avatar">Avatar</label>
<div class="input-group">
<span class="input-group-text">before</span>
<input class="form-control" id="user_avatar" name="user[avatar]" type="file" />
</div>
</div>
HTML
assert_equivalent_html expected, @builder.file_field(:avatar, prepend: "before")
end

test "file field with append text" do
expected = <<~HTML
<div class="mb-3">
<label class="form-label" for="user_avatar">Avatar</label>
<div class="input-group">
<input class="form-control" id="user_avatar" name="user[avatar]" type="file" />
<span class="input-group-text">after</span>
</div>
</div>
HTML
assert_equivalent_html expected, @builder.file_field(:avatar, append: "after")
end

test "file field with append and prepend button" do
prefix = '<div class="mb-3"><label class="form-label" for="user_avatar">Avatar</label><div class="input-group">'
field = <<~HTML
<input class="form-control" id="user_avatar" name="user[avatar]" type="file" />
HTML
button_src = link_to("Click", "#", class: "btn btn-secondary")
button_prepend = button_src
button_append = button_src
suffix = "</div></div>"
after_button = prefix + field + button_append + suffix
before_button = prefix + button_prepend + field + suffix
both_button = prefix + button_prepend + field + button_append + suffix
multiple_button = prefix + button_prepend + button_prepend + field + button_append + button_append + suffix
assert_equivalent_html after_button, @builder.file_field(:avatar, append: button_src)
assert_equivalent_html before_button, @builder.file_field(:avatar, prepend: button_src)
assert_equivalent_html both_button, @builder.file_field(:avatar, append: button_src, prepend: button_src)
assert_equivalent_html multiple_button, @builder.file_field(:avatar, append: [button_src] * 2, prepend: [button_src] * 2)
Comment on lines +237 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice set of tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shamelessly duped from a few lines up in the same file! 😁

end

test "help messages for default forms" do
expected = <<~HTML
<div class="mb-3">
Expand Down