From c020dd4770afd13695f7bb53f70babba8c4dfaa4 Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Wed, 21 Jun 2023 08:54:16 -0500 Subject: [PATCH 1/6] add rubocop gem --- Gemfile | 2 ++ Gemfile.lock | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Gemfile b/Gemfile index 9b2004dc..ecd0ed16 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,8 @@ group :development, :test do gem 'geckodriver-helper' gem 'puma' gem 'rspec-rails' + gem 'rubocop', require: false + gem 'rubocop-rspec', require: false gem 'selenium-webdriver' gem 'simplecov' gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index f822f813..b3415577 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,7 @@ GEM archive-zip (0.12.0) io-like (~> 0.3.0) arel (9.0.0) + ast (2.4.2) autoprefixer-rails (9.8.6.4) execjs bcrypt (3.1.16) @@ -270,9 +271,14 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) + parallel (1.23.0) + parser (3.2.2.3) + ast (~> 2.4.1) + racc public_suffix (4.0.6) puma (5.0.0) nio4r (~> 2.0) + racc (1.7.1) rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -330,6 +336,20 @@ GEM rspec-mocks (~> 3.9) rspec-support (~> 3.9) rspec-support (3.9.3) + rubocop (0.92.0) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.5.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-rspec (1.44.1) + rubocop (~> 0.87) + rubocop-ast (>= 0.7.1) ruby-progressbar (1.10.1) rubyzip (2.3.2) sanitize (5.2.1) @@ -384,6 +404,7 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unicode-display_width (1.8.0) warden (1.2.9) rack (>= 2.0.9) web-console (3.7.0) @@ -422,6 +443,8 @@ DEPENDENCIES rainbow rsolr rspec-rails + rubocop + rubocop-rspec sass-rails sdoc selenium-webdriver From 18b2e1e3b114566a28a53e9739a563360a22e4b8 Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Wed, 21 Jun 2023 09:16:06 -0500 Subject: [PATCH 2/6] lint helpers --- .rubocop.yml | 6 ++++++ app/helpers/application_helper.rb | 24 +++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..e0e4721c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +AllCops: + Exclude: + - 'db/**/*' + - 'bin/*' + - 'config/**/*' + - 'vendor/**/*' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 293b8f0f..a4728d84 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,8 @@ -module ApplicationHelper +# frozen_string_literal: true +module ApplicationHelper def construct_curated_maps - maps = NyuGeoblacklight::CuratedCollections.maps.shuffle[0..2] + maps = NyuGeoblacklight::CuratedCollections.maps.sample(3) toReturn = "

Featured Maps

" @@ -18,23 +19,18 @@ def download_text_alt(format) end def proper_case_format_alt(format) - if t "geoblacklight.formats.#{format.downcase}" - t "geoblacklight.formats.#{format.downcase}" - else - format - end + t "geoblacklight.formats.#{format.downcase}" || format end def download_text_laefer_alt(format) - "#{format}".html_safe + format.to_s.html_safe end - def create_map_portion(map) toReturn = "
" - toReturn += (image_tag "thumb/#{map[:slug]}.jpg", {:class => "card-img-top", :"data-svg-fallback" => "#{image_path('real250.png')}", :alt => 'NYU Spatial Data Repository'}) + toReturn += (image_tag "thumb/#{map[:slug]}.jpg", { class: 'card-img-top', "data-svg-fallback": image_path('real250.png').to_s, alt: 'NYU Spatial Data Repository' }) toReturn += "

#{map[:title]}

@@ -45,7 +41,7 @@ def create_map_portion(map) end def construct_curated_collections - collections = NyuGeoblacklight::CuratedCollections.collections.shuffle[0..1] + collections = NyuGeoblacklight::CuratedCollections.collections.sample(2) toReturn = "

Featured Collections

