From cb192fd90e58cfbd198d7f1311e3146886b86875 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Wed, 28 Sep 2022 16:14:30 +0200 Subject: [PATCH 01/14] Add GitHub action for tests --- .github/workflows/test.yml | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..41b5bb9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: Ruby + +on: [push] + +jobs: + test: + env: + RAILS_ENV: "test" + DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" + runs-on: ubuntu-latest + services: + mysql: + image: mariadb:10.5 + env: + MYSQL_DATABASE: "unipept_test" + MYSQL_ROOT_PASSWORD: "unipept" + MYSQL_HOST: "localhost" + ports: + - 3306:3306 + options: --health-cmd "mysqladmin ping -h localhost" --health-interval 10s --health-timeout 5s --health-retries 5 + steps: + - uses: actions/checkout@v2 + - name: Use ruby from .ruby-version + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Use node 12 + uses: actions/setup-node@v2 + with: + node-version: 12.x + - name: Get Yarn cache directory + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Use Yarn cache + uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ubuntu-yarn-node12-${{ hashFiles('**/yarn.lock') }} + - name: Install JS dependencies + run: yarn install --prefer-offline --frozen-lockfile + - name: Run tests + env: + CI: true + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: | + bundle exec rails test From 3c4a44d165d459cd5be01d98bdc89e2772ea7b37 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 09:41:04 +0200 Subject: [PATCH 02/14] Fix Ruby tests --- .rubocop.yml | 2 ++ app/helpers/application_helper.rb | 2 +- app/models/sequence.rb | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 12d5319..5be2d38 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -48,3 +48,5 @@ Naming/PredicateName: Enabled: false Naming/MethodParameterName: Enabled: false +Style/OptionalBooleanParameter: + Enabled: false diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e7a7346..7124d74 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module ApplicationHelper - def lineage_info(lineage, include_names: false) + def lineage_info(lineage, include_names = false) order = if @v1 Lineage::ORDER_V1 else diff --git a/app/models/sequence.rb b/app/models/sequence.rb index 0147896..063f019 100644 --- a/app/models/sequence.rb +++ b/app/models/sequence.rb @@ -23,7 +23,7 @@ class Sequence < ApplicationRecord belongs_to :lca_il_t, foreign_key: 'lca_il', primary_key: 'id', class_name: 'Taxon' alias generated_peptides peptides - def peptides(equate_il: true) + def peptides(equate_il = true) if equate_il generated_peptides else @@ -31,7 +31,7 @@ def peptides(equate_il: true) end end - def lineages(equate_il: true, eager: false) + def lineages(equate_il = true, eager = false) raise(ArgumentError, ':equate_il must be a boolean') unless Sequence.boolean?(equate_il) raise(ArgumentError, ':eager must be a boolean') unless Sequence.boolean?(eager) @@ -46,7 +46,7 @@ def lineages(equate_il: true, eager: false) end # Calculates the lowest common ancestor for this sequence - def calculate_lca(equate_il: true, return_taxon: false) + def calculate_lca(equate_il = true, return_taxon = false) if equate_il return lca_il_t if return_taxon @@ -67,7 +67,7 @@ def fa end # Calculates thefor this sequence - def calculate_fa(equate_il: true) + def calculate_fa(equate_il = true) equate_il ? fa_il : fa end @@ -152,7 +152,7 @@ def self.lca_t_relation_name(equate_il) end # search for a single sequence, include information through join tables - def self.single_search(sequence, equate_il: true) + def self.single_search(sequence, equate_il = true) raise(ArgumentError, ':equate_il must be a boolean') unless boolean?(equate_il) raise SequenceTooShortError if sequence.length < 5 @@ -163,7 +163,7 @@ def self.single_search(sequence, equate_il: true) end # try to find multiple matches for a single sequence - def self.advanced_single_search(sequence, equate_il: true) + def self.advanced_single_search(sequence, equate_il = true) raise(ArgumentError, ':equate_il must be a boolean') unless boolean?(equate_il) # sanity check raise(NoMatchesFoundError, sequence) if sequence.index(/([KR])([^P])/).nil? From 49fa7f48fb8372615ebb9426dc9f63d7eaeb5dd8 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 09:45:48 +0200 Subject: [PATCH 03/14] Remove redundant JS setup from test action --- .github/workflows/test.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41b5bb9..c31925a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,21 +24,6 @@ jobs: uses: ruby/setup-ruby@v1 with: bundler-cache: true - - name: Use node 12 - uses: actions/setup-node@v2 - with: - node-version: 12.x - - name: Get Yarn cache directory - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Use Yarn cache - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ubuntu-yarn-node12-${{ hashFiles('**/yarn.lock') }} - - name: Install JS dependencies - run: yarn install --prefer-offline --frozen-lockfile - name: Run tests env: CI: true From 2710a6909cc8a68b2e40f95cdac6d01d338e1070 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 09:48:19 +0200 Subject: [PATCH 04/14] Try to fix errors in tests --- app/controllers/private_api_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/private_api_controller.rb b/app/controllers/private_api_controller.rb index c24434a..fcbe354 100644 --- a/app/controllers/private_api_controller.rb +++ b/app/controllers/private_api_controller.rb @@ -1,7 +1,7 @@ class PrivateApiController < HandleOptionsController before_action :set_headers, only: %i[goterms ecnumbers interpros taxa proteins metadata] before_action :default_format_json - skip_before_action :verify_authenticity_token + skip_before_action :verify_authenticity_token, raise: false def goterms go_terms = params[:goterms] || [] From 0049be39f143cb8e8450af931470f797d66ad211 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 09:49:42 +0200 Subject: [PATCH 05/14] Change environment for Ruby tests --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c31925a..2757542 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,6 @@ jobs: bundler-cache: true - name: Run tests env: - CI: true - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + RAILS_ENV: "test" run: | bundle exec rails test From 6fea7ea4f77629e78b06b2b7103b4202302c7529 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 10:05:50 +0200 Subject: [PATCH 06/14] Update MariaDB image version --- .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 2757542..84bd173 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest services: mysql: - image: mariadb:10.5 + image: mariadb:10.9 env: MYSQL_DATABASE: "unipept_test" MYSQL_ROOT_PASSWORD: "unipept" From 7c7988614f59de9be5d23e67552e0e55c7a80024 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 29 Sep 2022 10:08:06 +0200 Subject: [PATCH 07/14] Change connection to GH actions DB --- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 4 ++-- config/database.yml | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 27aa315..65a815d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Ruby +name: Lint on: [push] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84bd173..9b67cc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Ruby +name: Test on: [push] @@ -26,6 +26,6 @@ jobs: bundler-cache: true - name: Run tests env: - RAILS_ENV: "test" + RAILS_ENV: "github_actions" run: | bundle exec rails test diff --git a/config/database.yml b/config/database.yml index dbbd538..f286e8b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,6 +19,12 @@ test: database: unipept_test socket: /tmp/mysql.sock +github_actions: + <<: *default + database: unipept_test + host: 127.0.0.1 + port: 3306 + production: <<: *default database: unipept From 04f073bd810ee393754c5eb21845c0ee2732afd1 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 14:41:06 +0100 Subject: [PATCH 08/14] Update database URL in test action --- .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 9b67cc9..f84630d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: test: env: RAILS_ENV: "test" - DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" + TEST_DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" runs-on: ubuntu-latest services: mysql: From f5411101fbd9a4a5ed8e4969f2c833454574400b Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 14:46:17 +0100 Subject: [PATCH 09/14] Trying to get tests to work in action --- .github/workflows/test.yml | 2 +- config/database.yml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f84630d..2694f3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest services: mysql: - image: mariadb:10.9 + image: mariadb env: MYSQL_DATABASE: "unipept_test" MYSQL_ROOT_PASSWORD: "unipept" diff --git a/config/database.yml b/config/database.yml index f286e8b..63ca1e3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -22,8 +22,7 @@ test: github_actions: <<: *default database: unipept_test - host: 127.0.0.1 - port: 3306 + url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %> production: <<: *default From e1868de23e1a0859a5eef0082df43eec85a870f2 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 14:47:52 +0100 Subject: [PATCH 10/14] Try and check environment variables for database --- config/database.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/database.yml b/config/database.yml index 63ca1e3..c6d7292 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,12 +14,12 @@ development: # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. -test: - <<: *default - database: unipept_test - socket: /tmp/mysql.sock +#test: +# <<: *default +# database: unipept_test +# socket: /tmp/mysql.sock -github_actions: +test: <<: *default database: unipept_test url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %> From 7762557114be258c10f9d544e610a570dae3ec88 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 14:52:18 +0100 Subject: [PATCH 11/14] More debugging --- .github/workflows/test.yml | 8 ++++---- config/database.yml | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2694f3b..dedf4f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,12 +5,12 @@ on: [push] jobs: test: env: - RAILS_ENV: "test" - TEST_DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" + RAILS_ENV: "github_actions" + DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" runs-on: ubuntu-latest services: mysql: - image: mariadb + image: mariadb:10.9 env: MYSQL_DATABASE: "unipept_test" MYSQL_ROOT_PASSWORD: "unipept" @@ -19,7 +19,7 @@ jobs: - 3306:3306 options: --health-cmd "mysqladmin ping -h localhost" --health-interval 10s --health-timeout 5s --health-retries 5 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use ruby from .ruby-version uses: ruby/setup-ruby@v1 with: diff --git a/config/database.yml b/config/database.yml index c6d7292..63ca1e3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,12 +14,12 @@ development: # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. -#test: -# <<: *default -# database: unipept_test -# socket: /tmp/mysql.sock - test: + <<: *default + database: unipept_test + socket: /tmp/mysql.sock + +github_actions: <<: *default database: unipept_test url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %> From 25d6ada02134567f1ff1fb5a707fbad460a5ab5c Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 14:56:35 +0100 Subject: [PATCH 12/14] Try with correct environment --- .github/workflows/test.yml | 6 ++---- config/database.yml | 5 ----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dedf4f6..3275217 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,8 @@ on: [push] jobs: test: env: - RAILS_ENV: "github_actions" - DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" + RAILS_ENV: "test" + TEST_DATABASE_URL: "mysql2://root:unipept@127.0.0.1:3306/unipept_test" runs-on: ubuntu-latest services: mysql: @@ -25,7 +25,5 @@ jobs: with: bundler-cache: true - name: Run tests - env: - RAILS_ENV: "github_actions" run: | bundle exec rails test diff --git a/config/database.yml b/config/database.yml index 63ca1e3..1147c46 100644 --- a/config/database.yml +++ b/config/database.yml @@ -15,11 +15,6 @@ development: # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: - <<: *default - database: unipept_test - socket: /tmp/mysql.sock - -github_actions: <<: *default database: unipept_test url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %> From 30c1b161e405630a9122481c41b58f291cdcc770 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 15:09:38 +0100 Subject: [PATCH 13/14] Remove redundant text fixtures --- test/fixtures/embl_cross_references.yml | 16 ----------- test/fixtures/proteome_caches.yml | 11 -------- test/fixtures/proteome_cross_references.yml | 18 ------------- test/fixtures/proteomes.yml | 30 --------------------- test/fixtures/refseq_cross_references.yml | 16 ----------- 5 files changed, 91 deletions(-) delete mode 100644 test/fixtures/embl_cross_references.yml delete mode 100644 test/fixtures/proteome_caches.yml delete mode 100644 test/fixtures/proteome_cross_references.yml delete mode 100644 test/fixtures/proteomes.yml delete mode 100644 test/fixtures/refseq_cross_references.yml diff --git a/test/fixtures/embl_cross_references.yml b/test/fixtures/embl_cross_references.yml deleted file mode 100644 index 84d0a8f..0000000 --- a/test/fixtures/embl_cross_references.yml +++ /dev/null @@ -1,16 +0,0 @@ -# == Schema Information -# -# Table name: embl_cross_references -# -# id :integer unsigned, not null, primary key -# uniprot_entry_id :integer unsigned, not null -# protein_id :string(25) -# sequence_id :string(25) -# - -emblcrossreference1: - id: 1 - uniprot_entry_id: 1 - protein_id: "pid" - sequence_id: "sid" - diff --git a/test/fixtures/proteome_caches.yml b/test/fixtures/proteome_caches.yml deleted file mode 100644 index 1d85ccf..0000000 --- a/test/fixtures/proteome_caches.yml +++ /dev/null @@ -1,11 +0,0 @@ -# == Schema Information -# -# Table name: proteome_caches -# -# proteome_id :integer unsigned, not null, primary key -# json_sequences :text(16777215) not null -# - -proteomecache1: - proteome_id: 1 - json_sequences: "[1,1,1]" diff --git a/test/fixtures/proteome_cross_references.yml b/test/fixtures/proteome_cross_references.yml deleted file mode 100644 index beb87d5..0000000 --- a/test/fixtures/proteome_cross_references.yml +++ /dev/null @@ -1,18 +0,0 @@ -# == Schema Information -# -# Table name: proteome_cross_references -# -# id :integer unsigned, not null, primary key -# uniprot_entry_id :integer unsigned, not null -# proteome_id :integer unsigned, not null -# - -proteomecrossreference1: - id: 1 - proteome_id: 1 - uniprot_entry_id: 1 - -proteomecrossreference2: - id: 2 - proteome_id: 2 - uniprot_entry_id: 1 diff --git a/test/fixtures/proteomes.yml b/test/fixtures/proteomes.yml deleted file mode 100644 index 56deede..0000000 --- a/test/fixtures/proteomes.yml +++ /dev/null @@ -1,30 +0,0 @@ -# == Schema Information -# -# Table name: proteomes -# -# id :integer unsigned, not null, primary key -# proteome_accession_number :string(12) not null -# proteome_name :string(145) not null -# taxon_id :integer unsigned -# type_strain :binary(1) default("b'0'"), not null -# reference_proteome :binary(1) default("b'0'"), not null -# strain :string(120) -# assembly :string(45) -# name :string(225) -# - -proteome1: - id: 1 - proteome_accession_number: "don't care" - proteome_name: "proteome name" - taxon_id: 1 - type_strain: 0b0 - reference_proteome: 0b0 - strain: "strain" - assembly: "don't care" - -proteome2: - id: 2 - proteome_accession_number: "don't care" - proteome_name: "proteome2" - type_strain: 0b1 diff --git a/test/fixtures/refseq_cross_references.yml b/test/fixtures/refseq_cross_references.yml deleted file mode 100644 index a437a9e..0000000 --- a/test/fixtures/refseq_cross_references.yml +++ /dev/null @@ -1,16 +0,0 @@ -# == Schema Information -# -# Table name: refseq_cross_references -# -# id :integer unsigned, not null, primary key -# uniprot_entry_id :integer unsigned, not null -# protein_id :string(25) -# sequence_id :string(25) -# - -refseqcrossreference1: - id: 1 - uniprot_entry_id: 1 - protein_id: "r_pid" - sequence_id: "r_sid" - From 944cd9416ce156b7a389a65e86bac0a3abbc0892 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Tue, 14 Mar 2023 15:11:21 +0100 Subject: [PATCH 14/14] Explicitly init test database --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3275217..c3c2a0a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,5 @@ jobs: bundler-cache: true - name: Run tests run: | + bundle exec rails db:test:prepare bundle exec rails test