mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-01-02 20:42:55 +01:00
Fix a bunch of rubocop offenses
This commit is contained in:
parent
106c6800a4
commit
4e1e8b798a
17 changed files with 57 additions and 222 deletions
24
.rubocop.yml
24
.rubocop.yml
|
@ -1 +1,25 @@
|
||||||
inherit_from: .rubocop_todo.yml
|
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
|
||||||
|
|
|
@ -1,73 +1,11 @@
|
||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `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
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
# versions of RuboCop, may require this file to be generated again.
|
# 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
|
# Offense count: 1
|
||||||
Lint/InterpolationCheck:
|
Lint/InterpolationCheck:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
@ -79,32 +17,11 @@ Lint/SendWithMixinArgument:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'config/initializers/kaminari_config.rb'
|
- '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
|
# Offense count: 4
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 58
|
Max: 58
|
||||||
|
|
||||||
# Offense count: 9
|
# Offense count: 8
|
||||||
# Configuration parameters: CountComments, ExcludedMethods.
|
# Configuration parameters: CountComments, ExcludedMethods.
|
||||||
# ExcludedMethods: refine
|
# ExcludedMethods: refine
|
||||||
Metrics/BlockLength:
|
Metrics/BlockLength:
|
||||||
|
@ -137,124 +54,18 @@ Naming/VariableNumber:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/features/search_filters_spec.rb'
|
- '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
|
# Offense count: 1
|
||||||
Style/DoubleNegation:
|
Style/DoubleNegation:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/application_controller.rb'
|
- '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
|
# Offense count: 2
|
||||||
Style/MultilineTernaryOperator:
|
Style/MultilineTernaryOperator:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/search_controller.rb'
|
- 'app/controllers/search_controller.rb'
|
||||||
- 'spec/features/basic_search_spec.rb'
|
- 'spec/features/basic_search_spec.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 57
|
||||||
# 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
|
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||||
# URISchemes: http, https
|
# URISchemes: http, https
|
||||||
|
|
20
Guardfile
20
Guardfile
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# A sample Guardfile
|
# A sample Guardfile
|
||||||
# More info at https://github.com/guard/guard#readme
|
# More info at https://github.com/guard/guard#readme
|
||||||
|
|
||||||
|
@ -24,8 +26,8 @@
|
||||||
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
||||||
# * 'just' rspec: 'rspec'
|
# * 'just' rspec: 'rspec'
|
||||||
|
|
||||||
guard :rspec, cmd: "bin/rspec" do
|
guard :rspec, cmd: 'bin/rspec' do
|
||||||
require "guard/rspec/dsl"
|
require 'guard/rspec/dsl'
|
||||||
dsl = Guard::RSpec::Dsl.new(self)
|
dsl = Guard::RSpec::Dsl.new(self)
|
||||||
|
|
||||||
# Feel free to open issues for suggestions and improvements
|
# 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)
|
dsl.watch_spec_files_for(ruby.lib_files)
|
||||||
|
|
||||||
# Rails 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.app_files)
|
||||||
dsl.watch_spec_files_for(rails.views)
|
dsl.watch_spec_files_for(rails.views)
|
||||||
|
|
||||||
watch(rails.controllers) do |m|
|
watch(rails.controllers) do |m|
|
||||||
[
|
[
|
||||||
rspec.spec.("routing/#{m[1]}_routing"),
|
rspec.spec.call("routing/#{m[1]}_routing"),
|
||||||
rspec.spec.("controllers/#{m[1]}_controller"),
|
rspec.spec.call("controllers/#{m[1]}_controller"),
|
||||||
rspec.spec.("acceptance/#{m[1]}")
|
rspec.spec.call("acceptance/#{m[1]}")
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,12 +61,12 @@ guard :rspec, cmd: "bin/rspec" do
|
||||||
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
||||||
|
|
||||||
# Capybara features specs
|
# Capybara features specs
|
||||||
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
||||||
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
|
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
||||||
|
|
||||||
# Turnip features and steps
|
# Turnip features and steps
|
||||||
watch(%r{^spec/acceptance/(.+)\.feature$})
|
watch(%r{^spec/acceptance/(.+)\.feature$})
|
||||||
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
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
|
||||||
end
|
end
|
||||||
|
|
2
Rakefile
2
Rakefile
|
@ -1,6 +1,6 @@
|
||||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
# 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.
|
# 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
|
Rails.application.load_tasks
|
||||||
|
|
|
@ -18,7 +18,7 @@ xml.rss :version => '2.0', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/' do
|
||||||
end
|
end
|
||||||
unless doc.published_at.blank?
|
unless doc.published_at.blank?
|
||||||
xml.pubDate DateTime.parse(doc.published_at).utc.strftime('%a, %d %b %Y %H:%M:%S %z')
|
xml.pubDate DateTime.parse(doc.published_at).utc.strftime('%a, %d %b %Y %H:%M:%S %z')
|
||||||
end
|
end
|
||||||
doc.originator.each do |originator|
|
doc.originator.each do |originator|
|
||||||
xml.dc :creator do
|
xml.dc :creator do
|
||||||
xml.cdata! originator
|
xml.cdata! originator
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# This file is used by Rack-based servers to start the application.
|
# 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
|
run Rails.application
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path('../boot', __FILE__)
|
require File.expand_path('boot', __dir__)
|
||||||
|
|
||||||
require 'rails/all'
|
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.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||||
config.i18n.default_locale = :de
|
config.i18n.default_locale = :de
|
||||||
|
|
||||||
|
|
||||||
# https://stackoverflow.com/a/28008145
|
# https://stackoverflow.com/a/28008145
|
||||||
#config.active_record.raise_in_transactional_callbacks = true
|
# config.active_record.raise_in_transactional_callbacks = true
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Set up gems listed in the Gemfile.
|
# 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'])
|
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Load the Rails application.
|
# Load the Rails application.
|
||||||
require File.expand_path('../application', __FILE__)
|
require File.expand_path('application', __dir__)
|
||||||
|
|
||||||
# Initialize the Rails application.
|
# Initialize the Rails application.
|
||||||
Rails.application.initialize!
|
Rails.application.initialize!
|
||||||
|
|
|
@ -37,5 +37,4 @@ Rails.application.configure do
|
||||||
|
|
||||||
# flush stdout in order to get logs in realtime
|
# flush stdout in order to get logs in realtime
|
||||||
$stdout.sync = true
|
$stdout.sync = true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,4 @@ Rails.application.config.assets.version = '1.0'
|
||||||
# Precompile additional assets.
|
# Precompile additional assets.
|
||||||
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
# 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( search.js )
|
||||||
# Rails.application.config.assets.precompile += %w( geo.js )
|
# Rails.application.config.assets.precompile += %w( geo.js )
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# Be sure to restart your server when you modify this file.
|
# Be sure to restart your server when you modify this file.
|
||||||
|
|
||||||
Rails.application.config.action_dispatch.cookies_serializer = :json
|
Rails.application.config.action_dispatch.cookies_serializer = :json
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
root :to => 'search#index', as: :search
|
root to: 'search#index', as: :search
|
||||||
post '/import' => 'import#new_papers_callback'
|
post '/import' => 'import#new_papers_callback'
|
||||||
get '/map' => 'geo#index', as: :geo
|
get '/map' => 'geo#index', as: :geo
|
||||||
get '/glossary' => 'application#glossary', as: :glossary
|
get '/glossary' => 'application#glossary', as: :glossary
|
||||||
|
|
|
@ -19,6 +19,6 @@ class CreatePapers < ActiveRecord::Migration[4.2]
|
||||||
add_index(:papers, :reference)
|
add_index(:papers, :reference)
|
||||||
add_index(:papers, :originator)
|
add_index(:papers, :originator)
|
||||||
add_index(:papers, :body)
|
add_index(:papers, :body)
|
||||||
add_index(:papers, [:reference, :body], unique: true)
|
add_index(:papers, %i[reference body], unique: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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)
|
raw_value = record.read_attribute_before_type_cast(attribute)
|
||||||
return nil if raw_value.nil?
|
return nil if raw_value.nil?
|
||||||
|
|
||||||
Date.parse(raw_value.to_json)
|
Date.parse(raw_value.to_json)
|
||||||
nil
|
nil
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError
|
||||||
record.errors[attribute] << (options[:message] || I18n.t("errors.messages.unparseable_date"))
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.unparseable_date'))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ desc 'Import Paper records from setup importers'
|
||||||
task import_papers: :environment do
|
task import_papers: :environment do
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
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")
|
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)
|
Paper.import_from_json(uri.read)
|
||||||
end
|
end
|
||||||
|
|
|
@ -209,7 +209,7 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Finds no 'Fahrrad' with search 'Rad'" do
|
scenario "Finds no 'Fahrrad' with search 'Rad'" do
|
||||||
paper = FactoryBot.create(:paper, name: 'Fahrrad')
|
FactoryBot.create(:paper, name: 'Fahrrad')
|
||||||
Paper.__elasticsearch__.refresh_index!
|
Paper.__elasticsearch__.refresh_index!
|
||||||
visit search_path body: 'leipzig', paper_search: { query: 'Rad' }
|
visit search_path body: 'leipzig', paper_search: { query: 'Rad' }
|
||||||
expect(page).to have_content('0 Dokumente in der Datenbank')
|
expect(page).to have_content('0 Dokumente in der Datenbank')
|
||||||
|
|
Loading…
Reference in a new issue