" @@ -58,7 +54,7 @@ def construct_curated_collections end def create_collection_portion(collection) - toReturn = link_to search_catalog_path({f: collection[:f]}), {class: "curated-card"} do + toReturn = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do "
@@ -87,7 +83,7 @@ def construct_recent_collections end def create_recent_portion(collection) - toReturn = link_to search_catalog_path({f: collection[:f]}), {class: "curated-card"} do + toReturn = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do "
@@ -101,6 +97,4 @@ def create_recent_portion(collection) end toReturn.html_safe end - - end From 48a02f9cbffb5e12c0f1dc1fa240b68f658385b2 Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Wed, 21 Jun 2023 09:19:06 -0500 Subject: [PATCH 3/6] lint controllers --- app/controllers/application_controller.rb | 8 +- app/controllers/catalog_controller.rb | 51 +++--- app/controllers/concerns/nyu_slug_concern.rb | 9 +- .../users/omniauth_callbacks_controller.rb | 159 +++++++++--------- app/controllers/wms_controller.rb | 2 + 5 files changed, 112 insertions(+), 117 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 752c0c38..82bd482b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base # Adds a few additional behaviors into the application controller include Blacklight::Controller @@ -9,7 +11,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception # Alias new_session_path as login_path for default devise config - def new_session_path(scope) + def new_session_path(_scope) login_path end @@ -20,7 +22,7 @@ def after_sign_in_path_for(resource) def current_user_dev @current_user ||= User.find_by_username('admin') || User.new end - alias_method :current_user, :current_user_dev if Rails.env.development? + alias current_user current_user_dev if Rails.env.development? # After signing out from the local application, # redirect to the logout path for the Login app @@ -33,7 +35,7 @@ def after_sign_out_path_for(resource_or_scope) end def logout_path - "https://login.library.nyu.edu/logout" + 'https://login.library.nyu.edu/logout' end private :logout_path end diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 2d3fd08f..720d4488 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -1,8 +1,8 @@ -# -*- encoding : utf-8 -*- +# frozen_string_literal: true + require 'blacklight/catalog' class CatalogController < ApplicationController - # include BlacklightRangeLimit::ControllerOverride include Blacklight::Catalog @@ -11,17 +11,17 @@ class CatalogController < ApplicationController configure_blacklight do |config| ## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params config.default_solr_params = { - :start => 0, - :rows => 10, - 'q.alt' => '*:*' + :start => 0, + :rows => 10, + 'q.alt' => '*:*' } ## Default parameters to send on single-document requests to Solr. These settings are the Blackligt defaults (see SolrHelper#solr_doc_params) or ## parameters included in the Blacklight-jetty document requestHandler. # config.default_document_solr_params = { - :qt => 'document', - :q => '{!raw f=layer_slug_s v=$id}' + qt: 'document', + q: '{!raw f=layer_slug_s v=$id}' } config.index.document_presenter_class = Geoblacklight::DocumentPresenter @@ -71,19 +71,19 @@ class CatalogController < ApplicationController # :years_25 => { :label => 'within 25 Years', :fq => "pub_date:[#{Time.now.year - 25 } TO *]" } # } - config.add_facet_field Settings.FIELDS.PROVENANCE, label: 'Institution', limit: 8, partial: "icon_facet" - config.add_facet_field Settings.FIELDS.CREATOR, :label => 'Author', :limit => 8 - config.add_facet_field Settings.FIELDS.PUBLISHER, :label => 'Publisher', :limit => 8 - config.add_facet_field Settings.FIELDS.SUBJECT, :label => 'Subject', :limit => 8 - config.add_facet_field Settings.FIELDS.SPATIAL_COVERAGE, :label => 'Place', :limit => 8 - config.add_facet_field Settings.FIELDS.PART_OF, :label => 'Collection', :limit => 8 - config.add_facet_field Settings.FIELDS.SOURCE, :label => 'Source Dataset', :limit => 0 + config.add_facet_field Settings.FIELDS.PROVENANCE, label: 'Institution', limit: 8, partial: 'icon_facet' + config.add_facet_field Settings.FIELDS.CREATOR, label: 'Author', limit: 8 + config.add_facet_field Settings.FIELDS.PUBLISHER, label: 'Publisher', limit: 8 + config.add_facet_field Settings.FIELDS.SUBJECT, label: 'Subject', limit: 8 + config.add_facet_field Settings.FIELDS.SPATIAL_COVERAGE, label: 'Place', limit: 8 + config.add_facet_field Settings.FIELDS.PART_OF, label: 'Collection', limit: 8 + config.add_facet_field Settings.FIELDS.SOURCE, label: 'Source Dataset', limit: 0 - config.add_facet_field Settings.FIELDS.YEAR, :label => 'Year', :limit => 10 + config.add_facet_field Settings.FIELDS.YEAR, label: 'Year', limit: 10 - config.add_facet_field Settings.FIELDS.RIGHTS, label: 'Access', limit: 8, partial: "icon_facet" - config.add_facet_field Settings.FIELDS.GEOM_TYPE, label: 'Data type', limit: 8, partial: "icon_facet" - config.add_facet_field Settings.FIELDS.FILE_FORMAT, :label => 'Format', :limit => 8 + config.add_facet_field Settings.FIELDS.RIGHTS, label: 'Access', limit: 8, partial: 'icon_facet' + config.add_facet_field Settings.FIELDS.GEOM_TYPE, label: 'Data type', limit: 8, partial: 'icon_facet' + config.add_facet_field Settings.FIELDS.FILE_FORMAT, label: 'Format', limit: 8 # Have BL send all facet field names to Solr, which has been the default # previously. Simply remove these lines if you'd rather use Solr request @@ -112,8 +112,6 @@ class CatalogController < ApplicationController config.add_index_field Settings.FIELDS.DESCRIPTION, helper_method: :snippit config.add_index_field Settings.FIELDS.PUBLISHER - - # solr fields to be displayed in the show (single result) view # The ordering of the field names is the order of the display # @@ -202,10 +200,10 @@ class CatalogController < ApplicationController # label in pulldown is followed by the name of the SOLR field to sort by and # whether the sort is ascending or descending (it must be asc or desc # except in the relevancy case). - config.add_sort_field 'score desc, dc_title_sort asc', :label => 'relevance' - config.add_sort_field "#{Settings.FIELDS.YEAR} desc, dc_title_sort asc", :label => 'year' - config.add_sort_field "#{Settings.FIELDS.PUBLISHER} asc, dc_title_sort asc", :label => 'publisher' - config.add_sort_field 'dc_title_sort asc', :label => 'title' + config.add_sort_field 'score desc, dc_title_sort asc', label: 'relevance' + config.add_sort_field "#{Settings.FIELDS.YEAR} desc, dc_title_sort asc", label: 'year' + config.add_sort_field "#{Settings.FIELDS.PUBLISHER} asc, dc_title_sort asc", label: 'publisher' + config.add_sort_field 'dc_title_sort asc', label: 'title' # If there are more than this many search results, no spelling ("did you # mean") suggestion is offered. @@ -225,13 +223,8 @@ class CatalogController < ApplicationController config.basemap_provider = 'positron' - # Configuration for autocomplete suggestor config.autocomplete_enabled = true config.autocomplete_path = 'suggest' - end - - - end diff --git a/app/controllers/concerns/nyu_slug_concern.rb b/app/controllers/concerns/nyu_slug_concern.rb index 973a8642..78a00312 100644 --- a/app/controllers/concerns/nyu_slug_concern.rb +++ b/app/controllers/concerns/nyu_slug_concern.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module NyuSlugConcern extend Blacklight::Catalog @@ -5,9 +7,7 @@ module NyuSlugConcern # NYU slugs ("nyu_2451_12345") and turn them into # new style ("nyu-2451-12345") def show - if /^nyu_\d{4}_\d{5}$/.match(params[:id]) - params[:id] = params[:id].gsub("_","-") - end + params[:id] = params[:id].gsub('_', '-') if /^nyu_\d{4}_\d{5}$/.match(params[:id]) @response, @document = fetch params[:id] respond_to do |format| format.html { setup_next_and_previous_documents } @@ -15,5 +15,4 @@ def show additional_export_formats(@document, format) end end - -end \ No newline at end of file +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index cdd1a2a4..fa00277c 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -1,103 +1,102 @@ -class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController - before_action :require_valid_omniauth, only: :nyulibraries - - def nyulibraries - # Find existing or initialize new user, - # and save new attributes each time - @user = find_user_with_or_without_provider.first_or_initialize(attributes_from_omniauth) - @user.update_attributes(attributes_from_omniauth) - - if @user.persisted? - sign_in_and_redirect @user, event: :authentication - logger.info(find_message(:success, kind: "NYU Libraries")) - else - session["devise.nyulibraries_data"] = request.env["omniauth.auth"] - redirect_to root_path +# frozen_string_literal: true + +module Users + class OmniauthCallbacksController < Devise::OmniauthCallbacksController + before_action :require_valid_omniauth, only: :nyulibraries + + def nyulibraries + # Find existing or initialize new user, + # and save new attributes each time + @user = find_user_with_or_without_provider.first_or_initialize(attributes_from_omniauth) + @user.update_attributes(attributes_from_omniauth) + + if @user.persisted? + sign_in_and_redirect @user, event: :authentication + logger.info(find_message(:success, kind: 'NYU Libraries')) + else + session['devise.nyulibraries_data'] = request.env['omniauth.auth'] + redirect_to root_path + end end - end - def find_user_with_or_without_provider - @find_user_with_or_without_provider ||= (find_user_with_provider.present?) ? find_user_with_provider : find_user_without_provider - end + def find_user_with_or_without_provider + @find_user_with_or_without_provider ||= find_user_with_provider.present? ? find_user_with_provider : find_user_without_provider + end - def find_user_with_provider - @find_user_with_provider ||= User.where(username: omniauth.uid, provider: omniauth.provider) - end + def find_user_with_provider + @find_user_with_provider ||= User.where(username: omniauth.uid, provider: omniauth.provider) + end - def find_user_without_provider - @find_user_without_provider ||= User.where(username: omniauth.uid, provider: "") - end + def find_user_without_provider + @find_user_without_provider ||= User.where(username: omniauth.uid, provider: '') + end - def require_valid_omniauth - head :bad_request unless valid_omniauth? - end + def require_valid_omniauth + head :bad_request unless valid_omniauth? + end - def valid_omniauth? - omniauth.present? && omniauth.provider.to_s == 'nyulibraries' && !omniauth_aleph_identity.blank? - # Only accept users with an Aleph ID, authenticated via nyulibraries - end + def valid_omniauth? + omniauth.present? && omniauth.provider.to_s == 'nyulibraries' && !omniauth_aleph_identity.blank? + # Only accept users with an Aleph ID, authenticated via nyulibraries + end - def omniauth - @omniauth ||= request.env["omniauth.auth"] - end + def omniauth + @omniauth ||= request.env['omniauth.auth'] + end - def omniauth_provider - @omniauth_provider ||= omniauth.provider - end + def omniauth_provider + @omniauth_provider ||= omniauth.provider + end - def attributes_from_omniauth - { - provider: omniauth_provider, - email: omniauth_email, - firstname: omniauth_firstname, - lastname: omniauth_lastname, - institution_code: omniauth_institution, - aleph_id: omniauth_aleph_id, - patron_status: omniauth_patron_status - } - end + def attributes_from_omniauth + { + provider: omniauth_provider, + email: omniauth_email, + firstname: omniauth_firstname, + lastname: omniauth_lastname, + institution_code: omniauth_institution, + aleph_id: omniauth_aleph_id, + patron_status: omniauth_patron_status + } + end - def omniauth_email - @omniauth_email ||= omniauth.info.email - end + def omniauth_email + @omniauth_email ||= omniauth.info.email + end - def omniauth_firstname - @omniauth_firstname ||= omniauth.info.first_name - end + def omniauth_firstname + @omniauth_firstname ||= omniauth.info.first_name + end - def omniauth_lastname - @omniauth_lastname ||= omniauth.info.last_name - end + def omniauth_lastname + @omniauth_lastname ||= omniauth.info.last_name + end - def omniauth_institution - @omniauth_institution ||= omniauth.extra.institution_code - end + def omniauth_institution + @omniauth_institution ||= omniauth.extra.institution_code + end - def omniauth_identities - #byebug - @omniauth_identities ||= omniauth.extra.identities - end + def omniauth_identities + # byebug + @omniauth_identities ||= omniauth.extra.identities + end - def omniauth_aleph_identity - @omniauth_aleph_identity ||= omniauth_identities.find do |omniauth_identity| - omniauth_identity.provider == 'aleph' + def omniauth_aleph_identity + @omniauth_aleph_identity ||= omniauth_identities.find do |omniauth_identity| + omniauth_identity.provider == 'aleph' + end end - end - def omniauth_aleph_id - unless omniauth_aleph_identity.blank? - @omniauth_aleph_id ||= omniauth_aleph_identity.uid + def omniauth_aleph_id + @omniauth_aleph_id ||= omniauth_aleph_identity.uid unless omniauth_aleph_identity.blank? end - end - def omniauth_patron_status - unless omniauth_aleph_identity.blank? - @omniauth_patron_status ||= omniauth_aleph_identity.properties.patron_status + def omniauth_patron_status + @omniauth_patron_status ||= omniauth_aleph_identity.properties.patron_status unless omniauth_aleph_identity.blank? end - end - def failure - redirect_to root_path + def failure + redirect_to root_path + end end - end diff --git a/app/controllers/wms_controller.rb b/app/controllers/wms_controller.rb index 1ba86e93..cdce79e3 100644 --- a/app/controllers/wms_controller.rb +++ b/app/controllers/wms_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class WmsController < ApplicationController before_action :format_url def handle From d46143925b0fb56828843c44bb9a74b953952462 Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Wed, 21 Jun 2023 09:21:09 -0500 Subject: [PATCH 4/6] lint helpers --- .rubocop.yml | 10 ++++++++ app/helpers/application_helper.rb | 40 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e0e4721c..762ab30d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,3 +4,13 @@ AllCops: - 'bin/*' - 'config/**/*' - 'vendor/**/*' +Style/Documentation: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Layout/LineLength: + Enabled: false + + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a4728d84..58509305 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,15 +3,15 @@ module ApplicationHelper def construct_curated_maps maps = NyuGeoblacklight::CuratedCollections.maps.sample(3) - toReturn = "
+ to_return = "

