From 704123ddfadb198d6c9553b4bcb889b945e9cb45 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Fri, 14 Jan 2022 09:44:51 -0800 Subject: [PATCH] Add Rails 7 to the test matrix. --- .../workflows/{tests.yml => ruby-tests.yml} | 35 ++++++++++--------- .rubocop.yml | 25 +------------ README.md | 3 +- gemfiles/{rails6_0.gemfile => 6_0.gemfile} | 2 +- gemfiles/{rails6_1.gemfile => 6_1.gemfile} | 2 +- gemfiles/7_0.gemfile | 6 ++++ lib/browser/accept_language.rb | 2 +- lib/browser/base.rb | 6 ++-- lib/browser/device.rb | 18 +++++----- lib/browser/meta/base.rb | 2 +- lib/browser/platform.rb | 2 +- test/test_helper.rb | 2 +- test/unit/bots_test.rb | 2 +- 13 files changed, 45 insertions(+), 62 deletions(-) rename .github/workflows/{tests.yml => ruby-tests.yml} (57%) rename gemfiles/{rails6_0.gemfile => 6_0.gemfile} (77%) rename gemfiles/{rails6_1.gemfile => 6_1.gemfile} (77%) create mode 100644 gemfiles/7_0.gemfile diff --git a/.github/workflows/tests.yml b/.github/workflows/ruby-tests.yml similarity index 57% rename from .github/workflows/tests.yml rename to .github/workflows/ruby-tests.yml index a5d0d10a..cffac166 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/ruby-tests.yml @@ -1,48 +1,48 @@ -name: Tests +--- +name: ruby-tests on: - pull_request: - branches: - - main + pull_request_target: push: branches: - main - - schedule: - - cron: "0 10 * * *" + workflow_dispatch: + inputs: {} jobs: build: name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }} runs-on: "ubuntu-latest" + if: | + github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' || + github.actor != 'dependabot[bot]' strategy: fail-fast: false matrix: - ruby: ["3.0.x", "2.7.x", "2.6.x", "2.5.x"] + ruby: ["2.7", "3.0", "3.1"] gemfile: - Gemfile - - gemfiles/rails6_1.gemfile - - gemfiles/rails6_0.gemfile + - gemfiles/7_0.gemfile + - gemfiles/6_1.gemfile + - gemfiles/6_0.gemfile steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2.4.0 - uses: actions/cache@v2 with: path: vendor/bundle key: > - ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }} - restore-keys: > - ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }} + ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ + hashFiles(matrix.gemfile) }} - name: Set up Ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Install gem dependencies env: - RAILS_ENV: test BUNDLE_GEMFILE: ${{ matrix.gemfile }} run: | gem install bundler @@ -51,7 +51,8 @@ jobs: - name: Run Tests env: - RAILS_ENV: test + PGHOST: localhost + PGUSER: postgres BUNDLE_GEMFILE: ${{ matrix.gemfile }} run: | bundle exec rake diff --git a/.rubocop.yml b/.rubocop.yml index 1a24d18d..81749dcf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ inherit_gem: AllCops: TargetRubyVersion: 2.5 + NewCops: enable Exclude: - bin/**/* - gemfiles/**/* @@ -13,29 +14,5 @@ AllCops: - "*.gemspec" - config.ru -Metrics/ClassLength: - Enabled: false - -Layout/LineLength: - Max: 80 - -Metrics/MethodLength: - Enabled: false - -Style/Alias: - EnforcedStyle: prefer_alias_method - -Lint/RedundantCopDisableDirective: - Enabled: false - -Metrics/AbcSize: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/PerceivedComplexity: - Enabled: false - Naming/VariableNumber: Enabled: false diff --git a/README.md b/README.md index e7cb8566..58730357 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Browser -[![Tests](https://github.com/fnando/browser/workflows/Tests/badge.svg)](https://github.com/fnando/browser) -[![Code Climate](https://codeclimate.com/github/fnando/browser/badges/gpa.svg)](https://codeclimate.com/github/fnando/browser) +[![Tests](https://github.com/fnando/browser/workflows/ruby-tests/badge.svg)](https://github.com/fnando/browser) [![Gem](https://img.shields.io/gem/v/browser.svg)](https://rubygems.org/gems/browser) [![Gem](https://img.shields.io/gem/dt/browser.svg)](https://rubygems.org/gems/browser) diff --git a/gemfiles/rails6_0.gemfile b/gemfiles/6_0.gemfile similarity index 77% rename from gemfiles/rails6_0.gemfile rename to gemfiles/6_0.gemfile index 19fcdaa7..bda7e30a 100644 --- a/gemfiles/rails6_0.gemfile +++ b/gemfiles/6_0.gemfile @@ -3,4 +3,4 @@ source "https://rubygems.org" gemspec path: ".." -gem "rails", "~> 6.0" +gem "rails", "~> 6.0.0" diff --git a/gemfiles/rails6_1.gemfile b/gemfiles/6_1.gemfile similarity index 77% rename from gemfiles/rails6_1.gemfile rename to gemfiles/6_1.gemfile index cd4bff52..8f0feace 100644 --- a/gemfiles/rails6_1.gemfile +++ b/gemfiles/6_1.gemfile @@ -3,4 +3,4 @@ source "https://rubygems.org" gemspec path: ".." -gem "rails", "~> 6.1" +gem "rails", "~> 6.1.0" diff --git a/gemfiles/7_0.gemfile b/gemfiles/7_0.gemfile new file mode 100644 index 00000000..aeab23ae --- /dev/null +++ b/gemfiles/7_0.gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source "https://rubygems.org" +gemspec path: ".." + +gem "rails", "~> 7.0.0" diff --git a/lib/browser/accept_language.rb b/lib/browser/accept_language.rb index b1d35c0e..7e2f73b3 100644 --- a/lib/browser/accept_language.rb +++ b/lib/browser/accept_language.rb @@ -55,7 +55,7 @@ def quality private def quality_value qvalue = part[/;q=([\d.]+)/, 1] - qvalue = /\A0\.0?\z/.match?(qvalue) ? "0.0" : qvalue + qvalue = "0.0" if /\A0\.0?\z/.match?(qvalue) qvalue = qvalue.squeeze(".") if qvalue qvalue end diff --git a/lib/browser/base.rb b/lib/browser/base.rb index 5cd38126..97e2a51b 100644 --- a/lib/browser/base.rb +++ b/lib/browser/base.rb @@ -26,7 +26,7 @@ def accept_language end end - alias_method :to_a, :meta + alias to_a meta # Return meta representation as string. def to_s @@ -161,7 +161,7 @@ def sputnik?(expected_version = nil) def yandex?(expected_version = nil) Yandex.new(ua).match? && detect_version?(full_version, expected_version) end - alias_method :yandex_browser?, :yandex? + alias yandex_browser? yandex? # Detect if browser is UCBrowser. def uc_browser?(expected_version = nil) @@ -180,7 +180,7 @@ def micro_messenger?(expected_version = nil) detect_version?(full_version, expected_version) end - alias_method :wechat?, :micro_messenger? + alias wechat? micro_messenger? def weibo?(expected_version = nil) Weibo.new(ua).match? && detect_version?(full_version, expected_version) diff --git a/lib/browser/device.rb b/lib/browser/device.rb index 463d8b97..ecee004a 100644 --- a/lib/browser/device.rb +++ b/lib/browser/device.rb @@ -96,7 +96,7 @@ def unknown? def ipod_touch? id == :ipod_touch end - alias_method :ipod?, :ipod_touch? + alias ipod? ipod_touch? def iphone? id == :iphone @@ -105,12 +105,12 @@ def iphone? def ps3? id == :ps3 end - alias_method :playstation3?, :ps3? + alias playstation3? ps3? def ps4? id == :ps4 end - alias_method :playstation4?, :ps4? + alias playstation4? ps4? def psp? id == :psp @@ -119,8 +119,8 @@ def psp? def playstation_vita? id == :psvita end - alias_method :vita?, :playstation_vita? - alias_method :psp_vita?, :playstation_vita? + alias vita? playstation_vita? + alias psp_vita? playstation_vita? def kindle? id == :kindle || kindle_fire? @@ -133,22 +133,22 @@ def kindle_fire? def nintendo_wii? id == :wii end - alias_method :wii?, :nintendo_wii? + alias wii? nintendo_wii? def nintendo_wiiu? id == :wiiu end - alias_method :wiiu?, :nintendo_wiiu? + alias wiiu? nintendo_wiiu? def nintendo_switch? id == :switch end - alias_method :switch?, :nintendo_switch? + alias switch? nintendo_switch? def blackberry_playbook? id == :playbook end - alias_method :playbook?, :blackberry_playbook? + alias playbook? blackberry_playbook? def surface? id == :surface diff --git a/lib/browser/meta/base.rb b/lib/browser/meta/base.rb index 1b82c640..ee792ebb 100644 --- a/lib/browser/meta/base.rb +++ b/lib/browser/meta/base.rb @@ -37,7 +37,7 @@ def meta end def to_a - meta.to_s.squeeze(" ").split(" ") + meta.to_s.squeeze(" ").split end end end diff --git a/lib/browser/platform.rb b/lib/browser/platform.rb index 4e673710..dcac48b9 100644 --- a/lib/browser/platform.rb +++ b/lib/browser/platform.rb @@ -138,7 +138,7 @@ def ios_webview? def android_app? android? && ua.match?(/\bwv\b/) end - alias_method :android_webview?, :android_app? + alias android_webview? android_app? # http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken def windows_xp? diff --git a/test/test_helper.rb b/test/test_helper.rb index 8fb6252a..9d672b51 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -14,7 +14,7 @@ module Minitest class Test setup do - Browser::Bot.instance_variable_set("@detect_empty_ua", false) + Browser::Bot.instance_variable_set(:@detect_empty_ua, false) end def assert_deprecated(message, file, line, &block) diff --git a/test/unit/bots_test.rb b/test/unit/bots_test.rb index a516853a..4283074f 100644 --- a/test/unit/bots_test.rb +++ b/test/unit/bots_test.rb @@ -86,7 +86,7 @@ class BotsTest < Minitest::Test end test "adds custom bot matcher" do - Browser::Bot.matchers << ->(ua, _) { ua.match?(/some-script/) } + Browser::Bot.matchers << ->(ua, _) { ua.include?("some-script") } browser = Browser.new("some-script") assert browser.bot?