diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..78f31d17a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:9.4 + ports: ["5432:5432"] + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: timeoverflow_test + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Run tests + env: + RAILS_ENV: test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + run: | + bundle exec rails db:setup + bundle exec rspec + - name: Publish code coverage + uses: paambaati/codeclimate-action@v3.2.0 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageLocations: ${{ github.workspace }}/coverage/coverage.json:simplecov diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d1259e700..000000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: ruby -dist: bionic -cache: bundler -services: - - postgresql -addons: - postgresql: "9.4" - chrome: stable -bundler_args: '--without development' -env: - global: - - DATABASE_URL=postgres://postgres@localhost/timeoverflow_test - - CC_TEST_REPORTER_ID=025bc15a0fa9afa52d86ee24fea845cf1d363f48a466bcf2cef8ab80c29acb28 -before_script: - - psql -c 'create database timeoverflow_test;' -U postgres - - psql -U postgres -q -d timeoverflow_test -f db/structure.sql - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build -after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT diff --git a/Gemfile b/Gemfile index e5c4a91f1..a8eb95e5c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby File.read('.ruby-version').strip +ruby ">= #{File.read('.ruby-version').strip}" gem 'rails', '~> 6.1.1' gem 'rails-i18n', '~> 6.0.0' @@ -10,7 +10,7 @@ gem 'activeadmin', '~> 2.9.0' gem 'bootsnap', '~> 1.12.0', require: false gem 'has_scope', '~> 0.7.2' gem 'pundit', '~> 2.1.0' -gem 'pg', '~> 1.2.1' +gem 'pg', '~> 1.4' gem 'json_translate', '~> 4.0.0' gem 'devise', '~> 4.7.1' gem 'http_accept_language', '~> 2.1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 687ceac58..a471be099 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -239,7 +239,7 @@ GEM parser (3.0.1.1) ast (~> 2.4.1) pdf-core (0.9.0) - pg (1.2.3) + pg (1.4.6) pg_search (2.3.5) activerecord (>= 5.2) activesupport (>= 5.2) @@ -450,7 +450,7 @@ DEPENDENCIES letter_opener (~> 1.7.0) listen (~> 3.2.0) localeapp (~> 3.1) - pg (~> 1.2.1) + pg (~> 1.4) pg_search (~> 2.3.5) prawn (~> 2.4.0) prawn-table (~> 0.2.2) diff --git a/README.md b/README.md index d3a7233ce..c08cc6ea1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # TimeOverflow [![View performance data on Skylight](https://badges.skylight.io/problem/grDTNuzZRnyu.svg)](https://oss.skylight.io/app/applications/grDTNuzZRnyu) -[![Build Status](https://travis-ci.com/coopdevs/timeoverflow.svg?branch=develop)](https://travis-ci.com/coopdevs/timeoverflow) +[![Build Status](https://github.com/coopdevs/timeoverflow/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/coopdevs/timeoverflow/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/f82c6d98a2441c84f2ef/maintainability)](https://codeclimate.com/github/coopdevs/timeoverflow/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/f82c6d98a2441c84f2ef/test_coverage)](https://codeclimate.com/github/coopdevs/timeoverflow/test_coverage) diff --git a/config/database.yml b/config/database.yml index ea70e91a2..a840d2a02 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,20 +1,6 @@ -# If you want to change this file, please keep the changes in your working -# copy by using -# -# git update-index --skip-worktree config/database.yml -# -# or just use DATABASE_URL, in which case Rails will happily skip the whole -# file. -# -# See https://github.com/coopdevs/timeoverflow/wiki/Keeping-your-local-files -# for more information -# - defaults: &defaults adapter: postgresql - username: <%= ENV['DATABASE_USER'] %> # default is null - collation: 'es_ES.UTF-8' - ctype: 'es_ES.UTF-8' + username: <%= ENV['DATABASE_USER'] || ENV["POSTGRES_USER"] %> template: 'template0' encoding: 'UTF8' @@ -24,12 +10,18 @@ development: test: <<: *defaults - database: 'timeoverflow_test' + database: timeoverflow_test + host: localhost + password: <%= ENV['DATABASE_PASSWORD'] || ENV["POSTGRES_PASSWORD"] %> staging: <<: *defaults + collation: 'es_ES.UTF-8' + ctype: 'es_ES.UTF-8' database: <%= ENV.fetch('DATABASE_NAME', 'timeoverflow_staging') %> production: <<: *defaults + collation: 'es_ES.UTF-8' + ctype: 'es_ES.UTF-8' database: <%= ENV.fetch('DATABASE_NAME', 'timeoverflow_production') %> diff --git a/db/migrate/20230312231058_migrate_hstore_to_json.rb b/db/migrate/20230312231058_migrate_hstore_to_json.rb new file mode 100644 index 000000000..7ab08b7af --- /dev/null +++ b/db/migrate/20230312231058_migrate_hstore_to_json.rb @@ -0,0 +1,15 @@ +class MigrateHstoreToJson < ActiveRecord::Migration[6.1] + def up + rename_column :categories, :name_translations, :name_translations_hstore + add_column :categories, :name_translations, :jsonb, default: {}, null: false, index: { using: 'gin' } + execute 'UPDATE "categories" SET "name_translations" = json_object(hstore_to_matrix("name_translations_hstore"))::jsonb' + remove_column :categories, :name_translations_hstore + end + + def down + rename_column :categories, :name_translations, :name_translations_jsonb + add_column :categories, :name_translations, :hstore, default: {}, null: false + execute 'UPDATE "categories" SET "name_translations" = (SELECT hstore(key, value) FROM jsonb_each_text("name_translations_jsonb"))' + remove_column :categories, :name_translations_jsonb + end +end diff --git a/db/structure.sql b/db/structure.sql index 8ad16f15b..2ce681d0f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -158,7 +158,7 @@ ALTER SEQUENCE public.active_admin_comments_id_seq OWNED BY public.active_admin_ -- --- Name: active_storage_attachments; Type: TABLE; Schema: public; Owner: - +-- Name: active_storage_attachments; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.active_storage_attachments ( @@ -191,7 +191,7 @@ ALTER SEQUENCE public.active_storage_attachments_id_seq OWNED BY public.active_s -- --- Name: active_storage_blobs; Type: TABLE; Schema: public; Owner: - +-- Name: active_storage_blobs; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.active_storage_blobs ( @@ -227,7 +227,7 @@ ALTER SEQUENCE public.active_storage_blobs_id_seq OWNED BY public.active_storage -- --- Name: active_storage_variant_records; Type: TABLE; Schema: public; Owner: - +-- Name: active_storage_variant_records; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.active_storage_variant_records ( @@ -257,7 +257,7 @@ ALTER SEQUENCE public.active_storage_variant_records_id_seq OWNED BY public.acti -- --- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - +-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.ar_internal_metadata ( @@ -276,7 +276,7 @@ CREATE TABLE public.categories ( id integer NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone, - name_translations public.hstore + name_translations jsonb DEFAULT '{}'::jsonb NOT NULL ); @@ -822,7 +822,7 @@ ALTER TABLE ONLY public.active_admin_comments -- --- Name: active_storage_attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_attachments @@ -830,7 +830,7 @@ ALTER TABLE ONLY public.active_storage_attachments -- --- Name: active_storage_blobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_blobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_blobs @@ -838,7 +838,7 @@ ALTER TABLE ONLY public.active_storage_blobs -- --- Name: active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.active_storage_variant_records @@ -846,7 +846,7 @@ ALTER TABLE ONLY public.active_storage_variant_records -- --- Name: ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.ar_internal_metadata @@ -977,28 +977,28 @@ CREATE INDEX index_active_admin_comments_on_resource_type_and_resource_id ON pub -- --- Name: index_active_storage_attachments_on_blob_id; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_storage_attachments_on_blob_id; Type: INDEX; Schema: public; Owner: - -- CREATE INDEX index_active_storage_attachments_on_blob_id ON public.active_storage_attachments USING btree (blob_id); -- --- Name: index_active_storage_attachments_uniqueness; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_storage_attachments_uniqueness; Type: INDEX; Schema: public; Owner: - -- CREATE UNIQUE INDEX index_active_storage_attachments_uniqueness ON public.active_storage_attachments USING btree (record_type, record_id, name, blob_id); -- --- Name: index_active_storage_blobs_on_key; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_storage_blobs_on_key; Type: INDEX; Schema: public; Owner: - -- CREATE UNIQUE INDEX index_active_storage_blobs_on_key ON public.active_storage_blobs USING btree (key); -- --- Name: index_active_storage_variant_records_uniqueness; Type: INDEX; Schema: public; Owner: - +-- Name: index_active_storage_variant_records_uniqueness; Type: INDEX; Schema: public; Owner: - -- CREATE UNIQUE INDEX index_active_storage_variant_records_uniqueness ON public.active_storage_variant_records USING btree (blob_id, variation_digest); @@ -1285,6 +1285,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210423193937'), ('20210424174640'), ('20210502160343'), -('20210503201944'); +('20210503201944'), +('20230312231058'); diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8045aedaa..1ab96aa99 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,16 @@ -require 'simplecov' -SimpleCov.start 'rails' - ENV["RAILS_ENV"] ||= 'test' ENV["ADMINS"] = "admin@timeoverflow.org" +require 'simplecov' + +SimpleCov.formatter = if ENV["CI"] + require "simplecov_json_formatter" + SimpleCov::Formatter::JSONFormatter +else + SimpleCov::Formatter::HTMLFormatter +end +SimpleCov.start 'rails' + require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'capybara/rails'