Featured Maps

" maps.each do |map| - toReturn += create_map_portion(map) + to_return += create_map_portion(map) end - toReturn += "
+ to_return += "
" - toReturn.html_safe + to_return.html_safe end def download_text_alt(format) @@ -27,34 +27,34 @@ def download_text_laefer_alt(format) end def create_map_portion(map) - toReturn = " + to_return = "
" - toReturn += (image_tag "thumb/#{map[:slug]}.jpg", { class: 'card-img-top', "data-svg-fallback": image_path('real250.png').to_s, alt: 'NYU Spatial Data Repository' }) - toReturn += "
+ to_return += (image_tag "thumb/#{map[:slug]}.jpg", { class: 'card-img-top', "data-svg-fallback": image_path('real250.png').to_s, alt: 'NYU Spatial Data Repository' }) + to_return += "

#{map[:title]}

" - toReturn + to_return end def construct_curated_collections collections = NyuGeoblacklight::CuratedCollections.collections.sample(2) - toReturn = "
+ to_return = "

Featured Collections

" collections.each do |collection| - toReturn += create_collection_portion(collection) + to_return += create_collection_portion(collection) end - toReturn += "
+ to_return += "
" - toReturn.html_safe + to_return.html_safe end def create_collection_portion(collection) - toReturn = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do + to_return = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do "
@@ -66,24 +66,24 @@ def create_collection_portion(collection)
".html_safe end - toReturn.html_safe + to_return.html_safe end def construct_recent_collections collections = NyuGeoblacklight::CuratedCollections.recent[0..1] - toReturn = "
+ to_return = "

