diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5857242f..ce617575 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 999 --no-offense-counts --no-auto-gen-timestamp` -# using RuboCop version 0.93.1. +# using RuboCop version 1.9.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 @@ -57,7 +57,7 @@ Lint/UselessAssignment: - 'spec/lib/openc_bot/incrementers/common_spec.rb' - 'spec/schemas/company-schema_spec.rb' -# Configuration parameters: IgnoredMethods. +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 33 @@ -65,14 +65,10 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Max: 13 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 27 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 6 - # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: Max: 14 @@ -87,8 +83,9 @@ Naming/FileName: Exclude: - 'spec/schemas/company-schema_spec.rb' -# Configuration parameters: EnforcedStyle. +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. # SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 Naming/VariableNumber: Exclude: - 'spec/schemas/company-schema_spec.rb' @@ -131,7 +128,8 @@ RSpec/ExpectInHook: Exclude: - 'spec/lib/openc_bot/helpers/register_methods_spec.rb' -# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* RSpec/FilePath: Exclude: - 'lib/openc_bot/templates/spec/bot_spec.rb' @@ -186,6 +184,7 @@ Security/Open: - 'lib/openc_bot/helpers/alpha_search.rb' # Configuration parameters: AllowedChars. +# AllowedChars: © Style/AsciiComments: Exclude: - 'lib/openc_bot/templates/lib/company_fetcher_bot.rb' @@ -220,6 +219,7 @@ Style/Documentation: - 'lib/openc_bot/templates/lib/bot.rb' - 'lib/openc_bot/templates/lib/company_fetcher_bot.rb' +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: allowed_in_returns, forbidden Style/DoubleNegation: @@ -236,6 +236,7 @@ Style/GuardClause: Exclude: - 'lib/openc_bot/helpers/register_methods.rb' +# Cop supports --auto-correct. # Configuration parameters: AllowIfModifier. Style/IfInsideElse: Exclude: diff --git a/.travis.yml b/.travis.yml index 38c72348..c1b1f3ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ before_install: - gem i rubygems-update -v '<3' && update_rubygems - gem install bundler -v 1.17.3 - rm Gemfile.lock + - bundle _1.17.3_ install before_script: - bin/rubocop - bin/rubocop --auto-gen-config --exclude-limit 999 --no-offense-counts --no-auto-gen-timestamp >/dev/null || true; git --no-pager diff --exit-code diff --git a/Gemfile.lock b/Gemfile.lock index e9c08663..a36713d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,111 +8,115 @@ GIT PATH remote: . specs: - openc_bot (0.0.82) - activesupport (~> 4.1) - backports (~> 3.11) - httpclient (~> 2.8) - json (~> 2.1) - json-schema (~> 2.8) - mail (~> 2.0) - nokogiri (~> 1.8) - rake (~> 12.3) - resque (~> 2.0) - retriable (~> 2.1) - scraperwiki (= 3.0.2) - sqlite_magic (= 0.0.6) - statsd-instrument (~> 1.7) - tzinfo (~> 1.2) + openc_bot (0.0.83) + activesupport + backports + httpclient + json + json-schema + mail + nokogiri (~> 1.11.1) + rake + resque + retriable + scraperwiki + sqlite_magic + statsd-instrument + tzinfo GEM remote: https://rubygems.org/ specs: - activesupport (4.2.11.3) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) + activesupport (6.1.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - ast (2.4.1) - backports (3.18.2) - byebug (10.0.2) + ast (2.4.2) + backports (3.20.2) + byebug (11.1.3) coderay (1.1.3) - concurrent-ruby (1.1.7) - crack (0.4.4) + concurrent-ruby (1.1.8) + crack (0.4.5) + rexml diff-lcs (1.4.4) hashdiff (1.0.1) httpclient (2.8.3) - i18n (0.9.5) + i18n (1.8.8) concurrent-ruby (~> 1.0) - json (2.3.1) + json (2.5.1) json-schema (2.8.1) addressable (>= 2.4) mail (2.7.1) mini_mime (>= 0.1.1) method_source (1.0.0) mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.14.2) + mini_portile2 (2.5.0) + minitest (5.14.3) mono_logger (1.1.0) multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) parallel (1.20.1) - parser (2.7.2.0) + parser (3.0.0.0) ast (~> 2.4.1) - pry (0.13.1) + pry (0.14.0) coderay (~> 1.1) method_source (~> 1.0) public_suffix (4.0.6) + racc (1.5.2) rack (2.2.3) rack-protection (2.1.0) rack rainbow (3.0.0) - rake (12.3.3) + rake (13.0.3) redis (4.2.5) - redis-namespace (1.8.0) + redis-namespace (1.8.1) redis (>= 3.0.4) - regexp_parser (2.0.0) + regexp_parser (2.0.3) resque (2.0.0) mono_logger (~> 1.0) multi_json (~> 1.0) redis-namespace (~> 1.6) sinatra (>= 0.9.2) vegas (~> 0.1.2) - retriable (2.1.0) + retriable (3.1.2) rexml (3.2.4) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) rspec-mocks (~> 3.10.0) - rspec-core (3.10.0) + rspec-core (3.10.1) rspec-support (~> 3.10.0) - rspec-expectations (3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-mocks (3.10.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-support (3.10.0) - rubocop (0.93.1) + rspec-support (3.10.2) + rubocop (1.9.1) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.6.0) + rubocop-ast (>= 1.2.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.3.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.4.1) parser (>= 2.7.1.5) - rubocop-rspec (1.44.1) - rubocop (~> 0.87) - rubocop-ast (>= 0.7.1) - ruby-progressbar (1.10.1) - ruby2_keywords (0.0.2) + rubocop-rspec (2.2.0) + rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) + ruby-progressbar (1.11.0) + ruby2_keywords (0.0.4) scraperwiki (3.0.2) httpclient sqlite_magic @@ -122,31 +126,31 @@ GEM rack-protection (= 2.1.0) tilt (~> 2.0) sqlite3 (1.4.2) - statsd-instrument (1.7.2) - thread_safe (0.3.6) + statsd-instrument (3.0.2) tilt (2.0.10) - tzinfo (1.2.8) - thread_safe (~> 0.1) - unicode-display_width (1.7.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + unicode-display_width (2.0.0) vegas (0.1.11) rack (>= 1.0.0) - webmock (1.24.6) + webmock (3.11.2) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) + zeitwerk (2.4.2) PLATFORMS ruby DEPENDENCIES - byebug (~> 10.0) + byebug openc_bot! pry - rspec (~> 3.8) - rubocop (~> 0.93.1) - rubocop-rspec (~> 1.30) + rspec + rubocop + rubocop-rspec sqlite_magic! - webmock (~> 1.20) + webmock BUNDLED WITH 1.17.3 diff --git a/lib/monkey_patches/mechanize.rb b/lib/monkey_patches/mechanize.rb index af06ac62..afb682dd 100644 --- a/lib/monkey_patches/mechanize.rb +++ b/lib/monkey_patches/mechanize.rb @@ -17,6 +17,7 @@ class Mechanize::HTTP::Agent # be retried once, but I am going to let it retry a few times # (MAX_RESET_RETRIES), just in case. # + # rubocop:disable Metrics/ParameterLists def fetch_with_retry( uri, method = :get, @@ -47,7 +48,7 @@ def fetch_with_retry( retry end end - + # rubocop:enable Metrics/ParameterLists # Alias so #fetch actually uses our new #fetch_with_retry to wrap the # old one aliased as #fetch_without_retry. alias fetch_without_retry fetch diff --git a/lib/openc_bot.rb b/lib/openc_bot.rb index 913bacc8..c4007332 100644 --- a/lib/openc_bot.rb +++ b/lib/openc_bot.rb @@ -12,8 +12,11 @@ module OpencBot class OpencBotError < StandardError; end + class DatabaseError < OpencBotError; end + class InvalidDataError < OpencBotError; end + class NotFoundError < OpencBotError; end include ScraperWiki @@ -81,10 +84,10 @@ def self.extended(_obj) def statsd_namespace @statsd_namespace ||= begin - bot_env = ENV.fetch("FETCHER_BOT_ENV", "development").to_sym - StatsD.mode = bot_env - StatsD.server = "sys1:8125" - StatsD.logger = Logger.new("/dev/null") if bot_env != :production + bot_env = ENV.fetch("FETCHER_BOT_ENV", "development").to_s + ENV["STATSD_ENV"] = bot_env + ENV["STATSD_ADDR"] = "sys1:8125" + StatsD.logger = Logger.new("/dev/null") if bot_env != "production" if respond_to?(:inferred_jurisdiction_code) && inferred_jurisdiction_code "fetcher_bot.#{bot_env}.#{inferred_jurisdiction_code}" diff --git a/lib/openc_bot/templates/spec/spec_helper.rb b/lib/openc_bot/templates/spec/spec_helper.rb index 3d60858d..5edeeff3 100644 --- a/lib/openc_bot/templates/spec/spec_helper.rb +++ b/lib/openc_bot/templates/spec/spec_helper.rb @@ -2,8 +2,10 @@ require "rspec/autorun" +# rubocop:disable Lint/EmptyBlock RSpec.configure do |config| end +# rubocop:enable Lint/EmptyBlock # Utility method to allow sample html pages, csv files, json or whatever. # Expects the files to be stored in a 'dummy_responses' folder in the spec directory diff --git a/lib/openc_bot/version.rb b/lib/openc_bot/version.rb index 33bbe360..73ccead3 100644 --- a/lib/openc_bot/version.rb +++ b/lib/openc_bot/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module OpencBot - VERSION = "0.0.82" + VERSION = "0.0.83" end diff --git a/openc_bot.gemspec b/openc_bot.gemspec index a55ecf50..4bd43b00 100644 --- a/openc_bot.gemspec +++ b/openc_bot.gemspec @@ -33,25 +33,25 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] - gem.add_dependency "activesupport", "~> 4.1" - gem.add_dependency "backports", "~> 3.11" - gem.add_dependency "httpclient", "~> 2.8" - gem.add_dependency "json", "~> 2.1" - gem.add_dependency "json-schema", "~> 2.8" - gem.add_dependency "mail", "~> 2.0" - gem.add_dependency "nokogiri", "~> 1.8" - gem.add_dependency "rake", "~> 12.3" - gem.add_dependency "resque", "~> 2.0" - gem.add_dependency "retriable", "~> 2.1" - gem.add_dependency "scraperwiki", "3.0.2" - gem.add_dependency "sqlite_magic", "0.0.6" - gem.add_dependency "statsd-instrument", "~> 1.7" - gem.add_dependency "tzinfo", "~> 1.2" + gem.add_dependency "activesupport" + gem.add_dependency "backports" + gem.add_dependency "httpclient" + gem.add_dependency "json" + gem.add_dependency "json-schema" + gem.add_dependency "mail" + gem.add_dependency "nokogiri", "~> 1.11.1" + gem.add_dependency "rake" + gem.add_dependency "resque" + gem.add_dependency "retriable" + gem.add_dependency "scraperwiki" + gem.add_dependency "sqlite_magic" + gem.add_dependency "statsd-instrument" + gem.add_dependency "tzinfo" # gem.add_development_dependency "perftools.rb" - gem.add_development_dependency "byebug", "~> 10.0" - gem.add_development_dependency "rspec", "~> 3.8" - gem.add_development_dependency "rubocop", "~> 0.93.1" - gem.add_development_dependency "rubocop-rspec", "~> 1.30" - gem.add_development_dependency "webmock", "~> 1.20" + gem.add_development_dependency "byebug" + gem.add_development_dependency "rspec" + gem.add_development_dependency "rubocop" + gem.add_development_dependency "rubocop-rspec" + gem.add_development_dependency "webmock" end diff --git a/spec/lib/openc_bot/helpers/alpha_search_spec.rb b/spec/lib/openc_bot/helpers/alpha_search_spec.rb index 926c35fb..fa79b778 100644 --- a/spec/lib/openc_bot/helpers/alpha_search_spec.rb +++ b/spec/lib/openc_bot/helpers/alpha_search_spec.rb @@ -110,10 +110,10 @@ module ModuleThatIncludesAlphaSearch it "processes entity data yielded by search_for_entities_for_term" do @alpha_terms.each do |term| - allow(ModuleThatIncludesAlphaSearch).to receive(:search_for_entities_for_term).with(term, anything).and_yield(:datum_1).and_yield(:datum_2) + allow(ModuleThatIncludesAlphaSearch).to receive(:search_for_entities_for_term).with(term, anything).and_yield(:datum_one).and_yield(:datum_two) end - expect(ModuleThatIncludesAlphaSearch).to receive(:save_entity).with(:datum_1) - expect(ModuleThatIncludesAlphaSearch).to receive(:save_entity).with(:datum_2) + expect(ModuleThatIncludesAlphaSearch).to receive(:save_entity).with(:datum_one) + expect(ModuleThatIncludesAlphaSearch).to receive(:save_entity).with(:datum_two) ModuleThatIncludesAlphaSearch.fetch_data_via_alpha_search end diff --git a/spec/lib/openc_bot/helpers/incremental_search_spec.rb b/spec/lib/openc_bot/helpers/incremental_search_spec.rb index 03aa2806..5c54adf2 100644 --- a/spec/lib/openc_bot/helpers/incremental_search_spec.rb +++ b/spec/lib/openc_bot/helpers/incremental_search_spec.rb @@ -97,15 +97,15 @@ module ModuleWithNoCustomPrimaryKey end it "iterates with prefixes, incrementing digits" do - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12345", anything).and_return(:entry_1) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12346", anything).and_return(:entry_2) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12345", anything).and_return(:entry_one) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12346", anything).and_return(:entry_two) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12347", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("12348", anything) ModuleThatIncludesIncrementalSearch.incremental_search("12345") end it "uses increment_number to, er, increment number" do - allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).and_return(:entry_1) + allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).and_return(:entry_one) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("25632", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:increment_number).with("12345").and_return("34567") expect(ModuleThatIncludesIncrementalSearch).to receive(:increment_number).with("34567").and_return("76543") @@ -115,11 +115,11 @@ module ModuleWithNoCustomPrimaryKey it "gets company details for given company number and subsequent company numbers until nil is returned more than max_failed_count times" do allow(ModuleThatIncludesIncrementalSearch).to receive_messages(max_failed_count: 2) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_1) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234569", anything).and_return(:entry_2) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_one) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234569", anything).and_return(:entry_two) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234570", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234571", anything).and_return(nil) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_3) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_three) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234573", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234574", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234575", anything).and_return(nil) @@ -129,11 +129,11 @@ module ModuleWithNoCustomPrimaryKey it "returns last good number" do allow(ModuleThatIncludesIncrementalSearch).to receive_messages(max_failed_count: 2) - allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_1) - allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234569", anything).and_return(:entry_2) + allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_one) + allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234569", anything).and_return(:entry_two) allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234570", anything).and_return(nil) allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234571", anything).and_return(nil) - allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_3) + allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_three) allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234573", anything).and_return(nil) allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234574", anything).and_return(nil) allow(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234575", anything).and_return(nil) @@ -155,11 +155,11 @@ module ModuleWithNoCustomPrimaryKey it "does not update_datum for existing entries" do allow(ModuleThatIncludesIncrementalSearch).to receive_messages(max_failed_count: 2) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_1) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234568", anything).and_return(:entry_one) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("1234569", anything) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234570", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("1234571", anything) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_3) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_three) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234573", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234574", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234575", anything).and_return(nil) @@ -173,7 +173,7 @@ module ModuleWithNoCustomPrimaryKey expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("1234569", anything) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234570", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("1234571", anything) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_3) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234572", anything).and_return(:entry_three) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234573", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("1234574", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("1234575", anything) @@ -183,8 +183,8 @@ module ModuleWithNoCustomPrimaryKey context "and offset passed in as option" do it "gets entries beginning from given number adjusted by offset" do - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12342", anything).and_return(:entry_1) - expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12343", anything).and_return(:entry_2) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12342", anything).and_return(:entry_one) + expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12343", anything).and_return(:entry_two) expect(ModuleThatIncludesIncrementalSearch).to receive(:update_datum).with("12344", anything).and_return(nil) expect(ModuleThatIncludesIncrementalSearch).not_to receive(:update_datum).with("12345", anything) ModuleThatIncludesIncrementalSearch.incremental_search("12345", offset: -3) diff --git a/spec/lib/openc_bot/helpers/register_methods_spec.rb b/spec/lib/openc_bot/helpers/register_methods_spec.rb index e4100785..05b30de5 100644 --- a/spec/lib/openc_bot/helpers/register_methods_spec.rb +++ b/spec/lib/openc_bot/helpers/register_methods_spec.rb @@ -65,7 +65,7 @@ module ModuleWithNoCustomPrimaryKey datum = { "food" => "tofu" } allow(ModuleThatIncludesRegisterMethods).to receive(:select).and_return([datum]) expect(ModuleThatIncludesRegisterMethods).to receive(:post_process).with(datum, true).and_return(datum) - ModuleThatIncludesRegisterMethods.export_data { |x| } + ModuleThatIncludesRegisterMethods.export_data(&:inspect) end end @@ -192,7 +192,9 @@ module ModuleWithNoCustomPrimaryKey allow(ModuleThatIncludesRegisterMethods).to receive(:skip_inactive?) + # rubocop:disable Lint/EmptyBlock ModuleThatIncludesRegisterMethods.stale_entry_uids {} + # rubocop:enable Lint/EmptyBlock end it "calls skip_inactive? on each record where current_status field value is in the array" do @@ -245,6 +247,7 @@ module ModuleWithNoCustomPrimaryKey ModuleThatIncludesRegisterMethods.save_data([:custom_uid], custom_uid: "A094567") end + # rubocop:disable Lint/EmptyBlock it "does not raise error" do expect { ModuleThatIncludesRegisterMethods.stale_entry_uids {} }.not_to raise_error end @@ -253,6 +256,7 @@ module ModuleWithNoCustomPrimaryKey ModuleThatIncludesRegisterMethods.stale_entry_uids {} expect(ModuleThatIncludesRegisterMethods.select("* from ocdata").first.keys).to include("retrieved_at") end + # rubocop:enable Lint/EmptyBlock it "retries the called method" do expect { |b| ModuleThatIncludesRegisterMethods.stale_entry_uids(&b) }.to yield_successive_args("99999", "A094567") @@ -273,7 +277,7 @@ module ModuleWithNoCustomPrimaryKey end it "returns true if record doesnt exist" do - ModuleThatIncludesRegisterMethods.save_data([:custom_uid], custom_uid: "5234888", retrieved_at: (Date.today - 2).to_time) # note: this creates the ocdata table, otherwise we get true returned because that's behaviour for such situations + ModuleThatIncludesRegisterMethods.save_data([:custom_uid], custom_uid: "5234888", retrieved_at: (Date.today - 2).to_time) # NOTE: this creates the ocdata table, otherwise we get true returned because that's behaviour for such situations expect(ModuleThatIncludesRegisterMethods.stale_entry?("foo")).to eq(true) end end @@ -930,12 +934,12 @@ module ModuleWithNoCustomPrimaryKey before do @unprocessed_data = { name: "Foo Corp", company_number: "12345", - serialised_field_1: "[\"foo\",\"bar\"]", - serialised_field_2: "[{\"position\":\"gestor\",\"name\":\"JOSE MANUEL REYES R.\",\"other_attributes\":{\"foo\":\"bar\"}}]", - serialised_field_3: "{\"foo\":\"bar\"}", - serialised_field_4: "[]", - serialised_field_5: "{}", - serialised_field_6: nil } + serialised_field_one: "[\"foo\",\"bar\"]", + serialised_field_two: "[{\"position\":\"gestor\",\"name\":\"JOSE MANUEL REYES R.\",\"other_attributes\":{\"foo\":\"bar\"}}]", + serialised_field_three: "{\"foo\":\"bar\"}", + serialised_field_four: "[]", + serialised_field_five: "{}", + serialised_field_six: nil } end context "in general" do @@ -949,20 +953,20 @@ module ModuleWithNoCustomPrimaryKey end it "deserializes fields" do - expect(@processed_data[:serialised_field_1]).to eq(%w[foo bar]) - expect(@processed_data[:serialised_field_3]).to eq("foo" => "bar") - expect(@processed_data[:serialised_field_4]).to eq([]) - expect(@processed_data[:serialised_field_5]).to eq({}) + expect(@processed_data[:serialised_field_one]).to eq(%w[foo bar]) + expect(@processed_data[:serialised_field_three]).to eq("foo" => "bar") + expect(@processed_data[:serialised_field_four]).to eq([]) + expect(@processed_data[:serialised_field_five]).to eq({}) end it "deserializes nested fields correctly" do - expect(@processed_data[:serialised_field_2].first[:position]).to eq("gestor") - expect(@processed_data[:serialised_field_2].first[:other_attributes][:foo]).to eq("bar") + expect(@processed_data[:serialised_field_two].first[:position]).to eq("gestor") + expect(@processed_data[:serialised_field_two].first[:other_attributes][:foo]).to eq("bar") end it "does not do anything with null value" do - expect(@processed_data[:serialised_field_6]).to be_nil - expect(@processed_data.key?(:serialised_field_6)).to be true + expect(@processed_data[:serialised_field_six]).to be_nil + expect(@processed_data.key?(:serialised_field_six)).to be true end end @@ -972,7 +976,7 @@ module ModuleWithNoCustomPrimaryKey end it "removes value from result" do - expect(@processed_data.key?(:serialised_field_6)).to be false + expect(@processed_data.key?(:serialised_field_six)).to be false end end diff --git a/spec/lib/openc_bot_spec.rb b/spec/lib/openc_bot_spec.rb index cac4790f..8270282c 100644 --- a/spec/lib/openc_bot_spec.rb +++ b/spec/lib/openc_bot_spec.rb @@ -70,8 +70,8 @@ expect(namespace).to eq("fetcher_bot.test.foobot") end - it "configures statsd mode based on the bot's environment" do - expect(StatsD.mode).to eq(:test) + it "configures statds environment based on the bot's environment" do + expect(ENV["STATSD_ENV"]).to eq("test") end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2e346a27..5ea3fedd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,8 +7,10 @@ WebMock.disable_net_connect!(allow_localhost: true) +# rubocop:disable Lint/EmptyBlock RSpec.configure do |config| end +# rubocop:enable Lint/EmptyBlock def remove_test_database File.delete(test_database_location) if File.exist?(test_database_location)