Skip to content

Commit

Permalink
Update rubocop ~> to 0.60.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 1, 2018
1 parent e0dbc22 commit c8b6dbd
Show file tree
Hide file tree
Showing 29 changed files with 48 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Metrics/LineLength:
Exclude:
- 'spec/**/*'

# https://github.com/rubocop-hq/rubocop/issues/6439
Style/AccessModifierDeclarations:
Enabled: false

Style/StringLiterals:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions app/builders/blacklight/action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize(klass, name, opts)
# doesn't already exist or the `:define_method` option is not `false`
def build
return if skip?

callback = opts.fetch(:callback, nil).inspect
validator = opts.fetch(:validator, nil).inspect
klass.class_eval <<EORUBY, __FILE__, __LINE__ + 1
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def track
def facet
@facet = blacklight_config.facet_fields[params[:id]]
raise ActionController::RoutingError, 'Not Found' unless @facet

@response = search_service.facet_field_response(@facet.key)
@display_facet = @response.aggregations[@facet.field]
@pagination = facet_paginator(@facet, @display_facet)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def require_user_authentication_provider
# When a user logs in, transfer any saved searches or bookmarks to the current_user
def transfer_guest_user_actions_to_current_user
return unless respond_to?(:current_user) && respond_to?(:guest_user) && current_user && guest_user

current_user_searches = current_user.searches.pluck(:query_params)
current_user_bookmarks = current_user.bookmarks.pluck(:document_id)

Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def start_new_search_session?
def agent_is_crawler?
crawler_proc = blacklight_config.crawler_detector
return false if crawler_proc.nil? || current_user.present?

crawler_proc.call(request)
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def render_page_title
# @option options [Array<String>] :exclude array of format shortnames to not include in the output
def render_link_rel_alternates(document = @document, options = {})
return if document.nil?

presenter(document).link_rel_alternates(options)
end

Expand Down
5 changes: 3 additions & 2 deletions app/helpers/blacklight/facets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def render_facet_partials fields = facet_field_names, options = {}
def render_facet_limit(display_facet, options = {})
field_config = facet_configuration_for_field(display_facet.name)
return unless should_render_facet?(display_facet, field_config)

options = options.dup
options[:partial] ||= facet_partial_name(display_facet)
options[:layout] ||= "facet_layout" unless options.key?(:layout)
Expand Down Expand Up @@ -77,6 +78,7 @@ def render_facet_item(facet_field, item)
# @return [Boolean]
def should_render_facet? display_facet, facet_config = nil
return false if display_facet.items.blank?

# display when show is nil or true
facet_config ||= facet_configuration_for_field(display_facet.name)
should_render_field?(facet_config, display_facet)
Expand Down Expand Up @@ -223,8 +225,7 @@ def facet_display_value field, item
facet_config.query[value][:label]
elsif facet_config.date
localization_options = facet_config.date == true ? {} : facet_config.date

l(value.to_datetime, localization_options)
l(Time.zone.parse(value), localization_options)
else
value
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/blacklight/render_constraints_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def remove_constraint_url(localized_params)
# @return [String]
def render_constraints_filters(localized_params = params)
return "".html_safe unless localized_params[:f]

path = controller.search_state_class.new(localized_params, blacklight_config, controller)
content = []
localized_params[:f].each_pair do |facet, values|
Expand All @@ -85,6 +86,7 @@ def render_filter_element(facet, values, path)