Recently Updated

" collections.each do |collection| - toReturn += create_recent_portion(collection) + to_return += create_recent_portion(collection) end - toReturn += "
+ to_return += "
" - toReturn.html_safe + to_return.html_safe end def create_recent_portion(collection) - toReturn = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do + to_return = link_to search_catalog_path({ f: collection[:f] }), { class: 'curated-card' } do "
@@ -95,6 +95,6 @@ def create_recent_portion(collection)
".html_safe end - toReturn.html_safe + to_return.html_safe end end From 14d7121374fb8cdc19995fef578e0b260a7130de Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Wed, 21 Jun 2023 09:23:30 -0500 Subject: [PATCH 5/6] lint tests --- .rubocop.yml | 1 + spec/factories/users.rb | 6 ++++-- spec/features/homepage_spec.rb | 2 ++ spec/features/search_spec.rb | 2 ++ spec/features/show_page_spec.rb | 20 ++++++++++---------- spec/routing/user_routing_spec.rb | 18 ++++++++++-------- spec/spec_helper.rb | 16 ++++++++-------- spec/support/controller_macros.rb | 6 ++++-- spec/support/features.rb | 4 +++- spec/support/features/session_helpers.rb | 4 +++- 10 files changed, 47 insertions(+), 32 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 762ab30d..de5da0d5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ AllCops: - 'bin/*' - 'config/**/*' - 'vendor/**/*' + Style/Documentation: Enabled: false diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 117f83a4..a2dc67bf 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + FactoryBot.define do factory :user do - sequence(:username) { |n| "OOOOOOOO" } - sequence(:email) { |n| "email-#{srand}@nyu.edu" } + sequence(:username) { |_n| 'OOOOOOOO' } + sequence(:email) { |_n| "email-#{srand}@nyu.edu" } end end diff --git a/spec/features/homepage_spec.rb b/spec/features/homepage_spec.rb index b3d651c8..fd00f839 100644 --- a/spec/features/homepage_spec.rb +++ b/spec/features/homepage_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe 'Homepage' do describe 'DOM' do it 'has Featured Collections' do diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb index b4350c66..dee9f75e 100644 --- a/spec/features/search_spec.rb +++ b/spec/features/search_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe 'Search' do describe 'Spelling suggestions' do it 'are turned on' do diff --git a/spec/features/show_page_spec.rb b/spec/features/show_page_spec.rb index 53c7907e..ecd8882f 100644 --- a/spec/features/show_page_spec.rb +++ b/spec/features/show_page_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe 'Show page' do context 'Restricted NYU result - nyu-2451-34626' do it 'the displays warning message' do @@ -35,7 +37,7 @@ it 'includes survey link' do visit solr_document_path 'nyu-2451-38684' expect(page).to have_link( - "this brief survey", href: "https://nyu.qualtrics.com/jfe/form/SV_42ddIXjT0CtaqAR" + 'this brief survey', href: 'https://nyu.qualtrics.com/jfe/form/SV_42ddIXjT0CtaqAR' ) end @@ -87,13 +89,11 @@ end end -=begin - context 'Parent/Child relationships - nyu-2451-34666' do - it 'to inlude relation links' do - visit solr_document_path 'nyu-2451-34666' - expect(page).to have_content("Data Relations") - expect(page).to have_content("Source Datasets") - end - end -=end + # context 'Parent/Child relationships - nyu-2451-34666' do + # it 'to inlude relation links' do + # visit solr_document_path 'nyu-2451-34666' + # expect(page).to have_content("Data Relations") + # expect(page).to have_content("Source Datasets") + # end + # end end diff --git a/spec/routing/user_routing_spec.rb b/spec/routing/user_routing_spec.rb index 6029dc45..884a82fc 100644 --- a/spec/routing/user_routing_spec.rb +++ b/spec/routing/user_routing_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + describe 'routes for users' do describe 'GET /users/auth/nyulibraries' do subject { get('/users/auth/nyulibraries') } it do should route_to({ - controller: 'users/omniauth_callbacks', - action: 'passthru' - }) + controller: 'users/omniauth_callbacks', + action: 'passthru' + }) end end @@ -13,19 +15,19 @@ subject { post('/users/auth/nyulibraries') } it do should route_to({ - controller: 'users/omniauth_callbacks', - action: 'passthru' - }) + controller: 'users/omniauth_callbacks', + action: 'passthru' + }) end end describe 'GET /users/auth/nyulibraries/callback' do subject { get('/users/auth/nyulibraries/callback') } - it { should route_to({controller: 'users/omniauth_callbacks', action: 'nyulibraries'}) } + it { should route_to({ controller: 'users/omniauth_callbacks', action: 'nyulibraries' }) } end describe 'POST /users/auth/nyulibraries/callback' do subject { post('/users/auth/nyulibraries/callback') } - it { should route_to({controller: 'users/omniauth_callbacks', action: 'nyulibraries'}) } + it { should route_to({ controller: 'users/omniauth_callbacks', action: 'nyulibraries' }) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index feadbcfb..ccace388 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) require 'capybara/rspec' require 'capybara/rails' require 'capybara-screenshot/rspec' @@ -31,9 +33,9 @@ ActiveRecord::Migration.maintain_test_schema! -Dir[Rails.root.join("spec", "support", "**", "*.rb")].sort.each { |file| require file } +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |file| require file } -#require_relative 'support/controller_macros' +# require_relative 'support/controller_macros' ActiveJob::Base.queue_adapter = :inline @@ -50,11 +52,9 @@ OmniAuth.config.test_mode = true config.before(:suite) do - begin - DatabaseCleaner.start - ensure - DatabaseCleaner.clean - end + DatabaseCleaner.start + ensure + DatabaseCleaner.clean end config.include Capybara::DSL diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index 3d78d567..5a055ba6 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module ControllerMacros def login_admin before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:admin] + @request.env['devise.mapping'] = Devise.mappings[:admin] sign_in FactoryBot.create(:admin) # Using factory bot as an example end end def login_user before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:user] + @request.env['devise.mapping'] = Devise.mappings[:user] user = FactoryBot.create(:user) user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the "confirmable" module sign_in user diff --git a/spec/support/features.rb b/spec/support/features.rb index 3b09b7cd..af32a579 100644 --- a/spec/support/features.rb +++ b/spec/support/features.rb @@ -1,4 +1,6 @@ -require File.expand_path('../features/session_helpers.rb', __FILE__) +# frozen_string_literal: true + +require File.expand_path('features/session_helpers.rb', __dir__) RSpec.configure do |config| config.include Features::SessionHelpers, type: :feature diff --git a/spec/support/features/session_helpers.rb b/spec/support/features/session_helpers.rb index 932cf710..3769bbbe 100644 --- a/spec/support/features/session_helpers.rb +++ b/spec/support/features/session_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'byebug' require 'ostruct' @@ -6,7 +8,7 @@ module SessionHelpers # @WIP: Authenticate # Poltergeist-friendly sign-in # Use this in feature tests - def sign_in(who = :user) + def sign_in(_who = :user) user = create(:user) extra = OpenStruct.new(identities: OpenStruct.new) From 6ab169cd04cb1a363b0b9a38a9ffa49f34042c7f Mon Sep 17 00:00:00 2001 From: mnyrop Date: Wed, 21 Jun 2023 14:51:00 -0400 Subject: [PATCH 6/6] add rubocop to ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38c31172..4be95957 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,8 +18,8 @@ jobs: uses: ruby/setup-ruby@v1 with: bundler-cache: true - # - name: Lint - # run: bundle exec rubocop + - name: Lint + run: bundle exec rubocop - name: Run tests run: | cp config/vars.yml.example config/vars.yml