diff --git a/.rubocop.yml b/.rubocop.yml index cc32da4..2c83e76 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,25 @@ inherit_from: .rubocop_todo.yml + +AllCops: + TargetRubyVersion: 2.5 + Exclude: + - 'bin/**/*' + - 'db/schema.rb' + - 'vendor/**/*' + +Style/Documentation: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: true + Exclude: + - 'config.ru' + - 'Gemfile' + - 'Rakefile' + - 'app/views/**/*' + - 'config/**/*' + - 'db/**/*' + - 'lib/tasks/**/*' + +Style/IfUnlessModifier: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 91572f1..f0070f2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,73 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-03-09 13:28:58 +0100 using RuboCop version 0.80.1. +# on 2020-03-09 14:56:53 +0100 using RuboCop version 0.80.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'lib/parseable_date_validator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'config/application.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'config/environments/development.rb' - - 'db/schema.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'config/application.rb' - - 'lib/parseable_date_validator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'app/views/search/index.rss.builder' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'bin/rails' - - 'config.ru' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'config/application.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'config/initializers/assets.rb' - - 'config/initializers/cookies_serializer.rb' - # Offense count: 1 Lint/InterpolationCheck: Exclude: @@ -79,32 +17,11 @@ Lint/SendWithMixinArgument: Exclude: - 'config/initializers/kaminari_config.rb' -# Offense count: 3 -# Configuration parameters: AllowComments. -Lint/SuppressedException: - Exclude: - - 'bin/rails' - - 'bin/rake' - - 'bin/rspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. -Lint/UnusedMethodArgument: - Exclude: - - 'lib/parseable_date_validator.rb' - -# Offense count: 2 -Lint/UselessAssignment: - Exclude: - - 'lib/parseable_date_validator.rb' - - 'spec/features/basic_search_spec.rb' - # Offense count: 4 Metrics/AbcSize: Max: 58 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: @@ -137,124 +54,18 @@ Naming/VariableNumber: Exclude: - 'spec/features/search_filters_spec.rb' -# Offense count: 15 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'app/controllers/application_controller.rb' - - 'app/controllers/geo_controller.rb' - - 'app/controllers/import_controller.rb' - - 'app/controllers/search_controller.rb' - - 'app/helpers/search_helper.rb' - - 'app/models/importer.rb' - - 'app/models/paper.rb' - - 'app/models/paper_search.rb' - - 'app/models/user.rb' - - 'config/application.rb' - - 'db/migrate/20141117201926_create_users.rb' - - 'db/migrate/20150413193656_create_papers.rb' - - 'db/migrate/20150517152218_create_importers.rb' - - 'db/migrate/20151010070158_create_paper_searches.rb' - - 'lib/parseable_date_validator.rb' - # Offense count: 1 Style/DoubleNegation: Exclude: - 'app/controllers/application_controller.rb' -# Offense count: 9 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'Rakefile' - - 'bin/bundle' - - 'bin/rails' - - 'bin/rake' - - 'bin/rspec' - - 'config/application.rb' - - 'config/boot.rb' - - 'config/environment.rb' - -# Offense count: 34 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'config/routes.rb' - -# Offense count: 7 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'app/models/paper_search.rb' - - 'app/views/search/index.rss.builder' - - 'spec/rails_helper.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: . -# SupportedStyles: call, braces -Style/LambdaCall: - EnforcedStyle: braces - # Offense count: 2 Style/MultilineTernaryOperator: Exclude: - 'app/controllers/search_controller.rb' - 'spec/features/basic_search_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 15 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'Guardfile' - -# Offense count: 45 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Guardfile' - - 'bin/rails' - - 'bin/rake' - - 'bin/rspec' - - 'db/schema.rb' - - 'lib/parseable_date_validator.rb' - - 'lib/tasks/import_papers.rake' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 3 - -# Offense count: 63 +# Offense count: 57 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/Guardfile b/Guardfile index e12d236..48c1df6 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A sample Guardfile # More info at https://github.com/guard/guard#readme @@ -24,8 +26,8 @@ # * zeus: 'zeus rspec' (requires the server to be started separately) # * 'just' rspec: 'rspec' -guard :rspec, cmd: "bin/rspec" do - require "guard/rspec/dsl" +guard :rspec, cmd: 'bin/rspec' do + require 'guard/rspec/dsl' dsl = Guard::RSpec::Dsl.new(self) # Feel free to open issues for suggestions and improvements @@ -41,15 +43,15 @@ guard :rspec, cmd: "bin/rspec" do dsl.watch_spec_files_for(ruby.lib_files) # Rails files - rails = dsl.rails(view_extensions: %w(erb haml slim)) + rails = dsl.rails(view_extensions: %w[erb haml slim]) dsl.watch_spec_files_for(rails.app_files) dsl.watch_spec_files_for(rails.views) watch(rails.controllers) do |m| [ - rspec.spec.("routing/#{m[1]}_routing"), - rspec.spec.("controllers/#{m[1]}_controller"), - rspec.spec.("acceptance/#{m[1]}") + rspec.spec.call("routing/#{m[1]}_routing"), + rspec.spec.call("controllers/#{m[1]}_controller"), + rspec.spec.call("acceptance/#{m[1]}") ] end @@ -59,12 +61,12 @@ guard :rspec, cmd: "bin/rspec" do watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } # Capybara features specs - watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") } - watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") } + watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } + watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } # Turnip features and steps watch(%r{^spec/acceptance/(.+)\.feature$}) watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| - Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance" + Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' end end diff --git a/Rakefile b/Rakefile index ba6b733..f7a26dd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Rails.application.load_tasks diff --git a/app/views/search/index.rss.builder b/app/views/search/index.rss.builder index e2571f7..799aa8b 100644 --- a/app/views/search/index.rss.builder +++ b/app/views/search/index.rss.builder @@ -18,7 +18,7 @@ xml.rss :version => '2.0', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/' do end unless doc.published_at.blank? xml.pubDate DateTime.parse(doc.published_at).utc.strftime('%a, %d %b %Y %H:%M:%S %z') - end + end doc.originator.each do |originator| xml.dc :creator do xml.cdata! originator diff --git a/config.ru b/config.ru index 5bc2a61..bd83b25 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run Rails.application diff --git a/config/application.rb b/config/application.rb index 41a881d..0bc5be8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require File.expand_path('../boot', __FILE__) +require File.expand_path('boot', __dir__) require 'rails/all' @@ -20,9 +20,7 @@ module LorisWeb # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] config.i18n.default_locale = :de - # https://stackoverflow.com/a/28008145 - #config.active_record.raise_in_transactional_callbacks = true - + # config.active_record.raise_in_transactional_callbacks = true end end diff --git a/config/boot.rb b/config/boot.rb index 5e5f0c1..126c4a8 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index ee8d90d..0b8bdd8 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 47ce644..aab03cc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -37,5 +37,4 @@ Rails.application.configure do # flush stdout in order to get logs in realtime $stdout.sync = true - end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index e71b831..e548542 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -6,4 +6,4 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) -# Rails.application.config.assets.precompile += %w( geo.js ) \ No newline at end of file +# Rails.application.config.assets.precompile += %w( geo.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7a06a89..7f70458 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/routes.rb b/config/routes.rb index a177ad8..23f94e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - root :to => 'search#index', as: :search + root to: 'search#index', as: :search post '/import' => 'import#new_papers_callback' get '/map' => 'geo#index', as: :geo get '/glossary' => 'application#glossary', as: :glossary diff --git a/db/migrate/20150413193656_create_papers.rb b/db/migrate/20150413193656_create_papers.rb index 956268d..41331fc 100644 --- a/db/migrate/20150413193656_create_papers.rb +++ b/db/migrate/20150413193656_create_papers.rb @@ -19,6 +19,6 @@ class CreatePapers < ActiveRecord::Migration[4.2] add_index(:papers, :reference) add_index(:papers, :originator) add_index(:papers, :body) - add_index(:papers, [:reference, :body], unique: true) + add_index(:papers, %i[reference body], unique: true) end end diff --git a/lib/parseable_date_validator.rb b/lib/parseable_date_validator.rb index 57b39b9..1166f2c 100644 --- a/lib/parseable_date_validator.rb +++ b/lib/parseable_date_validator.rb @@ -1,12 +1,13 @@ -class ParseableDateValidator < ActiveModel::EachValidator +# frozen_string_literal: true - def validate_each(record, attribute, value) +class ParseableDateValidator < ActiveModel::EachValidator + def validate_each(record, attribute, _value) raw_value = record.read_attribute_before_type_cast(attribute) return nil if raw_value.nil? + Date.parse(raw_value.to_json) nil - rescue ArgumentError => e - record.errors[attribute] << (options[:message] || I18n.t("errors.messages.unparseable_date")) + rescue ArgumentError + record.errors[attribute] << (options[:message] || I18n.t('errors.messages.unparseable_date')) end - end diff --git a/lib/tasks/import_papers.rake b/lib/tasks/import_papers.rake index 997b916..f096b76 100644 --- a/lib/tasks/import_papers.rake +++ b/lib/tasks/import_papers.rake @@ -2,7 +2,7 @@ desc 'Import Paper records from setup importers' task import_papers: :environment do require 'open-uri' OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE - api_key = Rails.application.config_for(:morph)["key"] + api_key = Rails.application.config_for(:morph)['key'] uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27") Paper.import_from_json(uri.read) end diff --git a/spec/features/basic_search_spec.rb b/spec/features/basic_search_spec.rb index 58f4bb0..9c8333f 100644 --- a/spec/features/basic_search_spec.rb +++ b/spec/features/basic_search_spec.rb @@ -209,7 +209,7 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do end scenario "Finds no 'Fahrrad' with search 'Rad'" do - paper = FactoryBot.create(:paper, name: 'Fahrrad') + FactoryBot.create(:paper, name: 'Fahrrad') Paper.__elasticsearch__.refresh_index! visit search_path body: 'leipzig', paper_search: { query: 'Rad' } expect(page).to have_content('0 Dokumente in der Datenbank')