safe_join(Array(values).map do |val|
next if val.blank? # skip empty string

render_constraint_element(facet_field_label(facet_config.key),
facet_display_value(facet, val),
remove: search_action_path(path.remove_facet_params(facet, val)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def render_search_to_s_element(key, value, _options = {})
# Render the name of the facet
def render_filter_name name
return "".html_safe if name.blank?

content_tag(:span,
t('blacklight.search.filters.label', label: name),
class: 'filter-name')
Expand Down
1 change: 1 addition & 0 deletions app/models/blacklight/icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def path
# @return [String]
def file_source
raise Blacklight::Exceptions::IconNotFound, "Could not find #{path}" if file.blank?

file.source.force_encoding('UTF-8')
end

Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/blacklight/solr/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def more_like_this

def has_highlight_field? k
return false if response['highlighting'].blank? || response['highlighting'][id].blank?

response['highlighting'][id].key? k.to_s
end

Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/blacklight/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Blacklight::User
# is injected into the hosting application through ActiveRecord::Base extend
def self.included(base)
return unless base.respond_to? :has_many

base.send :has_many, :bookmarks, dependent: :destroy, as: :user
base.send :has_many, :searches, dependent: :destroy, as: :user
end
Expand Down
1 change: 1 addition & 0 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def saved?
def self.delete_old_searches(days_old)
raise ArgumentError, 'days_old is expected to be a number' unless days_old.is_a?(Numeric)
raise ArgumentError, 'days_old is expected to be greater than 0' if days_old <= 0

where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).destroy_all
end
end
2 changes: 2 additions & 0 deletions app/presenters/blacklight/rendering/link_to_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LinkToFacet < AbstractStep
extend Deprecation
def render
return next_step(values) unless config.link_to_facet

next_step(render_link)
end

Expand All @@ -18,6 +19,7 @@ def render_link

def link_field
return config.key if config.link_to_facet == true

config.link_to_facet
end

Expand Down
1 change: 1 addition & 0 deletions app/presenters/blacklight/rendering/microdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Microdata < AbstractStep
include ActionView::Helpers::TagHelper
def render
return next_step(values) unless config.itemprop

next_step(values.map { |x| itemprop(x, config.itemprop) })
end

Expand Down
1 change: 1 addition & 0 deletions app/presenters/blacklight/thumbnail_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def exists?
def thumbnail_tag image_options = {}, url_options = {}
value = thumbnail_value(image_options)
return value if value.nil? || url_options[:suppress_link]

view_context.link_to_document document, value, url_options
end

Expand Down
1 change: 1 addition & 0 deletions app/values/blacklight/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Date
def self.coerce(input)
field = String.coerce(input)
return if field.blank?

begin
::Date.parse(field)
rescue ArgumentError
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/index.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'base64'
xml.instruct!(:xml, encoding: "UTF-8")

xml.feed("xmlns" => "http://www.w3.org/2005/Atom",
"xmlns:opensearch"=>"http://a9.com/-/spec/opensearch/1.1/") do
"xmlns:opensearch" => "http://a9.com/-/spec/opensearch/1.1/") do

xml.title t('blacklight.search.page_title.title', constraints: render_search_to_page_title(params), application_name: application_name)
# an author is required, so we'll just use the app name
Expand Down Expand Up @@ -35,7 +35,7 @@ xml.feed("xmlns" => "http://www.w3.org/2005/Atom",
# used as an example in opensearch docs
xml.link( "rel" => "search",
"type" => "application/opensearchdescription+xml",
"href" => url_for(controller: 'catalog',action: 'opensearch', format: 'xml', only_path: false))
"href" => url_for(controller: 'catalog',action: 'opensearch', format: 'xml', only_path: false))

# opensearch response elements
xml.opensearch :totalResults, @response.total.to_s
Expand Down
2 changes: 1 addition & 1 deletion blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "equivalent-xml"
s.add_development_dependency "coveralls"
s.add_development_dependency "simplecov"
s.add_development_dependency "rubocop", '~> 0.56.0'
s.add_development_dependency "rubocop", '~> 0.60.0'
s.add_development_dependency "rubocop-rspec", '~> 1.8'
s.add_development_dependency "i18n-tasks"
end
2 changes: 2 additions & 0 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def self.repository_class
connection_config[:adapter].constantize
else
raise "The value for :adapter was not found in the blacklight.yml config" unless connection_config.key? :adapter

Blacklight.const_get("#{connection_config.fetch(:adapter)}/Repository".classify)
end
end
Expand All @@ -60,6 +61,7 @@ def self.default_configuration
def self.connection_config
Blacklight::RuntimeRegistry.connection_config ||= begin
raise "The #{::Rails.env} environment settings were not found in the blacklight.yml config" unless blacklight_yml[::Rails.env]

blacklight_yml[::Rails.env].symbolize_keys
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def reverse_merge(extra_params, &block)
# @return [Blacklight::Solr::Response] the solr response object
def to_hash
return @params unless params_need_update?

@params = processed_parameters
.reverse_merge(@reverse_merged_params)
.merge(@merged_params)
Expand Down Expand Up @@ -227,6 +228,7 @@ def sort
blacklight_config.sort_fields[blacklight_params[:sort]]
end
return sort_field.sort if sort_field.present?

Blacklight.logger.warn "Invalid sort field: '#{blacklight_params[:sort]}' was provided."
nil
end
Expand Down
1 change: 1 addition & 0 deletions lib/blacklight/solr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def find id, params = {}

solr_response = send_and_receive blacklight_config.document_solr_path || blacklight_config.solr_path, doc_params
raise Blacklight::Exceptions::RecordNotFound if solr_response.documents.empty?

solr_response
end

Expand Down
1 change: 1 addition & 0 deletions lib/blacklight/solr/response/spelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def collation
# FIXME: DRY up with words
spellcheck = response[:spellcheck]
return unless spellcheck && spellcheck[:suggestions]

suggestions = spellcheck[:suggestions]

if suggestions.is_a?(Array) && suggestions.index("collation")
Expand Down
1 change: 0 additions & 1 deletion lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# frozen_string_literal: true

namespace :blacklight do
Expand Down
6 changes: 4 additions & 2 deletions spec/controllers/blacklight/search_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MockConfig
allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new do |config|
config.add_search_field label: 'All Fields', qt: 'all_fields'
config.add_search_field 'title', qt: 'title_search'
end) end.to raise_error ArgumentError
end)
end .to raise_error ArgumentError
end
end

