diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 000000000..ffa9fc3ef --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,45 @@ +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + Lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.2 + bundler-cache: true + - name: Danger + if: ${{ github.event_name == 'pull_request' }} + run: | + gem install danger + danger + - name: Rubocop + run: bundle exec rubocop --auto-correct + Test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: [ '3.0', '2.7', '2.6' ] + gemfile: [ '6.1', '6.0', '5.2', 'edge' ] + exclude: + - { ruby-version: '3.0', gemfile: "5.2" } + - { ruby-version: '2.6', gemfile: "edge" } + env: + BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Run tests + run: bundle exec rake test diff --git a/.gitignore b/.gitignore index e7bb8f752..7c02cff54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .bundle/ +.idea log/*.log pkg/ demo/db/*.sqlite3 @@ -13,7 +14,7 @@ test/gemfiles/*.lock Vagrantfile .vagrant -// For the demo app. +# For the demo app. # Ignore uploaded files in development. demo/storage/* @@ -30,3 +31,17 @@ demo/node_modules demo/yarn-error.log demo/yarn-debug.log* demo/.yarn-integrity + +# For stuff that gets created if using the Dockerfile image +.bundle/ +.cache/ +vendor/bundle + +# or .local/share/pry/pry_history if you need to be more exact +.local/ +.irb_history +.byebug_history +# For Debian images with Bash +.bash_history +# For Alpine images +.ash_history diff --git a/.rubocop.yml b/.rubocop.yml index 88cc286dc..213e69d98 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,3 @@ -# Taken from: https://github.com/mattbrictson/rails-template/blob/master/rubocop.yml.tt -# Modified for demo app in `demo/` directory. require: - rubocop-performance - rubocop-rails @@ -8,23 +6,32 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true TargetRubyVersion: 2.5 + NewCops: enable Exclude: - - "bin/*" + - bin/* - Capfile - demo/bin/* - - "demo/bower_components/**/*" + - demo/bower_components/**/* - demo/config/boot.rb - demo/config/environment.rb - demo/config/initializers/version.rb - demo/db/schema.rb - - "demo/node_modules/**/*" + - demo/node_modules/**/* - demo/Rakefile - - "demo/tmp/**/*" - - "demo/vendor/**/*" + - demo/tmp/**/* + - demo/vendor/**/* - Gemfile - gemfiles/vendor/bundle/**/* + - vendor/bundle/**/* - Guardfile - Rakefile + - vendor/**/* + +Layout/LineLength: + Max: 132 + Exclude: + - "demo/config/**/*" + - "demo/db/**/*" Layout/SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space @@ -45,12 +52,6 @@ Metrics/ClassLength: - "demo/test/**/*" - "test/**/*" -Metrics/LineLength: - Max: 132 - Exclude: - - "demo/config/**/*" - - "demo/db/**/*" - Metrics/MethodLength: Max: 12 Exclude: diff --git a/CHANGELOG.md b/CHANGELOG.md index b3b03e9bf..faf90194f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,8 @@ ### Bugfixes -* Your contribution here! +* [#586](https://github.com/bootstrap-ruby/bootstrap_form/pull/586): Fix Rails 6.1 tests on master - [@thimo](https://github.com/thimo). +* [#587](https://github.com/bootstrap-ruby/bootstrap_form/pull/587): Replace `strip_heredoc` with `<<~` - [@thimo](https://github.com/thimo). ## [4.5.0][] (2020-04-29) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4610a54de..dea9253bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ There are a number of ways you can contribute to `bootstrap_form`: *Note:* If you want to work on preparing `bootstrap_form` for Bootstrap 5, please start from the `bootstrap-5` branch. If you're submitting a pull request with code or documentation, -say that you want to merge your branch to the `bootstrap-5` branch. +target the pull request to the `bootstrap-5` branch. ## Code Contributions @@ -82,6 +82,33 @@ The goal of `bootstrap_form` is to support all versions of Rails currently suppo The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html). +### Developing with Docker + +This repository includes a `Dockerfile` to build an image with the minimum `bootstrap_form`-supported Ruby environment. To build the image: + +```bash +docker build --tag bootstrap_form . +``` + +This builds an image called `bootstrap_form`. You can change that to any tag you wish. Just make sure you use the same tag name in the `docker run` command. + +If you want to use a different Ruby version, or a smaller Linux distribution (although the distro may be missing tools you need): + +```bash +docker build --build-arg "RUBY_VERSION=2.7" --build-arg "DISTRO=slim-buster" --tag bootstrap_form . +``` + +Then run whichever container you built with the shell to create the bundle: + +```bash +docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -it bootstrap_form /bin/bash +bundle install +``` + +You can run tests in the container as normal, with `rake test`. + +(Some of that command line is need for Linux hosts, to run the container as the current user.) + ## Documentation Contributions Contributions to documentation are always welcome. Even fixing one typo improves the quality of `bootstrap_form`. To make a documentation contribution, follow steps 1-3 of Code Contributions, then make the documentation changes, then make the pull request (step 6 of Code Contributions). diff --git a/Dockerfile b/Dockerfile index 617ed8496..3e5976595 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,26 @@ -# From: https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development -ARG RUBY_VERSION -# See explanation below -FROM ruby:$RUBY_VERSION-slim-buster +ARG DISTRO=buster +ARG RUBY_VERSION=2.6 -ARG NODE_MAJOR -ARG BUNDLER_VERSION -ARG YARN_VERSION +FROM ruby:$RUBY_VERSION-$DISTRO -# Common dependencies -RUN apt-get update -qq \ - && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ - build-essential \ - gnupg2 \ - curl \ - less \ - git \ - sqlite3 \ - libsqlite3-dev \ - && apt-get clean \ - && rm -rf /var/cache/apt/archives/* \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - && truncate -s 0 /var/log/*log - -# Add NodeJS to sources list -RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - - -# Add Yarn to the sources list -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ - && echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list - -# Application dependencies -RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ - DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ - nodejs \ - yarn=$YARN_VERSION-1 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ - truncate -s 0 /var/log/*log - -# Configure bundler -ENV LANG=C.UTF-8 \ - BUNDLE_JOBS=4 \ - BUNDLE_RETRY=3 - -# Uncomment this line if you store Bundler settings in the project's root -# ENV BUNDLE_APP_CONFIG=.bundle - -# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec` -# ENV PATH /app/bin:$PATH - -# Upgrade RubyGems and install required Bundler version -RUN gem update --system && \ - gem install bundler:$BUNDLER_VERSION - -# Create a directory for the app code RUN mkdir -p /app - -WORKDIR /app \ No newline at end of file +ENV HOME /app +WORKDIR /app + +ENV GEM_HOME $HOME/vendor/bundle +ENV BUNDLE_APP_CONFIG="$GEM_HOME" +ENV PATH ./bin:$GEM_HOME/bin:$PATH +RUN (echo 'docker'; echo 'docker') | passwd root + +# Yarn installs nodejs. +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt update -y -q && \ + apt install -y -q yarn + +# Ruby now comes with bundler, but we're not using the default version yet, because we were using +# a newer version of bundler already. Ruby 3 comes with Bundler 2.2.3. Ruby 2.7 has Bundler 2.1.2, +# which is still behind what we were using. +RUN gem install bundler -v 2.1.4 + +EXPOSE 3000 diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 5b153fdd0..375fc53ef 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -14,7 +14,7 @@ def submit(name=nil, options={}) def primary(name=nil, options={}, &block) setup_css_class "btn btn-primary", options - if options[:render_as_button] || block_given? + if options[:render_as_button] || block options.except! :render_as_button button(name, options, &block) else diff --git a/lib/bootstrap_form/inputs/check_box.rb b/lib/bootstrap_form/inputs/check_box.rb index 2d0612539..245ca7d69 100644 --- a/lib/bootstrap_form/inputs/check_box.rb +++ b/lib/bootstrap_form/inputs/check_box.rb @@ -38,7 +38,7 @@ def check_box_label(name, options, checked_value, &block) end def check_box_description(name, options, &block) - content = block_given? ? capture(&block) : options[:label] + content = block ? capture(&block) : options[:label] content || object&.class&.human_attribute_name(name) || name.to_s.humanize end diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index f7eacbfec..0b34d131f 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -6,7 +6,7 @@ class BootstrapCheckboxTest < ActionView::TestCase setup :setup_test_fixture test "check_box is wrapped correctly" do - expected = <<-HTML.strip_heredoc + expected = <<~HTML