Skip to content

Commit

Permalink
Update rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 26, 2022
1 parent da7792c commit a12b19e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ AllCops:
- "lib/generators/blacklight/templates/**/*"
- "blacklight.gemspec"


Lint/UselessAssignment:
Exclude:
- app/presenters/blacklight/facet_item_pivot_presenter.rb # https://github.com/rubocop/rubocop/issues/11124


# engine_cart block includes conditional, not duplication
Bundler/DuplicatedGem:
Exclude:
Expand Down
3 changes: 3 additions & 0 deletions app/presenters/blacklight/facet_item_pivot_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def label
else
item_fq = label_source.respond_to?(:fq) ? label_source.fq : {}
item_fq = item_fq.symbolize_keys
# rubocop:disable Rails/Pluck
# https://github.com/rubocop/rubocop-rails/issues/842
label_value = facet_config.pivot.map(&:to_sym).map { |k| item_fq[k] }
# rubocop:enable Rails/Pluck
if label_source.respond_to?(:field)
label_value << value
else
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def facet_fields_in_group(group)

# @return [Array<String>] a list of facet groups
def facet_group_names
facet_fields.map { |_facet, opts| opts[:group] }.uniq
facet_fields.pluck(:group).uniq
end

# Add any configured facet fields to the default solr parameters hash
Expand Down
4 changes: 1 addition & 3 deletions lib/blacklight/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ class Parameters
# Sanitize the search parameters by removing unnecessary parameters
# from the provided parameters.
# @param [Hash] params parameters
# rubocop:disable Style/CollectionCompact can be removed when we drop Rails 6.0 support
def self.sanitize params
params.reject { |_k, v| v.nil? }
params.reject { |_k, v| v.nil? } # rubocop:disable Style/CollectionCompact not available in Rails 6.0
.except(:action, :controller, :id, :commit, :utf8)
end
# rubocop:enable Style/CollectionCompact

# rubocop:disable Naming/MethodParameterName
# Merge two Rails strong_params-style permissions into a single list of permitted parameters,
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/solr/response/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def facet_query_aggregations
return {} unless blacklight_config

blacklight_config.facet_fields.select { |_k, v| v.query }.each_with_object({}) do |(field_name, facet_field), hash|
salient_facet_queries = facet_field.query.map { |_k, x| x[:fq] }
salient_facet_queries = facet_field.query.pluck(:fq)
items = facet_queries.select { |k, _v| salient_facet_queries.include?(k) }.reject { |_value, hits| hits.zero? }.map do |value, hits|
salient_fields = facet_field.query.select { |_key, val| val[:fq] == value }
key = ((salient_fields.keys if salient_fields.respond_to? :keys) || salient_fields.first).first
Expand All @@ -248,7 +248,7 @@ def facet_query_aggregations
def facet_query_aggregations_from_json(facet_field)
return [] unless self['facets']

salient_facet_queries = facet_field.query.map { |_k, x| x[:fq] }
salient_facet_queries = facet_field.query.pluck(:fq)

relevant_facet_data = self['facets'].select { |k, _v| salient_facet_queries.include?(k) }.reject { |_key, data| data['count'].zero? }

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@

format = facets.find { |x| x['id'] == 'format' }

expect(format['attributes']['items'].map { |x| x['attributes'] }).to match_array([{ "value" => "Book", "hits" => 30, "label" => "Book" }])
expect(format['attributes']['items'].pluck('attributes')).to match_array([{ "value" => "Book", "hits" => 30, "label" => "Book" }])
expect(format['links']['self']).to eq facet_catalog_url(format: :json, id: 'format')
expect(format['attributes']['items'].first['links']['self']).to eq search_catalog_url(format: :json, f: { format: ['Book'] })
end

it "gets the search fields" do
expect(search_fields).to have(4).fields
expect(search_fields.map { |x| x['id'] }).to match_array %w[all_fields author subject title]
expect(search_fields.pluck('id')).to match_array %w[all_fields author subject title]
expect(search_fields.first['links']['self']).to eq search_catalog_url(format: :json, search_field: 'all_fields')
end

describe "facets" do
let(:query_facet) { facets.find { |x| x['id'] == 'example_query_facet_field' } }
let(:query_facet_items) { query_facet['attributes']['items'].map { |x| x['attributes'] } }
let(:query_facet_items) { query_facet['attributes']['items'].pluck('attributes') }

it "has items with labels and values" do
expect(query_facet_items.first['label']).to eq 'within 25 Years'
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/blacklight/url_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
context "with an integer id" do
let(:id) { 123_456 }

it "works" do
it "has a link" do
expect(helper.link_to_document(document)).to have_selector("a")
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/presenters/blacklight/facet_item_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
let(:search_state) { instance_double(Blacklight::SearchState, filter: filter_field) }

describe '#selected?' do
it 'works' do
expect(presenter.selected?).to be true
end
subject { presenter.selected? }

it { is_expected.to be true }
end

describe '#label' do
Expand Down
4 changes: 2 additions & 2 deletions spec/views/catalog/index.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@
let(:facets) { hash[:included].select { |x| x['type'] == 'facet' } }
let(:format) { facets.find { |x| x['id'] == 'format' } }
let(:format_items) { format['attributes']['items'] }
let(:format_item_attributes) { format_items.map { |x| x['attributes'] } }
let(:format_item_attributes) { format_items.pluck('attributes') }

context 'when no facets have been selected' do
it 'has facet information and links' do
expect(facets).to be_present
expect(facets.map { |x| x['id'] }).to include 'format'
expect(facets.pluck('id')).to include 'format'
expect(format['links']).to include self: 'http://test.host/some/facet/url'
expect(format['attributes']['label']).to eq 'Format'
expect(format_item_attributes).to match_array [{ value: 'Book', hits: 30, label: 'Book' }]
Expand Down

0 comments on commit a12b19e

Please sign in to comment.