diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..df05d84 --- /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:14.6 + - 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" 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 diff --git a/Gemfile b/Gemfile index 2b7aa2d..869de3b 100644 --- a/Gemfile +++ b/Gemfile @@ -44,10 +44,10 @@ 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-discourse', '~> 3.2' gem 'rubocop-rails', '~> 2.19' + gem "rspec_junit_formatter", "~> 0.6.0" end + + +gem "active_model_serializers", "~> 0.10.13" diff --git a/Gemfile.lock b/Gemfile.lock index a47461b..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) @@ -246,6 +254,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) @@ -258,10 +268,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) @@ -287,6 +308,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + active_model_serializers (~> 0.10.13) bootsnap debug factory_bot_rails (~> 6.2) @@ -297,6 +319,8 @@ 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 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 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