From 29fc3343c8d5d8183d344d28fa81c8dd5425c214 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Wed, 9 Dec 2020 16:11:07 -0600 Subject: [PATCH 1/5] Switch to github actions --- .github/workflows/test.yml | 79 +++++++++++++++++++ .travis.yml | 63 --------------- Appraisals | 34 ++++++++ gemfiles/activerecord_6.1.0.gemfile | 20 +++++ gemfiles/activerecord_master.gemfile | 20 +++++ .../model_adapters/active_record_5_adapter.rb | 7 +- spec/support/sql_helpers.rb | 6 +- 7 files changed, 158 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml create mode 100644 gemfiles/activerecord_6.1.0.gemfile create mode 100644 gemfiles/activerecord_master.gemfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..dc23084e1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,79 @@ +name: Test & lint +on: [push] + +env: + RAILS_ENV: test + PGHOST: localhost + PGUSER: postgres + +jobs: + tests: + name: Test & lint + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + ruby: ['2.4', '2.5', '2.6', '2.7', 'jruby'] + gemfile: ['gemfiles/activerecord_4.2.0.gemfile', 'gemfiles/activerecord_5.0.2.gemfile', 'gemfiles/activerecord_5.1.0.gemfile', 'gemfiles/activerecord_5.2.2.gemfile', 'gemfiles/activerecord_6.0.0.gemfile', 'gemfiles/activerecord_6.1.0.gemfile', 'gemfiles/activerecord_master.gemfile'] + exclude: + - gemfile: 'gemfiles/activerecord_4.2.0.gemfile' + ruby: '2.7' # rails 4.2 can't run on ruby 2.7 due to BigDecimal API change + - gemfile: 'gemfiles/activerecord_6.0.0.gemfile' + ruby: '2.4' # rails 6+ requires ruby 2.5+ + - gemfile: 'gemfiles/activerecord_6.1.0.gemfile' + ruby: '2.4' # rails 6+ requires ruby 2.5+ + - gemfile: 'gemfiles/activerecord_master.gemfile' + ruby: '2.4' # rails 6+ requires ruby 2.5+ + - gemfile: 'gemfiles/activerecord_5.0.2.gemfile' + ruby: 'jruby' # this *should* work - there's a test failure; it's not incompatible like the other excludes. could be an issue in Rails 5.0.2? + - gemfile: 'gemfiles/activerecord_6.1.0.gemfile' + ruby: 'jruby' # this *should* work. it seems like there's an issue with rails 6 on jruby. + - gemfile: 'gemfiles/activerecord_master.gemfile' + ruby: 'jruby' # this *should* work. it seems like there's an issue with rails 6 on jruby. + + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_DB: cancan_postgresql_spec + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: ["5432:5432"] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: '20' + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Install bundler + run: gem install bundler + + # https://github.com/oracle/truffleruby/issues/62#issuecomment-362065726 + # TODO: can't get this to work on Github actions. see comments in https://github.com/CanCanCommunity/cancancan/pull/669 + - name: Nokogiri support for Truffleruby + run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle config build.nokogiri --use-system-libraries + if: ${{ matrix.ruby == 'truffleruby' }} + + - name: Install gems + run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle install --jobs 2 + + - name: Run linter + run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rubocop + + - name: Run tests on sqlite + run: DB=sqlite BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rake + + - name: Run tests on postgres + run: DB=postgres BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index db1150ba5..000000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -language: ruby -cache: bundler -addons: - postgresql: "9.6" -rvm: - - 2.3.5 - - 2.4.2 - - 2.5.1 - - 2.6.3 - - 2.7.0 - - ruby-head - - jruby-9.1.17.0 - - jruby-9.2.11.1 - - jruby-head - - truffleruby-head - -gemfile: - - gemfiles/activerecord_4.2.0.gemfile - - gemfiles/activerecord_5.0.2.gemfile - - gemfiles/activerecord_5.1.0.gemfile - - gemfiles/activerecord_5.2.2.gemfile - - gemfiles/activerecord_6.0.0.gemfile -env: - - DB=sqlite - - DB=postgres - -matrix: - fast_finish: true - exclude: - - rvm: 2.2.6 - gemfile: gemfiles/activerecord_6.0.0.gemfile - - rvm: 2.3.5 - gemfile: gemfiles/activerecord_6.0.0.gemfile - - rvm: 2.4.2 - gemfile: gemfiles/activerecord_6.0.0.gemfile - - rvm: 2.7.0 - gemfile: gemfiles/activerecord_4.2.0.gemfile - - rvm: truffleruby-head - gemfile: gemfiles/activerecord_4.2.0.gemfile - - rvm: jruby-9.1.17.0 - gemfile: gemfiles/activerecord_5.0.2.gemfile - - rvm: jruby-9.1.17.0 - gemfile: gemfiles/activerecord_6.0.0.gemfile - - rvm: jruby-9.2.11.1 - gemfile: gemfiles/activerecord_5.0.2.gemfile - - rvm: jruby-9.2.11.1 - gemfile: gemfiles/activerecord_6.0.0.gemfile - allow_failures: - - rvm: ruby-head - - rvm: jruby-head - -notifications: - email: - recipients: - - alessandro.rodi@renuo.ch - on_success: change - on_failure: change -before_install: - - rvm get stable - - gem update --system - - gem install bundler -script: - - bundle exec rubocop && bundle exec rake diff --git a/Appraisals b/Appraisals index 9fd8ce0c8..f7b89691a 100644 --- a/Appraisals +++ b/Appraisals @@ -83,3 +83,37 @@ appraise 'activerecord_6.0.0' do gem 'sqlite3', '~> 1.4.0' end end + +appraise 'activerecord_6.1.0' do + gem 'actionpack', '~> 6.1.0', require: 'action_pack' + gem 'activerecord', '~> 6.1.0', require: 'active_record' + gem 'activesupport', '~> 6.1.0', require: 'active_support/all' + + platforms :jruby do + gem 'activerecord-jdbcsqlite3-adapter' + gem 'jdbc-sqlite3' + gem 'jdbc-postgres' + end + + platforms :ruby, :mswin, :mingw do + gem 'pg', '~> 1.2.3' + gem 'sqlite3', '~> 1.4.2' + end +end + +appraise 'activerecord_master' do + gem 'actionpack', github: 'rails/rails', require: 'action_pack' + gem 'activerecord', github: 'rails/rails', require: 'active_record' + gem 'activesupport', github: 'rails/rails', require: 'active_support/all' + + platforms :jruby do + gem 'activerecord-jdbcsqlite3-adapter' + gem 'jdbc-sqlite3' + gem 'jdbc-postgres' + end + + platforms :ruby, :mswin, :mingw do + gem 'pg', '~> 1.2.3' + gem 'sqlite3', '~> 1.4.2' + end +end diff --git a/gemfiles/activerecord_6.1.0.gemfile b/gemfiles/activerecord_6.1.0.gemfile new file mode 100644 index 000000000..857cfa4e2 --- /dev/null +++ b/gemfiles/activerecord_6.1.0.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "actionpack", "~> 6.1.0", require: "action_pack" +gem "activerecord", "~> 6.1.0", require: "active_record" +gem "activesupport", "~> 6.1.0", require: "active_support/all" + +platforms :jruby do + gem "activerecord-jdbcsqlite3-adapter" + gem "jdbc-sqlite3" + gem "jdbc-postgres" +end + +platforms :ruby, :mswin, :mingw do + gem "pg", "~> 1.2.3" + gem "sqlite3", "~> 1.4.2" +end + +gemspec path: "../" diff --git a/gemfiles/activerecord_master.gemfile b/gemfiles/activerecord_master.gemfile new file mode 100644 index 000000000..8328cadc1 --- /dev/null +++ b/gemfiles/activerecord_master.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "actionpack", github: "rails/rails", require: "action_pack" +gem "activerecord", github: "rails/rails", require: "active_record" +gem "activesupport", github: "rails/rails", require: "active_support/all" + +platforms :jruby do + gem "activerecord-jdbcsqlite3-adapter" + gem "jdbc-sqlite3" + gem "jdbc-postgres" +end + +platforms :ruby, :mswin, :mingw do + gem "pg", "~> 1.2.3" + gem "sqlite3", "~> 1.4.2" +end + +gemspec path: "../" diff --git a/lib/cancan/model_adapters/active_record_5_adapter.rb b/lib/cancan/model_adapters/active_record_5_adapter.rb index f7c5df8dc..1326aeece 100644 --- a/lib/cancan/model_adapters/active_record_5_adapter.rb +++ b/lib/cancan/model_adapters/active_record_5_adapter.rb @@ -32,7 +32,6 @@ def build_relation(*where_conditions) end end - # Rails 4.2 deprecates `sanitize_sql_hash_for_conditions` def sanitize_sql(conditions) if conditions.is_a?(Hash) sanitize_sql_activerecord5(conditions) @@ -46,11 +45,7 @@ def sanitize_sql_activerecord5(conditions) table_metadata = ActiveRecord::TableMetadata.new(@model_class, table) predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata) - conditions = predicate_builder.resolve_column_aliases(conditions) - - conditions.stringify_keys! - - predicate_builder.build_from_hash(conditions).map { |b| visit_nodes(b) }.join(' AND ') + predicate_builder.build_from_hash(conditions.stringify_keys).map { |b| visit_nodes(b) }.join(' AND ') end def visit_nodes(node) diff --git a/spec/support/sql_helpers.rb b/spec/support/sql_helpers.rb index fc1ac8cdc..4d5c703a6 100644 --- a/spec/support/sql_helpers.rb +++ b/spec/support/sql_helpers.rb @@ -23,11 +23,13 @@ def connect_db def connect_postgres ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: 'localhost', - database: 'postgres', schema_search_path: 'public') + database: 'postgres', schema_search_path: 'public', + user: 'postgres', password: 'postgres') ActiveRecord::Base.connection.drop_database('cancan_postgresql_spec') ActiveRecord::Base.connection.create_database('cancan_postgresql_spec', 'encoding' => 'utf-8', 'adapter' => 'postgresql') ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: 'localhost', - database: 'cancan_postgresql_spec') + database: 'cancan_postgresql_spec', + user: 'postgres', password: 'postgres') end end From 9a96e2e4ea3c6af018fe01d6398a9f68171f40f0 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Fri, 18 Dec 2020 11:52:38 -0600 Subject: [PATCH 2/5] https://github.com/CanCanCommunity/cancancan/pull/669#issuecomment-748019539 --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc23084e1..89c4189e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,10 +60,9 @@ jobs: - name: Install bundler run: gem install bundler - # https://github.com/oracle/truffleruby/issues/62#issuecomment-362065726 - # TODO: can't get this to work on Github actions. see comments in https://github.com/CanCanCommunity/cancancan/pull/669 + # https://github.com/CanCanCommunity/cancancan/pull/669#issuecomment-748019539 - name: Nokogiri support for Truffleruby - run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle config build.nokogiri --use-system-libraries + run: sudo apt-get -yqq install libxml2-dev libxslt-dev if: ${{ matrix.ruby == 'truffleruby' }} - name: Install gems From 27db5911e17a4827100f37431f11db003e04af97 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Fri, 18 Dec 2020 11:53:35 -0600 Subject: [PATCH 3/5] put bundle gemfile in env --- .github/workflows/test.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89c4189e9..8d680725b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,9 @@ jobs: - gemfile: 'gemfiles/activerecord_master.gemfile' ruby: 'jruby' # this *should* work. it seems like there's an issue with rails 6 on jruby. + env: + BUNDLE_GEMFILE: ${{ matrix.gemfile }} + services: postgres: image: postgres @@ -66,13 +69,13 @@ jobs: if: ${{ matrix.ruby == 'truffleruby' }} - name: Install gems - run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle install --jobs 2 + run: bundle install --jobs 2 - name: Run linter - run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rubocop + run: bundle exec rubocop - name: Run tests on sqlite - run: DB=sqlite BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rake + run: DB=sqlite bundle exec rake - name: Run tests on postgres - run: DB=postgres BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rake + run: DB=postgres bundle exec rake From 4c099f7c9802178a7779030a84aed56bbdf50a35 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Fri, 18 Dec 2020 11:55:47 -0600 Subject: [PATCH 4/5] actually test truffleruby --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d680725b..40ff27fa3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.4', '2.5', '2.6', '2.7', 'jruby'] + ruby: ['2.4', '2.5', '2.6', '2.7', 'jruby', 'truffleruby'] gemfile: ['gemfiles/activerecord_4.2.0.gemfile', 'gemfiles/activerecord_5.0.2.gemfile', 'gemfiles/activerecord_5.1.0.gemfile', 'gemfiles/activerecord_5.2.2.gemfile', 'gemfiles/activerecord_6.0.0.gemfile', 'gemfiles/activerecord_6.1.0.gemfile', 'gemfiles/activerecord_master.gemfile'] exclude: - gemfile: 'gemfiles/activerecord_4.2.0.gemfile' From fbe6c5dab79c4816b52636f426ac12934f5e9607 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Tue, 29 Dec 2020 14:23:21 -0500 Subject: [PATCH 5/5] restore .travis.yml --- .travis.yml | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..bffcb1a99 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,82 @@ +language: ruby +cache: bundler +addons: + postgresql: "9.6" +rvm: + - 2.4.2 + - 2.5.1 + - 2.6.3 + - 2.7.0 + - ruby-head + - jruby-9.1.17.0 + - jruby-9.2.11.1 + - jruby-head + - truffleruby-head + +gemfile: + - gemfiles/activerecord_4.2.0.gemfile + - gemfiles/activerecord_5.0.2.gemfile + - gemfiles/activerecord_5.1.0.gemfile + - gemfiles/activerecord_5.2.2.gemfile + - gemfiles/activerecord_6.0.0.gemfile + - gemfiles/activerecord_6.1.0.gemfile + - gemfiles/activerecord_master.gemfile +env: + - DB=sqlite + - DB=postgres + +matrix: + fast_finish: true + exclude: + - rvm: 2.4.2 + gemfile: gemfiles/activerecord_6.0.0.gemfile + - rvm: 2.2.6 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: 2.3.5 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: 2.4.2 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: 2.2.6 + gemfile: gemfiles/activerecord_master.gemfile + - rvm: 2.3.5 + gemfile: gemfiles/activerecord_master.gemfile + - rvm: 2.4.2 + gemfile: gemfiles/activerecord_master.gemfile + - rvm: 2.7.0 + gemfile: gemfiles/activerecord_4.2.0.gemfile + - rvm: ruby-head + gemfile: gemfiles/activerecord_4.2.0.gemfile + - rvm: truffleruby-head + gemfile: gemfiles/activerecord_4.2.0.gemfile + - rvm: jruby-9.1.17.0 + gemfile: gemfiles/activerecord_5.0.2.gemfile + - rvm: jruby-9.1.17.0 + gemfile: gemfiles/activerecord_6.0.0.gemfile + - rvm: jruby-9.1.17.0 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: jruby-9.1.17.0 + gemfile: gemfiles/activerecord_master.gemfile + - rvm: jruby-9.2.11.1 + gemfile: gemfiles/activerecord_5.0.2.gemfile + - rvm: jruby-9.2.11.1 + gemfile: gemfiles/activerecord_6.0.0.gemfile + - rvm: jruby-9.2.11.1 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: jruby-9.2.11.1 + gemfile: gemfiles/activerecord_master.gemfile + allow_failures: + - rvm: ruby-head + - rvm: jruby-head + +notifications: + email: + recipients: + - alessandro.rodi@renuo.ch + on_success: change + on_failure: change +before_install: + - rvm get stable + - gem update --system + - gem install bundler +script: + - bundle exec rubocop && bundle exec rake