Expand All @@ -52,7 +53,8 @@ class MockConfig
allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new do |config|
config.add_search_field 'my_key', label: 'All Fields'
config.add_search_field 'my_key', label: 'title'
end) end.to raise_error RuntimeError
end)
end .to raise_error RuntimeError
end
end
end
8 changes: 4 additions & 4 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ def export_as_mock
expect(search_service).to receive(:fetch).and_return([nil, SolrDocument.new(id: 'my_fake_doc')])
end

after do
SolrDocument.registered_extensions.pop # remove the fake extension
end

it "responds to an extension-registered format properly" do
get :show, params: { id: doc_id, format: 'mock' }
expect(response).to be_successful
expect(response.body).to match /mock_export/
end

after do
SolrDocument.registered_extensions.pop # remove the fake extension
end
end # dynamic export formats
end # describe show action

Expand Down
2 changes: 2 additions & 0 deletions spec/lib/blacklight/search_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@

params.each_pair do |key, _value|
next if key == :f

expect(result_params[key]).to eq params[key]
end
end
Expand Down Expand Up @@ -191,6 +192,7 @@

params.each_pair do |key, _value|
next if key == 'f'

expect(result_params[key]).to eq params[key]
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/presenters/pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
subject { described_class.operations }

it {
is_expected.to eq [Blacklight::Rendering::HelperMethod,
Blacklight::Rendering::LinkToFacet,
Blacklight::Rendering::Microdata,
Blacklight::Rendering::Join]
expect(subject).to eq [Blacklight::Rendering::HelperMethod,
Blacklight::Rendering::LinkToFacet,
Blacklight::Rendering::Microdata,
Blacklight::Rendering::Join]
}
end
end
2 changes: 1 addition & 1 deletion spec/views/catalog/index.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
it "has pagination information" do
expect(hash).to include(meta: hash_including(pages:
{
'current_page' => 1,
'current_page' => 1,
'next_page' => 2,
'prev_page' => nil
}))
Expand Down

0 comments on commit c8b6dbd

Please sign in to comment.