diff --git a/.rubocop.yml b/.rubocop.yml index f7996f0af4..9b7790015e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,8 @@ inherit_from: .rubocop_todo.yml -require: rubocop-rspec +require: + - rubocop-rspec + - rubocop-rails AllCops: TargetRubyVersion: 2.5 diff --git a/Gemfile b/Gemfile index f35722314a..c9d56f4cc4 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,8 @@ group :test, :development do gem 'rack-console' gem 'rails-controller-testing' gem 'rspec-rails' - gem 'rubocop', '~> 0.65.0' + gem 'rubocop', '~> 0.74.0' + gem 'rubocop-rails' gem 'rubocop-rspec', '~> 1.32.0' gem 'simplecov' gem 'webmock' diff --git a/Gemfile.lock b/Gemfile.lock index 43848f0077..6b4f60d1ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -266,9 +266,7 @@ GEM parallel (1.17.0) parser (2.6.4.0) ast (~> 2.4.0) - powerpack (0.1.2) progressbar (1.10.1) - psych (3.1.0) public_suffix (4.0.1) puma (3.12.1) rack (2.0.7) @@ -355,15 +353,16 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.2) - rubocop (0.65.0) + rubocop (0.74.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) - psych (>= 3.1.0) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) + unicode-display_width (>= 1.4.0, < 1.7) + rubocop-rails (2.3.2) + rack (>= 1.1) + rubocop (>= 0.72.0) rubocop-rspec (1.32.0) rubocop (>= 0.60.0) ruby-cache (0.3.0) @@ -423,7 +422,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.6) - unicode-display_width (1.4.1) + unicode-display_width (1.6.0) uuidtools (2.1.5) webmock (3.7.1) addressable (>= 2.3.6) @@ -463,7 +462,8 @@ DEPENDENCIES rails-controller-testing rest-client rspec-rails - rubocop (~> 0.65.0) + rubocop (~> 0.74.0) + rubocop-rails rubocop-rspec (~> 1.32.0) ruby-cache (~> 0.3.0) simplecov diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ad0c85cfd6..74a6f00527 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,7 +22,7 @@ class ApplicationController < ActionController::API # Ensure a valid token is present, or renders "401: Not Authorized" def check_auth_token token = decoded_auth_token - return render json: { error: 'Not Authorized' }, status: 401 unless token + return render json: { error: 'Not Authorized' }, status: :unauthorized unless token Honeybadger.context(invoked_by: token[:sub]) end diff --git a/app/controllers/embargoes_controller.rb b/app/controllers/embargoes_controller.rb index 154212d7b4..6d10c2ab28 100644 --- a/app/controllers/embargoes_controller.rb +++ b/app/controllers/embargoes_controller.rb @@ -11,6 +11,6 @@ def update @item.events.add_event('Embargo', params[:requesting_user], 'Embargo date modified') head :no_content rescue ArgumentError => e - render status: 422, plain: e.message + render status: :unprocessable_entity, plain: e.message end end diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 768250f044..e908a3d50a 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -4,15 +4,15 @@ class ObjectsController < ApplicationController before_action :load_item, except: [:create] rescue_from(Dor::ParameterError) do |e| - render status: 400, plain: e.message + render status: :bad_request, plain: e.message end rescue_from(Dor::DuplicateIdError) do |e| - render status: 409, plain: e.message, location: object_location(e.pid) + render status: :conflict, plain: e.message, location: object_location(e.pid) end rescue_from(DublinCoreService::CrosswalkError) do |e| - render status: 500, plain: e.message + render status: :internal_server_error, plain: e.message end # Register new objects in DOR @@ -21,14 +21,14 @@ def create begin reg_response = RegistrationService.create_from_request(create_params) rescue ArgumentError => e - return render status: 422, plain: e.message + return render status: :unprocessable_entity, plain: e.message end Rails.logger.info(reg_response) pid = reg_response[:pid] respond_to do |format| - format.all { render status: 201, location: object_location(pid), plain: Dor::RegistrationResponse.new(reg_response).to_txt } - format.json { render status: 201, location: object_location(pid), json: Dor::RegistrationResponse.new(reg_response) } + format.all { render status: :created, location: object_location(pid), plain: Dor::RegistrationResponse.new(reg_response).to_txt } + format.json { render status: :created, location: object_location(pid), json: Dor::RegistrationResponse.new(reg_response) } end end @@ -62,7 +62,7 @@ def notify_goobi response = Dor::Goobi.new(@item).register proxy_rest_client_response(response) rescue RestClient::Conflict => e - render status: 409, plain: e.http_body + render status: :conflict, plain: e.http_body end # You can post a release tag as JSON in the body to add a release tag to an item. @@ -80,7 +80,7 @@ def release_tags @item.save head :created else - render status: 400, plain: "A release attribute is required in the JSON, and its value must be either 'true' or 'false'. You sent '#{raw_params[:release]}'" + render status: :bad_request, plain: "A release attribute is required in the JSON, and its value must be either 'true' or 'false'. You sent '#{raw_params[:release]}'" end end diff --git a/app/controllers/sdr_controller.rb b/app/controllers/sdr_controller.rb index b10e09baa3..863a8496be 100644 --- a/app/controllers/sdr_controller.rb +++ b/app/controllers/sdr_controller.rb @@ -3,7 +3,7 @@ class SdrController < ApplicationController def cm_inv_diff unless %w(all shelve preserve publish).include?(params[:subset].to_s) - render status: 400, plain: "Invalid subset value: #{params[:subset]}" + render status: :bad_request, plain: "Invalid subset value: #{params[:subset]}" return end diff --git a/app/controllers/workspaces_controller.rb b/app/controllers/workspaces_controller.rb index 486ddec080..9be1a54d30 100644 --- a/app/controllers/workspaces_controller.rb +++ b/app/controllers/workspaces_controller.rb @@ -3,7 +3,7 @@ # Handles API routes for managing the DOR workspace class WorkspacesController < ApplicationController rescue_from(DruidTools::SameContentExistsError, DruidTools::DifferentContentExistsError) do |e| - render status: 409, plain: e.message + render status: :conflict, plain: e.message end # POST /v1/objects/:druid/workspace diff --git a/spec/services/cleanup_service_spec.rb b/spec/services/cleanup_service_spec.rb index 9c8ee8d639..5e15614c03 100644 --- a/spec/services/cleanup_service_spec.rb +++ b/spec/services/cleanup_service_spec.rb @@ -24,8 +24,8 @@ workitem_pathname.rmtree if workitem_pathname.exist? export_pathname = Pathname(Settings.cleanup.local_export_home) export_pathname.rmtree if export_pathname.exist? - bag_pathname = export_pathname.join(druid.split(':').last) - tarfile_pathname = export_pathname.join(bag_pathname + '.tar') + bag_pathname = export_pathname.join(druid.split(':').last) + tarfile_pathname = export_pathname.join(bag_pathname + '.tar') workitem_pathname.join('content').mkpath workitem_pathname.join('temp').mkpath diff --git a/spec/services/public_desc_metadata_service_spec.rb b/spec/services/public_desc_metadata_service_spec.rb index c10fb20a29..089073e203 100644 --- a/spec/services/public_desc_metadata_service_spec.rb +++ b/spec/services/public_desc_metadata_service_spec.rb @@ -118,7 +118,7 @@ doc = Nokogiri::XML(xml) expect(doc.encoding).to eq('UTF-8') expect(doc.xpath('//comment()').size).to eq 0 - collections = doc.search('//mods:relatedItem/mods:typeOfResource[@collection=\'yes\']') + collections = doc.search('//mods:relatedItem/mods:typeOfResource[@collection=\'yes\']') collection_title = doc.search('//mods:relatedItem/mods:titleInfo/mods:title') collection_uri = doc.search('//mods:relatedItem/mods:location/mods:url') expect(collections.length).to eq 1 @@ -147,7 +147,7 @@ it 'handles mods as the default namespace' do doc = Nokogiri::XML(xml) - collections = doc.search('//xmlns:relatedItem/xmlns:typeOfResource[@collection=\'yes\']') + collections = doc.search('//xmlns:relatedItem/xmlns:typeOfResource[@collection=\'yes\']') collection_title = doc.search('//xmlns:relatedItem/xmlns:titleInfo/xmlns:title') collection_uri = doc.search('//xmlns:relatedItem/xmlns:location/xmlns:url') expect(collections.length).to eq 1