From 5deb6b5affd134bf74cdfb4634c64a950852d41b Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 13:40:37 -0400 Subject: [PATCH 01/10] add circleci config --- .circleci/config.yml | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..c7ed92a --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,58 @@ +version: 2.1 + +commands: + setup_db: + steps: + - run: + name: Wait for DB + command: dockerize -wait tcp://localhost:5432 -timeout 1m + - run: + name: Database setup + command: bundle exec rake db:create && bundle exec rails db:schema:load --trace + +orbs: + ruby: circleci/ruby@2.0.0 + gitleaks: upenn-libraries/gitleaks@1.0.0 + +ruby_env_defaults: &ruby_env_defaults + RAILS_ENV: test + RACK_ENV: test + DATABASE_URL: "postgresql://postgres@localhost:5432/ethel_test" +postgres_env_defaults: &postgres_env_defaults + POSTGRES_USER: postgres + POSTGRES_PASSWORD: "" + POSTGRES_DB: ethel_test + POSTGRES_HOST_AUTH_METHOD: trust + +jobs: + rspec: + docker: + - image: cimg/ruby:3.2.2 + - image: cimg/postgres:15.2 + - image: cimg/redis:6.2 + environment: + <<: *ruby_env_defaults + <<: *postgres_env_defaults + steps: + - checkout + - ruby/install-deps + - setup_db + - ruby/rspec-test + + rubocop: + docker: + - image: cimg/ruby:3.2.2 + steps: + - checkout + - ruby/install-deps + - ruby/rubocop-check + +workflows: + version: 2 + test: + jobs: + - rspec + - rubocop + - gitleaks/check_local: + image: "quay.io/upennlibraries/gitleaks:v1.23.0" + options: "--redact --repo-config" From c775d8c6b996a4ab1f3a25cfeb1fbfd071ef6f71 Mon Sep 17 00:00:00 2001 From: "Nicky_Dover.exe" Date: Thu, 11 May 2023 13:44:18 -0400 Subject: [PATCH 02/10] Updated config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c7ed92a..2516727 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ commands: orbs: ruby: circleci/ruby@2.0.0 gitleaks: upenn-libraries/gitleaks@1.0.0 - + ruby_env_defaults: &ruby_env_defaults RAILS_ENV: test RACK_ENV: test From 4d1fb642b16011668866f6fa767462ac257a078e Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 13:46:28 -0400 Subject: [PATCH 03/10] add rubocop to test --- Gemfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Gemfile b/Gemfile index 2b7aa2d..544ca15 100644 --- a/Gemfile +++ b/Gemfile @@ -44,10 +44,5 @@ group :development, :test do gem 'factory_bot_rails', '~> 6.2' gem 'pry' gem 'rspec-rails', '~> 6.0' -end - -group :development do - # Speed up commands on slow machines / big apps [https://github.com/rails/spring] - # gem "spring" gem 'rubocop-rails', '~> 2.19' end From baecbde15dde01a599eb9a0f452ba1c9169317ce Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 13:50:43 -0400 Subject: [PATCH 04/10] add rubocop gem --- Gemfile | 1 + Gemfile.lock | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Gemfile b/Gemfile index 544ca15..e355ffb 100644 --- a/Gemfile +++ b/Gemfile @@ -44,5 +44,6 @@ group :development, :test do gem 'factory_bot_rails', '~> 6.2' gem 'pry' gem 'rspec-rails', '~> 6.0' + gem 'rubocop-discourse', '~> 3.2' gem 'rubocop-rails', '~> 2.19' end diff --git a/Gemfile.lock b/Gemfile.lock index a47461b..9c6005c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -258,10 +258,21 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.28.1) parser (>= 3.2.1.0) + rubocop-capybara (2.18.0) + rubocop (~> 1.41) + rubocop-discourse (3.2.0) + rubocop (>= 1.1.0) + rubocop-rspec (>= 2.0.0) + rubocop-factory_bot (2.22.0) + rubocop (~> 1.33) rubocop-rails (2.19.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-rspec (2.22.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) signet (0.17.0) @@ -297,6 +308,7 @@ DEPENDENCIES rack-cors rails (~> 7.0.4, >= 7.0.4.3) rspec-rails (~> 6.0) + rubocop-discourse (~> 3.2) rubocop-rails (~> 2.19) tzinfo-data From b225997e0f86d149c3c97f664396d8a205fba74f Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 14:15:19 -0400 Subject: [PATCH 05/10] try new circleci config --- .circleci/config.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2516727..c42a948 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,22 +13,22 @@ commands: orbs: ruby: circleci/ruby@2.0.0 gitleaks: upenn-libraries/gitleaks@1.0.0 - + ruby_env_defaults: &ruby_env_defaults RAILS_ENV: test RACK_ENV: test - DATABASE_URL: "postgresql://postgres@localhost:5432/ethel_test" + DATABASE_URL: "postgresql://postgres@localhost:5432/ethel-test" postgres_env_defaults: &postgres_env_defaults POSTGRES_USER: postgres POSTGRES_PASSWORD: "" - POSTGRES_DB: ethel_test + POSTGRES_DB: ethel-test POSTGRES_HOST_AUTH_METHOD: trust jobs: rspec: docker: - - image: cimg/ruby:3.2.2 - - image: cimg/postgres:15.2 + - image: cimg/ruby:3.2.0 + - image: cimg/postgres:14.6 - image: cimg/redis:6.2 environment: <<: *ruby_env_defaults @@ -41,7 +41,7 @@ jobs: rubocop: docker: - - image: cimg/ruby:3.2.2 + - image: cimg/ruby:3.2.0 steps: - checkout - ruby/install-deps From 93e81856847c6420b925249165b974efb0ff5db6 Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 14:16:19 -0400 Subject: [PATCH 06/10] upgrade ruby version --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c42a948..df05d84 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ postgres_env_defaults: &postgres_env_defaults jobs: rspec: docker: - - image: cimg/ruby:3.2.0 + - image: cimg/ruby:3.2.2 - image: cimg/postgres:14.6 - image: cimg/redis:6.2 environment: @@ -41,7 +41,7 @@ jobs: rubocop: docker: - - image: cimg/ruby:3.2.0 + - image: cimg/ruby:3.2.2 steps: - checkout - ruby/install-deps From 2f2ee2d4a08c607888c79080065e3d5cef93a853 Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 14:18:26 -0400 Subject: [PATCH 07/10] add rspec_junit_formatter --- Gemfile | 2 ++ Gemfile.lock | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index e355ffb..31199e2 100644 --- a/Gemfile +++ b/Gemfile @@ -46,4 +46,6 @@ group :development, :test do gem 'rspec-rails', '~> 6.0' gem 'rubocop-discourse', '~> 3.2' gem 'rubocop-rails', '~> 2.19' + gem "rspec_junit_formatter", "~> 0.6.0" end + diff --git a/Gemfile.lock b/Gemfile.lock index 9c6005c..fd7f8b0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -246,6 +246,8 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.0) + rspec_junit_formatter (0.6.0) + rspec-core (>= 2, < 4, != 2.12.0) rubocop (1.50.2) json (~> 2.3) parallel (~> 1.10) @@ -308,6 +310,7 @@ DEPENDENCIES rack-cors rails (~> 7.0.4, >= 7.0.4.3) rspec-rails (~> 6.0) + rspec_junit_formatter (~> 0.6.0) rubocop-discourse (~> 3.2) rubocop-rails (~> 2.19) tzinfo-data From b91bf0a8c3bed1c4ad68d8957daf9771d3bc22ec Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 20:55:11 -0400 Subject: [PATCH 08/10] reject empty params --- app/controllers/items_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index c55a236..90dc082 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -2,7 +2,7 @@ class ItemsController < ApplicationController def index - permitted_params = params.permit(:year, :item_number, :item_text, :points, :rating) + permitted_params = params.permit(:year, :item_number, :item_text, :points, :rating).reject{|_, v| v.blank?} render json: Item.filter_by_params(permitted_params) end end From 8bc4dcbb24fc5b336697438d0b732f5bc34395c3 Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Thu, 11 May 2023 21:28:21 -0400 Subject: [PATCH 09/10] key transform --- Gemfile | 2 ++ Gemfile.lock | 9 +++++++++ app/serializers/item_serializer.rb | 3 +++ config/initializers/serializers.rb | 1 + 4 files changed, 15 insertions(+) create mode 100644 app/serializers/item_serializer.rb create mode 100644 config/initializers/serializers.rb diff --git a/Gemfile b/Gemfile index 31199e2..869de3b 100644 --- a/Gemfile +++ b/Gemfile @@ -49,3 +49,5 @@ group :development, :test do gem "rspec_junit_formatter", "~> 0.6.0" end + +gem "active_model_serializers", "~> 0.10.13" diff --git a/Gemfile.lock b/Gemfile.lock index fd7f8b0..b80f6a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,11 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_model_serializers (0.10.13) + actionpack (>= 4.1, < 7.1) + activemodel (>= 4.1, < 7.1) + case_transform (>= 0.2) + jsonapi-renderer (>= 0.1.1.beta1, < 0.3) activejob (7.0.4.3) activesupport (= 7.0.4.3) globalid (>= 0.3.6) @@ -72,6 +77,8 @@ GEM bootsnap (1.16.0) msgpack (~> 1.2) builder (3.2.4) + case_transform (0.2) + activesupport coderay (1.1.3) concurrent-ruby (1.2.2) crass (1.0.6) @@ -144,6 +151,7 @@ GEM irb (1.6.4) reline (>= 0.3.0) json (2.6.3) + jsonapi-renderer (0.2.2) jwt (2.7.0) loofah (2.21.1) crass (~> 1.0.2) @@ -300,6 +308,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + active_model_serializers (~> 0.10.13) bootsnap debug factory_bot_rails (~> 6.2) diff --git a/app/serializers/item_serializer.rb b/app/serializers/item_serializer.rb new file mode 100644 index 0000000..6c0b9c0 --- /dev/null +++ b/app/serializers/item_serializer.rb @@ -0,0 +1,3 @@ +class ItemSerializer < ActiveModel::Serializer + attributes :id, :year, :item_number, :item_number_addendum, :original_item, :spellchecked_item, :special_event, :points, :point_value, :rating, :comment, :errata +end diff --git a/config/initializers/serializers.rb b/config/initializers/serializers.rb new file mode 100644 index 0000000..95443fd --- /dev/null +++ b/config/initializers/serializers.rb @@ -0,0 +1 @@ +ActiveModelSerializers.config.key_transform = :camel_lower \ No newline at end of file From cc60f02d5e745bf484e2b9981c38bf36828cf2fe Mon Sep 17 00:00:00 2001 From: Nicky Dover Date: Fri, 12 May 2023 12:30:00 -0400 Subject: [PATCH 10/10] try disabling obsolete methods --- .rubocop.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 635fc6d..2a256a4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,9 +11,18 @@ Style/Documentation: Metrics/ClassLength: Enabled: false +Metrics/LineLength: + Enabled: false + Metrics/ModuleLength: Enabled: false +Layout/IndentArray: + Enabled: false + +Layout/IndentHash: + Enabled: false + Layout/LineLength: Enabled: false