From 6a9632cf46b34a8109371f6b8fa21e861894af90 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 30 Dec 2023 21:26:41 +0200 Subject: [PATCH 01/13] Fix issue with running specs with Rails 7.1 --- Gemfile | 8 ++++++++ Gemfile.lock | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 30ff51b9..1dcbe968 100644 --- a/Gemfile +++ b/Gemfile @@ -48,4 +48,12 @@ if ENV['CI'].nil? platforms :ruby do gem 'pry-byebug' end + + gem 'activemodel', '= 7.0.4' + + # There is an issue with Rails 7.1 fixed in 3.12.5. + # See: + # - https://github.com/rspec/rspec-mocks/pull/1534 + # - https://github.com/rspec/rspec-mocks/issues/1530 + gem 'rspec-mocks', '>= 3.12.5' end diff --git a/Gemfile.lock b/Gemfile.lock index c0ce2748..7b6cad7a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dynamoid (3.8.0) + dynamoid (3.9.0) activemodel (>= 4) aws-sdk-dynamodb (~> 1.0) concurrent-ruby (>= 1.0) @@ -21,17 +21,17 @@ GEM rake thor (>= 0.14.0) ast (2.4.2) - aws-eventstream (1.2.0) - aws-partitions (1.679.0) - aws-sdk-core (3.168.4) - aws-eventstream (~> 1, >= 1.0.2) + aws-eventstream (1.3.0) + aws-partitions (1.876.0) + aws-sdk-core (3.190.1) + aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) - aws-sigv4 (~> 1.5) + aws-sigv4 (~> 1.8) jmespath (~> 1, >= 1.6.1) - aws-sdk-dynamodb (1.80.0) - aws-sdk-core (~> 3, >= 3.165.0) + aws-sdk-dynamodb (1.98.0) + aws-sdk-core (~> 3, >= 3.188.0) aws-sigv4 (~> 1.1) - aws-sigv4 (1.5.2) + aws-sigv4 (1.8.0) aws-eventstream (~> 1, >= 1.0.2) byebug (11.1.3) childprocess (4.1.0) @@ -74,7 +74,7 @@ GEM rspec-expectations (3.12.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.1) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) @@ -131,6 +131,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + activemodel (= 7.0.4) appraisal bundler codecov (~> 0.6) @@ -141,6 +142,7 @@ DEPENDENCIES pry-debugger-jruby rake (~> 13.0) rspec (~> 3.12) + rspec-mocks (>= 3.12.5) rubocop-lts (~> 10.0) rubocop-md rubocop-packaging From b8e3a24775e5cd075d7e801b6520463526969b5f Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 30 Dec 2023 21:35:48 +0200 Subject: [PATCH 02/13] Add Rails 7.1 on CI --- .github/workflows/ci.yml | 11 +++++++++++ Appraisals | 8 ++++++++ README.md | 2 +- gemfiles/rails_7_1.gemfile | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11121f58..df1a71f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,7 @@ jobs: - rails_6_0 - rails_6_1 - rails_7_0 + - rails_7_1 rubygems: - default bundler: @@ -54,6 +55,16 @@ jobs: - "3.2" exclude: + # Rails 7.1 requires Ruby 2.7 and above + - gemfile: rails_7_1 + ruby: "2.3" + - gemfile: rails_7_1 + ruby: "2.4" + - gemfile: rails_7_1 + ruby: "2.5" + - gemfile: rails_7_1 + ruby: "2.6" + # Rails 7.0 requires Ruby 2.7 and above - gemfile: rails_7_0 ruby: "2.3" diff --git a/Appraisals b/Appraisals index aebf4889..6c52ab40 100644 --- a/Appraisals +++ b/Appraisals @@ -32,3 +32,11 @@ end appraise 'rails-6-1' do gem 'activemodel', '~> 6.1.0' end + +appraise 'rails-7-0' do + gem 'activemodel', '~> 7.0.0' +end + +appraise 'rails-7-1' do + gem 'activemodel', '~> 7.1.0' +end diff --git a/README.md b/README.md index b22b93d9..fbc3dd9b 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Dynamoid supports Ruby >= 2.3 and Rails >= 4.2. Its compatibility is tested against following Ruby versions: 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1 and 3.2, JRuby 9.4.x and against Rails versions: 4.2, 5.0, 5.1, -5.2, 6.0, 6.1 and 7.0. +5.2, 6.0, 6.1, 7.0 and 7.1. ## Setup diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 00000000..a24915c6 --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source 'https://rubygems.org' + +gem 'activemodel', '~> 7.1.0' +gem 'pry-byebug', platforms: :ruby + +gemspec path: '../' From fdb4f36c5224bbcb38a9df3c3dc8af8c0c3daa93 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 30 Dec 2023 21:40:08 +0200 Subject: [PATCH 03/13] Add Ruby 3.3 on CI --- .github/workflows/ci.yml | 10 ++++++++++ README.md | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df1a71f3..1710b7a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,7 @@ jobs: - "3.0" - "3.1" - "3.2" + - "3.3" exclude: # Rails 7.1 requires Ruby 2.7 and above @@ -112,6 +113,15 @@ jobs: gemfile: rails_5_1 - ruby: "3.2" gemfile: rails_5_2 + - ruby: "3.3" + gemfile: rails_4_2 + - ruby: "3.3" + gemfile: rails_5_0 + - ruby: "3.3" + gemfile: rails_5_1 + - ruby: "3.3" + gemfile: rails_5_2 + - ruby: "jruby" gemfile: rails_4_2 - ruby: "jruby" diff --git a/README.md b/README.md index fbc3dd9b..29ff2410 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ end Dynamoid supports Ruby >= 2.3 and Rails >= 4.2. Its compatibility is tested against following Ruby versions: 2.3, 2.4, -2.5, 2.6, 2.7, 3.0, 3.1 and 3.2, JRuby 9.4.x and against Rails versions: 4.2, 5.0, 5.1, +2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and 3.3, JRuby 9.4.x and against Rails versions: 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0 and 7.1. ## Setup From 8bc19d055a592500f2b1096902e31e0e80e4370b Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 30 Dec 2023 21:57:35 +0200 Subject: [PATCH 04/13] Fix failed spec that depends on DynamoDB response structure --- spec/dynamoid/log/formatter/debug_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/dynamoid/log/formatter/debug_spec.rb b/spec/dynamoid/log/formatter/debug_spec.rb index d896df44..af8b3fd7 100644 --- a/spec/dynamoid/log/formatter/debug_spec.rb +++ b/spec/dynamoid/log/formatter/debug_spec.rb @@ -63,7 +63,8 @@ \\}, "TableSizeBytes": 0, "ItemCount": 0, - "TableArn": ".+?" + "TableArn": ".+?", + "DeletionProtectionEnabled": false \\} \\} JSON From ff8bc2064e7e09983601774c53fcb9ffd0f81197 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 30 Dec 2023 22:05:17 +0200 Subject: [PATCH 05/13] Update development environment to use Ruby 3.3.0 and Rails 7.1.2 --- .ruby-version | 1 + Gemfile | 8 --- Gemfile.lock | 163 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 111 insertions(+), 61 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..15a27998 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.3.0 diff --git a/Gemfile b/Gemfile index 1dcbe968..30ff51b9 100644 --- a/Gemfile +++ b/Gemfile @@ -48,12 +48,4 @@ if ENV['CI'].nil? platforms :ruby do gem 'pry-byebug' end - - gem 'activemodel', '= 7.0.4' - - # There is an issue with Rails 7.1 fixed in 3.12.5. - # See: - # - https://github.com/rspec/rspec-mocks/pull/1534 - # - https://github.com/rspec/rspec-mocks/issues/1530 - gem 'rspec-mocks', '>= 3.12.5' end diff --git a/Gemfile.lock b/Gemfile.lock index 7b6cad7a..2dd53fff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,14 +9,19 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (7.0.4) - activesupport (= 7.0.4) - activesupport (7.0.4) + activemodel (7.1.2) + activesupport (= 7.1.2) + activesupport (7.1.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - appraisal (2.4.1) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) @@ -33,76 +38,116 @@ GEM aws-sigv4 (~> 1.1) aws-sigv4 (1.8.0) aws-eventstream (~> 1, >= 1.0.2) + base64 (0.2.0) + bigdecimal (3.1.5) byebug (11.1.3) childprocess (4.1.0) codecov (0.6.0) simplecov (>= 0.15, < 0.22) coderay (1.1.3) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) diff-lcs (1.5.0) + diffy (3.4.2) docile (1.4.0) - i18n (1.12.0) + drb (2.2.0) + ruby2_keywords + i18n (1.14.1) concurrent-ruby (~> 1.0) iniparse (1.5.0) - jaro_winkler (1.5.4) jmespath (1.6.2) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) method_source (1.0.0) - minitest (5.16.3) - overcommit (0.59.1) + minitest (5.20.0) + mutex_m (0.2.0) + overcommit (0.61.0) childprocess (>= 0.6.3, < 5) iniparse (~> 1.4) rexml (~> 3.2) - parallel (1.22.1) - parser (3.1.3.0) + parallel (1.24.0) + parser (3.2.2.4) ast (~> 2.4.1) + racc pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.8.0) + pry-byebug (3.10.1) byebug (~> 11.0) - pry (~> 0.10) + pry (>= 0.13, < 0.15) + racc (1.7.3) rainbow (3.1.1) - rake (13.0.6) - rexml (3.2.5) + rake (13.1.0) + regexp_parser (2.8.3) + rexml (3.2.6) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) + rspec-core (3.12.2) rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-support (3.12.0) - rubocop (0.81.0) - jaro_winkler (~> 1.5.1) + rspec-support (3.12.1) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) - rexml + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-lts (10.0.1) - rubocop-ruby2_3 (~> 1.0.3) - rubocop-md (0.4.1) - rubocop (>= 0.60) - rubocop-packaging (0.1.1) - rubocop (>= 0.75.0) - rubocop-performance (1.6.1) - rubocop (>= 0.71.0) - rubocop-rake (0.5.1) - rubocop - rubocop-rspec (1.41.0) - rubocop (>= 0.68.1) - rubocop-ruby2_3 (1.0.3) - rubocop (= 0.81.0) - rubocop-thread_safety (0.4.4) - rubocop (>= 0.53.0) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) + rubocop-gradual (0.3.4) + diff-lcs (>= 1.2.0, < 2.0) + diffy (~> 3.0) + parallel (~> 1.10) + rainbow (>= 2.2.2, < 4.0) + rubocop (~> 1.0) + rubocop-lts (10.1.1) + rubocop-ruby2_3 (>= 2.0.3, < 3) + standard-rubocop-lts (>= 1.0.3, < 3) + version_gem (>= 1.1.2, < 3) + rubocop-md (1.2.2) + rubocop (>= 1.0) + rubocop-packaging (0.5.2) + rubocop (>= 1.33, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.25.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-ruby2_3 (2.0.5) + rubocop-gradual (~> 0.3, >= 0.3.1) + rubocop-md (~> 1.2) + rubocop-rake (~> 0.6) + rubocop-shopify (~> 2.14) + rubocop-thread_safety (~> 0.5, >= 0.5.1) + standard-rubocop-lts (~> 1.0, >= 1.0.7) + version_gem (>= 1.1.3, < 3) + rubocop-shopify (2.14.0) + rubocop (~> 1.51) + rubocop-thread_safety (0.5.1) + rubocop (>= 0.90.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -116,22 +161,35 @@ GEM simplecov simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) - thor (1.2.1) - tzinfo (2.0.5) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.1) + standard-rubocop-lts (1.0.9) + standard (>= 1.31.1, < 2) + standard-custom (>= 1.0.1, < 2) + standard-performance (>= 1.2, < 2) + version_gem (>= 1.1.3, < 4) + thor (1.3.0) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (1.8.0) - webrick (1.7.0) - yard (0.9.28) - webrick (~> 1.7.0) + unicode-display_width (2.5.0) + version_gem (1.1.3) + yard (0.9.34) PLATFORMS - x86_64-darwin-19 - x86_64-darwin-21 + ruby x86_64-darwin-22 - x86_64-linux DEPENDENCIES - activemodel (= 7.0.4) appraisal bundler codecov (~> 0.6) @@ -142,7 +200,6 @@ DEPENDENCIES pry-debugger-jruby rake (~> 13.0) rspec (~> 3.12) - rspec-mocks (>= 3.12.5) rubocop-lts (~> 10.0) rubocop-md rubocop-packaging @@ -157,4 +214,4 @@ DEPENDENCIES yard BUNDLED WITH - 2.3.26 + 2.5.3 From 6e4273dfdc42df1d184c7cb702790773b8bbe70b Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 01:15:41 +0200 Subject: [PATCH 06/13] Remove rubocop-lts gem Rubocop supports now TargetRubyVersion for EOL Ruby versions down to 2.3. See https://docs.rubocop.org/rubocop/1.59/compatibility.html: > RuboCop targets Ruby 2.0+ code analysis since RuboCop 1.30. It restored code analysis support that had been removed earlier by mistake, together with dropping runtime support for unsupported Ruby versions. --- .rubocop.yml | 3 --- Gemfile.lock | 41 ----------------------------------------- dynamoid.gemspec | 2 -- 3 files changed, 46 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2dc79713..27d9fdc0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,9 +5,6 @@ inherit_from: - .rubocop_thread_safety.yml - .rubocop_todo.yml -inherit_gem: - rubocop-lts: rubocop-lts.yml - require: - rubocop-md - rubocop-packaging diff --git a/Gemfile.lock b/Gemfile.lock index 2dd53fff..49271c34 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,7 +48,6 @@ GEM concurrent-ruby (1.2.2) connection_pool (2.4.1) diff-lcs (1.5.0) - diffy (3.4.2) docile (1.4.0) drb (2.2.0) ruby2_keywords @@ -58,7 +57,6 @@ GEM jmespath (1.6.2) json (2.7.1) language_server-protocol (3.17.0.3) - lint_roller (1.1.0) method_source (1.0.0) minitest (5.20.0) mutex_m (0.2.0) @@ -111,16 +109,6 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.24.0) rubocop (~> 1.33) - rubocop-gradual (0.3.4) - diff-lcs (>= 1.2.0, < 2.0) - diffy (~> 3.0) - parallel (~> 1.10) - rainbow (>= 2.2.2, < 4.0) - rubocop (~> 1.0) - rubocop-lts (10.1.1) - rubocop-ruby2_3 (>= 2.0.3, < 3) - standard-rubocop-lts (>= 1.0.3, < 3) - version_gem (>= 1.1.2, < 3) rubocop-md (1.2.2) rubocop (>= 1.0) rubocop-packaging (0.5.2) @@ -134,16 +122,6 @@ GEM rubocop (~> 1.40) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) - rubocop-ruby2_3 (2.0.5) - rubocop-gradual (~> 0.3, >= 0.3.1) - rubocop-md (~> 1.2) - rubocop-rake (~> 0.6) - rubocop-shopify (~> 2.14) - rubocop-thread_safety (~> 0.5, >= 0.5.1) - standard-rubocop-lts (~> 1.0, >= 1.0.7) - version_gem (>= 1.1.3, < 3) - rubocop-shopify (2.14.0) - rubocop (~> 1.51) rubocop-thread_safety (0.5.1) rubocop (>= 0.90.0) ruby-progressbar (1.13.0) @@ -161,28 +139,10 @@ GEM simplecov simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) - standard (1.33.0) - language_server-protocol (~> 3.17.0.2) - lint_roller (~> 1.0) - rubocop (~> 1.59.0) - standard-custom (~> 1.0.0) - standard-performance (~> 1.3) - standard-custom (1.0.2) - lint_roller (~> 1.0) - rubocop (~> 1.50) - standard-performance (1.3.0) - lint_roller (~> 1.1) - rubocop-performance (~> 1.20.1) - standard-rubocop-lts (1.0.9) - standard (>= 1.31.1, < 2) - standard-custom (>= 1.0.1, < 2) - standard-performance (>= 1.2, < 2) - version_gem (>= 1.1.3, < 4) thor (1.3.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) - version_gem (1.1.3) yard (0.9.34) PLATFORMS @@ -200,7 +160,6 @@ DEPENDENCIES pry-debugger-jruby rake (~> 13.0) rspec (~> 3.12) - rubocop-lts (~> 10.0) rubocop-md rubocop-packaging rubocop-performance diff --git a/dynamoid.gemspec b/dynamoid.gemspec index 814235fb..c590f521 100644 --- a/dynamoid.gemspec +++ b/dynamoid.gemspec @@ -60,7 +60,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'pry', '~> 0.14' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.12' - # 'rubocop-lts' is for Ruby 2.3+, see https://rubocop-lts.gitlab.io/ - spec.add_development_dependency 'rubocop-lts', '~> 10.0' spec.add_development_dependency 'yard' end From f87b84228efdaecb407a04e6fad6519545159ce8 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 01:16:22 +0200 Subject: [PATCH 07/13] Run rubocop on CI on Ruby 3.3 --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 1dc8b183..c9059d4b 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -23,7 +23,7 @@ jobs: bundler: - latest ruby: - - "2.7" + - "3.3" runs-on: ubuntu-latest env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/style.gemfile From 5e3bfc1a25d1a110c58ac553c6d6fa8056c8cbf7 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 01:17:56 +0200 Subject: [PATCH 08/13] Explicitly set up Ruby 2.3 syntax for Rubocop --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index 27d9fdc0..3dec5c25 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,7 @@ require: # It's the lowest supported Ruby version AllCops: DisplayCopNames: true # Display the name of the failing cops + TargetRubyVersion: 2.3 # It's a matter of taste Layout/ParameterAlignment: From 583347c8791c737b2e9d31eaa8368f9e728d60e5 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 01:23:53 +0200 Subject: [PATCH 09/13] Automatically correct with Rubocop --- .simplecov | 2 +- Gemfile | 2 +- README.md | 14 +++--- Rakefile | 2 +- lib/dynamoid/adapter_plugin/aws_sdk_v3.rb | 2 +- .../adapter_plugin/aws_sdk_v3/create_table.rb | 4 +- .../adapter_plugin/aws_sdk_v3/item_updater.rb | 3 +- lib/dynamoid/associations.rb | 2 +- lib/dynamoid/criteria/chain.rb | 2 +- .../criteria/nonexistent_fields_detector.rb | 4 +- lib/dynamoid/dirty.rb | 2 +- lib/dynamoid/dumping.rb | 4 +- lib/dynamoid/fields.rb | 12 ++--- lib/dynamoid/fields/declare.rb | 12 ++--- lib/dynamoid/finders.rb | 2 +- lib/dynamoid/indexes.rb | 13 +++--- lib/dynamoid/loadable.rb | 4 +- lib/dynamoid/persistence.rb | 2 +- lib/dynamoid/persistence/save.rb | 24 ++++------ .../persistence/update_validations.rb | 2 +- lib/dynamoid/type_casting.rb | 18 +++----- lib/dynamoid/undumping.rb | 2 +- .../adapter_plugin/aws_sdk_v3_spec.rb | 44 +++++++++--------- spec/dynamoid/adapter_spec.rb | 16 +++---- spec/dynamoid/associations/has_one_spec.rb | 2 +- spec/dynamoid/criteria/chain_spec.rb | 24 +++++----- spec/dynamoid/criteria_spec.rb | 6 +-- spec/dynamoid/document_spec.rb | 4 +- spec/dynamoid/dumping_spec.rb | 4 +- spec/dynamoid/finders_spec.rb | 6 +-- spec/dynamoid/identity_map_spec.rb | 2 +- spec/dynamoid/loadable_spec.rb | 2 +- spec/dynamoid/persistence_spec.rb | 46 +++++++++---------- spec/dynamoid/sti_spec.rb | 2 +- spec/spec_helper.rb | 6 +-- spec/support/config.rb | 6 +-- spec/support/helpers/new_class_helper.rb | 4 +- 37 files changed, 148 insertions(+), 160 deletions(-) diff --git a/.simplecov b/.simplecov index 3a55b238..32fe34e7 100644 --- a/.simplecov +++ b/.simplecov @@ -21,7 +21,7 @@ if RUN_COVERAGE track_files '**/*.rb' if ALL_FORMATTERS - command_name "#{ENV['GITHUB_WORKFLOW']} Job #{ENV['GITHUB_RUN_ID']}:#{ENV['GITHUB_RUN_NUMBER']}" + command_name "#{ENV.fetch('GITHUB_WORKFLOW')} Job #{ENV.fetch('GITHUB_RUN_ID')}:#{ENV.fetch('GITHUB_RUN_NUMBER')}" else formatter SimpleCov::Formatter::HTMLFormatter end diff --git a/Gemfile b/Gemfile index 30ff51b9..0b5de506 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gemspec # All CI jobs must use a discrete Gemfile located at gemfiles/*.gemfile. They will not use this Gemfile if ENV['CI'].nil? ruby_version = Gem::Version.new(RUBY_VERSION) - minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == engine } + minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && engine == RUBY_ENGINE } committing = minimum_version.call('2.4') linting = minimum_version.call('2.7') coverage = minimum_version.call('2.7') diff --git a/README.md b/README.md index 29ff2410..32d954ea 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,10 @@ For example, to configure AWS access: Create `config/initializers/aws.rb` as follows: ```ruby -Aws.config.update({ - region: 'us-west-2', +Aws.config.update( + region: 'us-west-2', credentials: Aws::Credentials.new('REPLACE_WITH_ACCESS_KEY_ID', 'REPLACE_WITH_SECRET_ACCESS_KEY'), - }) +) ``` Alternatively, if you don't want Aws connection settings to be @@ -740,7 +740,7 @@ If Dynamoid keeps `nil` value attributes `eq`/`ne` operators should be used instead: ```ruby -Address.where('postcode': nil) +Address.where(postcode: nil) Address.where('postcode.ne': nil) ``` @@ -914,8 +914,8 @@ If you have a range index, Dynamoid provides a number of additional other convenience methods to make your life a little easier: ```ruby -User.where("created_at.gt": DateTime.now - 1.day).all -User.where("created_at.lt": DateTime.now - 1.day).all +User.where('created_at.gt': DateTime.now - 1.day).all +User.where('created_at.lt': DateTime.now - 1.day).all ``` It also supports `gte` and `lte`. Turning those into symbols and @@ -1295,7 +1295,7 @@ end In addition, the first test for each model may fail if the relevant models are not included in `included_models`. This can be fixed by adding this line before the `DynamoidReset` module: ```ruby -Dir[File.join(Dynamoid::Config.models_dir, '**/*.rb')].each { |file| require file } +Dir[File.join(Dynamoid::Config.models_dir, '**/*.rb')].sort.each { |file| require file } ``` Note that this will require _all_ models in your models folder - you can also explicitly require only certain models if you would prefer to. diff --git a/Rakefile b/Rakefile index d90a89ba..638792c8 100644 --- a/Rakefile +++ b/Rakefile @@ -20,7 +20,7 @@ desc 'alias test task to spec' task test: :spec ruby_version = Gem::Version.new(RUBY_VERSION) -minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == engine } +minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && engine == RUBY_ENGINE } linting = minimum_version.call('2.7') def rubocop_task(warning) desc 'rubocop task stub' diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb index d3687299..72c3219c 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb @@ -14,7 +14,7 @@ module Dynamoid module AdapterPlugin # The AwsSdkV3 adapter provides support for the aws-sdk version 2 for ruby. - # Note: Don't use keyword arguments in public methods as far as method + # NOTE: Don't use keyword arguments in public methods as far as method # calls on adapter are delegated to the plugin. # # There are breaking changes in Ruby related to delegating keyword diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb index 6c1c6f35..b9f04198 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb @@ -29,7 +29,7 @@ def call gs_indexes = options[:global_secondary_indexes] key_schema = { - hash_key_schema: { key => (options[:hash_key_type] || :string) }, + hash_key_schema: { key => options[:hash_key_type] || :string }, range_key_schema: options[:range_key] } attribute_definitions = build_all_attribute_definitions( @@ -69,7 +69,7 @@ def call end end resp = client.create_table(client_opts) - options[:sync] = true if !options.key?(:sync) && ls_indexes.present? || gs_indexes.present? + options[:sync] = true if (!options.key?(:sync) && ls_indexes.present?) || gs_indexes.present? if options[:sync] status = PARSE_TABLE_STATUS.call(resp, :table_description) diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb index cac53c6f..d30a5247 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb @@ -57,13 +57,12 @@ def set(values) else # delete explicitly attributes if assigned nil value and configured # to not store nil values - values_to_update = values_sanitized.select { |_, v| !v.nil? } + values_to_update = values_sanitized.reject { |_, v| v.nil? } values_to_delete = values_sanitized.select { |_, v| v.nil? } @updates.merge!(values_to_update) @deletions.merge!(values_to_delete) end - end # diff --git a/lib/dynamoid/associations.rb b/lib/dynamoid/associations.rb index 8dc800ab..8491c22f 100644 --- a/lib/dynamoid/associations.rb +++ b/lib/dynamoid/associations.rb @@ -265,7 +265,7 @@ def association(type, name, options = {}) @associations[:"#{name}_ids"] ||= Dynamoid::Associations.const_get(type.to_s.camelcase).new(self, name, options) end - define_method("#{name}=".to_sym) do |objects| + define_method(:"#{name}=") do |objects| @associations[:"#{name}_ids"] ||= Dynamoid::Associations.const_get(type.to_s.camelcase).new(self, name, options) @associations[:"#{name}_ids"].setter(objects) end diff --git a/lib/dynamoid/criteria/chain.rb b/lib/dynamoid/criteria/chain.rb index 2902803b..a498c9e5 100644 --- a/lib/dynamoid/criteria/chain.rb +++ b/lib/dynamoid/criteria/chain.rb @@ -593,7 +593,7 @@ def field_condition(key, value_before_type_casting) raise Dynamoid::Errors::Error, "Unsupported operator #{operator} in #{key}" end - condition = \ + condition = case operator # NULL/NOT_NULL operators don't have parameters # So { null: true } means NULL check and { null: false } means NOT_NULL one diff --git a/lib/dynamoid/criteria/nonexistent_fields_detector.rb b/lib/dynamoid/criteria/nonexistent_fields_detector.rb index fcd496e8..fbda05b7 100644 --- a/lib/dynamoid/criteria/nonexistent_fields_detector.rb +++ b/lib/dynamoid/criteria/nonexistent_fields_detector.rb @@ -20,8 +20,8 @@ def warning_message fields_list = @nonexistent_fields.map { |s| "`#{s}`" }.join(', ') count = @nonexistent_fields.size - 'where conditions contain nonexistent' \ - " field #{'name'.pluralize(count)} #{fields_list}" + 'where conditions contain nonexistent ' \ + "field #{'name'.pluralize(count)} #{fields_list}" end private diff --git a/lib/dynamoid/dirty.rb b/lib/dynamoid/dirty.rb index 63eacf5a..5be07d81 100644 --- a/lib/dynamoid/dirty.rb +++ b/lib/dynamoid/dirty.rb @@ -238,7 +238,7 @@ def attribute_will_change!(name) begin value = read_attribute(name) - value = value.duplicable? ? value.clone : value + value = value.clone if value.duplicable? rescue TypeError, NoMethodError end diff --git a/lib/dynamoid/dumping.rb b/lib/dynamoid/dumping.rb index e7477875..5965469b 100644 --- a/lib/dynamoid/dumping.rb +++ b/lib/dynamoid/dumping.rb @@ -210,7 +210,7 @@ def process(value) # datetime -> integer/string class DateTimeDumper < Base def process(value) - !value.nil? ? format_datetime(value, @options) : nil + value.nil? ? nil : format_datetime(value, @options) end private @@ -237,7 +237,7 @@ def format_datetime(value, options) # date -> integer/string class DateDumper < Base def process(value) - !value.nil? ? format_date(value, @options) : nil + value.nil? ? nil : format_date(value, @options) end private diff --git a/lib/dynamoid/fields.rb b/lib/dynamoid/fields.rb index 373c412d..4b09bace 100644 --- a/lib/dynamoid/fields.rb +++ b/lib/dynamoid/fields.rb @@ -263,10 +263,8 @@ def timestamps_enabled? # @private def generated_methods - @generated_methods ||= begin - Module.new.tap do |mod| - include(mod) - end + @generated_methods ||= Module.new.tap do |mod| + include(mod) end end end @@ -362,7 +360,7 @@ def set_expires_field seconds = options[:after] if self[name].blank? - send("#{name}=", Time.now.to_i + seconds) + send(:"#{name}=", Time.now.to_i + seconds) end end end @@ -374,12 +372,12 @@ def set_inheritance_field type = self.class.inheritance_field if self.class.attributes[type] && send(type).nil? - send("#{type}=", self.class.sti_name) + send(:"#{type}=", self.class.sti_name) end end def attribute_is_present_on_model?(attribute_name) - setter = "#{attribute_name}=".to_sym + setter = :"#{attribute_name}=" respond_to?(setter) end end diff --git a/lib/dynamoid/fields/declare.rb b/lib/dynamoid/fields/declare.rb index 5a4f58bb..e8aaae42 100644 --- a/lib/dynamoid/fields/declare.rb +++ b/lib/dynamoid/fields/declare.rb @@ -48,7 +48,7 @@ def generate_instance_methods @source.generated_methods.module_eval do define_method(name) { read_attribute(name) } - define_method("#{name}?") do + define_method(:"#{name}?") do value = read_attribute(name) case value when true then true @@ -57,8 +57,8 @@ def generate_instance_methods !value.nil? end end - define_method("#{name}=") { |value| write_attribute(name, value) } - define_method("#{name}_before_type_cast") { read_attribute_before_type_cast(name) } + define_method(:"#{name}=") { |value| write_attribute(name, value) } + define_method(:"#{name}_before_type_cast") { read_attribute_before_type_cast(name) } end end @@ -70,9 +70,9 @@ def generate_instance_methods_for_alias @source.generated_methods.module_eval do alias_method alias_name, name - alias_method "#{alias_name}=", "#{name}=" - alias_method "#{alias_name}?", "#{name}?" - alias_method "#{alias_name}_before_type_cast", "#{name}_before_type_cast" + alias_method :"#{alias_name}=", :"#{name}=" + alias_method :"#{alias_name}?", :"#{name}?" + alias_method :"#{alias_name}_before_type_cast", :"#{name}_before_type_cast" end end diff --git a/lib/dynamoid/finders.rb b/lib/dynamoid/finders.rb index f047357a..ec75a820 100644 --- a/lib/dynamoid/finders.rb +++ b/lib/dynamoid/finders.rb @@ -299,7 +299,7 @@ def method_missing(method, *args) chain = Dynamoid::Criteria::Chain.new(self) chain = chain.where({}.tap { |h| attributes.each_with_index { |attr, index| h[attr.to_sym] = args[index] } }) - if finder =~ /all/ + if finder.include?('all') chain.all else chain.first diff --git a/lib/dynamoid/indexes.rb b/lib/dynamoid/indexes.rb index e83c41b5..7155a0aa 100644 --- a/lib/dynamoid/indexes.rb +++ b/lib/dynamoid/indexes.rb @@ -130,13 +130,13 @@ def local_secondary_index(options = {}) index_range_key = options[:range_key] unless index_range_key.present? - raise Dynamoid::Errors::InvalidIndex, 'A local secondary index '\ - 'requires a :range_key to be specified' + raise Dynamoid::Errors::InvalidIndex, 'A local secondary index ' \ + 'requires a :range_key to be specified' end if primary_range_key.present? && index_range_key == primary_range_key - raise Dynamoid::Errors::InvalidIndex, 'A local secondary index'\ - ' must use a different :range_key than the primary key' + raise Dynamoid::Errors::InvalidIndex, 'A local secondary index ' \ + 'must use a different :range_key than the primary key' end index_opts = options.merge( @@ -159,8 +159,7 @@ def local_secondary_index(options = {}) # @param range [scalar] the range key used to declare an index (optional) # @return [Dynamoid::Indexes::Index, nil] index object or nil if it isn't found def find_index(hash, range = nil) - index = indexes[index_key(hash, range)] - index + indexes[index_key(hash, range)] end # Returns an index by its name @@ -317,7 +316,7 @@ def validate_index_key(key_param, key_val) key_dynamodb_type = dynamodb_type(key_field_attributes[:type], key_field_attributes) if PERMITTED_KEY_DYNAMODB_TYPES.include?(key_dynamodb_type) - send("#{key_param}_schema=", { key_val => key_dynamodb_type }) + send(:"#{key_param}_schema=", { key_val => key_dynamodb_type }) else errors.add(key_param, "Index :#{key_param} is not a valid key type") end diff --git a/lib/dynamoid/loadable.rb b/lib/dynamoid/loadable.rb index 555ed0a3..2fbe285a 100644 --- a/lib/dynamoid/loadable.rb +++ b/lib/dynamoid/loadable.rb @@ -6,7 +6,7 @@ module Loadable def load(attrs) attrs.each do |key, value| - send("#{key}=", value) if respond_to?("#{key}=") + send(:"#{key}=", value) if respond_to?(:"#{key}=") end self @@ -27,7 +27,7 @@ def reload self.attributes = self.class.find(hash_key, **options).attributes - @associations.values.each(&:reset) + @associations.each_value(&:reset) @new_record = false self diff --git a/lib/dynamoid/persistence.rb b/lib/dynamoid/persistence.rb index b82dabdd..3d453882 100644 --- a/lib/dynamoid/persistence.rb +++ b/lib/dynamoid/persistence.rb @@ -924,7 +924,7 @@ def delete Dynamoid.adapter.delete(self.class.table_name, hash_key, options) - self.class.associations.each do |name, _options| + self.class.associations.each_key do |name| send(name).disassociate_source end diff --git a/lib/dynamoid/persistence/save.rb b/lib/dynamoid/persistence/save.rb index f586bc06..787f9ca0 100644 --- a/lib/dynamoid/persistence/save.rb +++ b/lib/dynamoid/persistence/save.rb @@ -68,13 +68,11 @@ def conditions_for_write end # Add an optimistic locking check if the lock_version column exists - if @model.class.attributes[:lock_version] - # Uses the original lock_version value from Dirty API - # in case user changed 'lock_version' manually - if @model.changes[:lock_version][0] - conditions[:if] ||= {} - conditions[:if][:lock_version] = @model.changes[:lock_version][0] - end + # Uses the original lock_version value from Dirty API + # in case user changed 'lock_version' manually + if @model.class.attributes[:lock_version] && (@model.changes[:lock_version][0]) + conditions[:if] ||= {} + conditions[:if][:lock_version] = @model.changes[:lock_version][0] end conditions @@ -93,13 +91,11 @@ def options_to_update_item conditions[:if][@model.class.hash_key] = @model.hash_key # Add an optimistic locking check if the lock_version column exists - if @model.class.attributes[:lock_version] - # Uses the original lock_version value from Dirty API - # in case user changed 'lock_version' manually - if @model.changes[:lock_version][0] - conditions[:if] ||= {} - conditions[:if][:lock_version] = @model.changes[:lock_version][0] - end + # Uses the original lock_version value from Dirty API + # in case user changed 'lock_version' manually + if @model.class.attributes[:lock_version] && (@model.changes[:lock_version][0]) + conditions[:if] ||= {} + conditions[:if][:lock_version] = @model.changes[:lock_version][0] end options[:conditions] = conditions diff --git a/lib/dynamoid/persistence/update_validations.rb b/lib/dynamoid/persistence/update_validations.rb index c9d1bb91..b9b663c1 100644 --- a/lib/dynamoid/persistence/update_validations.rb +++ b/lib/dynamoid/persistence/update_validations.rb @@ -7,7 +7,7 @@ module UpdateValidations def self.validate_attributes_exist(model_class, attributes) model_attributes = model_class.attributes.keys - attributes.each do |attr_name, _| + attributes.each_key do |attr_name| unless model_attributes.include?(attr_name) raise Dynamoid::Errors::UnknownAttribute, "Attribute #{attr_name} does not exist in #{model_class}" end diff --git a/lib/dynamoid/type_casting.rb b/lib/dynamoid/type_casting.rb index 564d98b9..ec3723eb 100644 --- a/lib/dynamoid/type_casting.rb +++ b/lib/dynamoid/type_casting.rb @@ -135,7 +135,7 @@ def process_typed_set(set) raise ArgumentError, "Set element type #{element_type} isn't supported" end - set.map { |el| type_caster.process(el) }.to_set + set.to_set { |el| type_caster.process(el) } end def element_type @@ -227,10 +227,10 @@ def process(value) nil elsif value.is_a?(String) dt = begin - DateTime.parse(value) - rescue StandardError - nil - end + DateTime.parse(value) + rescue StandardError + nil + end if dt seconds = string_utc_offset(value) || ApplicationTimeZone.utc_offset offset = seconds_to_offset(seconds) @@ -255,9 +255,7 @@ def seconds_to_offset(seconds) class DateTypeCaster < Base def process(value) - if !value.respond_to?(:to_date) - nil - else + if value.respond_to?(:to_date) begin value.to_date rescue StandardError @@ -277,10 +275,8 @@ class BooleanTypeCaster < Base def process(value) if value == '' nil - elsif [false, 'false', 'FALSE', 0, '0', 'f', 'F', 'off', 'OFF'].include? value - false else - true + ![false, 'false', 'FALSE', 0, '0', 'f', 'F', 'off', 'OFF'].include? value end end end diff --git a/lib/dynamoid/undumping.rb b/lib/dynamoid/undumping.rb index 00f0ad77..76e7a114 100644 --- a/lib/dynamoid/undumping.rb +++ b/lib/dynamoid/undumping.rb @@ -115,7 +115,7 @@ def process(set) def process_typed_collection(set) if allowed_type? undumper = Undumping.find_undumper(element_options) - set.map { |el| undumper.process(el) }.to_set + set.to_set { |el| undumper.process(el) } else raise ArgumentError, "Set element type #{element_type} isn't supported" end diff --git a/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb b/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb index 2da796b8..cc7b7bfd 100644 --- a/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb +++ b/spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb @@ -284,27 +284,27 @@ def dynamo_request(table_name, conditions = {}, options = {}) end it 'performs query on a table with a range and selects items in a range' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:between, [0.0, 3.0]]] }).to_a).to eq [[[{ id: '1', range: BigDecimal(1) }, { id: '1', range: BigDecimal(3) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:between, [0.0, 3.0]]] }).to_a).to eq [[[{ id: '1', range: BigDecimal('1') }, { id: '1', range: BigDecimal('3') }], { last_evaluated_key: nil }]] end it 'performs query on a table with a range and selects items in a range with :select option' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:between, [0.0, 3.0]]] }, {}, { select: 'ALL_ATTRIBUTES' }).to_a).to eq [[[{ id: '1', range: BigDecimal(1) }, { id: '1', range: BigDecimal(3) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:between, [0.0, 3.0]]] }, {}, { select: 'ALL_ATTRIBUTES' }).to_a).to eq [[[{ id: '1', range: BigDecimal('1') }, { id: '1', range: BigDecimal('3') }], { last_evaluated_key: nil }]] end it 'performs query on a table with a range and selects items greater than' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:gt, 1.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal(3) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:gt, 1.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal('3') }], { last_evaluated_key: nil }]] end it 'performs query on a table with a range and selects items less than' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:lt, 2.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal(1) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:lt, 2.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal('1') }], { last_evaluated_key: nil }]] end it 'performs query on a table with a range and selects items gte' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:gte, 1.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal(1) }, { id: '1', range: BigDecimal(3) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:gte, 1.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal('1') }, { id: '1', range: BigDecimal('3') }], { last_evaluated_key: nil }]] end it 'performs query on a table with a range and selects items lte' do - expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:lte, 3.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal(1) }, { id: '1', range: BigDecimal(3) }], { last_evaluated_key: nil }]] + expect(Dynamoid.adapter.query(test_table3, { id: [[:eq, '1']], range: [[:lte, 3.0]] }).to_a).to eq [[[{ id: '1', range: BigDecimal('1') }, { id: '1', range: BigDecimal('3') }], { last_evaluated_key: nil }]] end it 'performs query on a table and returns items based on returns correct limit' do @@ -333,22 +333,22 @@ def dynamo_request(table_name, conditions = {}, options = {}) it 'performs query on a table with a range and selects items less than that is in the correct order, scan_index_forward true' do query = Dynamoid.adapter.query(test_table4, { id: [[:eq, '1']], range: [[:gt, 0]] }, {}, { scan_index_forward: true }).flat_map { |i| i }.to_a - expect(query[0]).to eq(id: '1', order: 1, range: BigDecimal(1)) - expect(query[1]).to eq(id: '1', order: 2, range: BigDecimal(2)) - expect(query[2]).to eq(id: '1', order: 3, range: BigDecimal(3)) - expect(query[3]).to eq(id: '1', order: 4, range: BigDecimal(4)) - expect(query[4]).to eq(id: '1', order: 5, range: BigDecimal(5)) - expect(query[5]).to eq(id: '1', order: 6, range: BigDecimal(6)) + expect(query[0]).to eq(id: '1', order: 1, range: BigDecimal('1')) + expect(query[1]).to eq(id: '1', order: 2, range: BigDecimal('2')) + expect(query[2]).to eq(id: '1', order: 3, range: BigDecimal('3')) + expect(query[3]).to eq(id: '1', order: 4, range: BigDecimal('4')) + expect(query[4]).to eq(id: '1', order: 5, range: BigDecimal('5')) + expect(query[5]).to eq(id: '1', order: 6, range: BigDecimal('6')) end it 'performs query on a table with a range and selects items less than that is in the correct order, scan_index_forward false' do query = Dynamoid.adapter.query(test_table4, { id: [[:eq, '1']], range: [[:gt, 0]] }, {}, { scan_index_forward: false }).flat_map { |i| i }.to_a - expect(query[5]).to eq(id: '1', order: 1, range: BigDecimal(1)) - expect(query[4]).to eq(id: '1', order: 2, range: BigDecimal(2)) - expect(query[3]).to eq(id: '1', order: 3, range: BigDecimal(3)) - expect(query[2]).to eq(id: '1', order: 4, range: BigDecimal(4)) - expect(query[1]).to eq(id: '1', order: 5, range: BigDecimal(5)) - expect(query[0]).to eq(id: '1', order: 6, range: BigDecimal(6)) + expect(query[5]).to eq(id: '1', order: 1, range: BigDecimal('1')) + expect(query[4]).to eq(id: '1', order: 2, range: BigDecimal('2')) + expect(query[3]).to eq(id: '1', order: 3, range: BigDecimal('3')) + expect(query[2]).to eq(id: '1', order: 4, range: BigDecimal('4')) + expect(query[1]).to eq(id: '1', order: 5, range: BigDecimal('5')) + expect(query[0]).to eq(id: '1', order: 6, range: BigDecimal('6')) end end @@ -490,8 +490,8 @@ def dynamo_request(table_name, conditions = {}, options = {}) expect(results).to match( { table_with_composite_key => contain_exactly( - { id: '1', age: 29.to_d, name: 'Josh' }, - { id: '2', age: 16.to_d, name: 'Justin' }, + { id: '1', age: BigDecimal('29'), name: 'Josh' }, + { id: '2', age: BigDecimal('16'), name: 'Justin' }, ) } ) @@ -584,7 +584,7 @@ def dynamo_request(table_name, conditions = {}, options = {}) Dynamoid.adapter.put_item(table, id: '1') results = Dynamoid.adapter.batch_get_item(table => '1') { |batch, _| batch } - expect(results).to eq nil + expect(results).to be_nil end it 'calles block for each loaded items batch' do @@ -1049,7 +1049,7 @@ def dynamo_request(table_name, conditions = {}, options = {}) ).to match( [ [ - match_array([{ name: 'Josh', id: '2' }, { name: 'Josh', id: '1' }]), + contain_exactly({ name: 'Josh', id: '2' }, { name: 'Josh', id: '1' }), { last_evaluated_key: nil } ] ] diff --git a/spec/dynamoid/adapter_spec.rb b/spec/dynamoid/adapter_spec.rb index 6261a7ee..12c5302c 100644 --- a/spec/dynamoid/adapter_spec.rb +++ b/spec/dynamoid/adapter_spec.rb @@ -110,14 +110,14 @@ def test_table it 'returns true if table created' do actual = Dynamoid.adapter.create_table(table_name, :id, sync: true) - expect(actual).to eq true + expect(actual).to be true end it 'returns false if table was created earlier' do Dynamoid.adapter.create_table(table_name, :id, sync: true) actual = Dynamoid.adapter.create_table(table_name, :id, sync: true) - expect(actual).to eq false + expect(actual).to be false end end @@ -132,7 +132,7 @@ def test_table Dynamoid.adapter.scan(test_table1).flat_map { |i| i }.to_a.size }.from(2).to(1) - expect(Dynamoid.adapter.get_item(test_table1, '1')).to eq nil + expect(Dynamoid.adapter.get_item(test_table1, '1')).to be_nil end it 'deletes through the adapter for many IDs' do @@ -146,8 +146,8 @@ def test_table Dynamoid.adapter.scan(test_table1).flat_map { |i| i }.to_a.size }.from(3).to(1) - expect(Dynamoid.adapter.get_item(test_table1, '1')).to eq nil - expect(Dynamoid.adapter.get_item(test_table1, '2')).to eq nil + expect(Dynamoid.adapter.get_item(test_table1, '1')).to be_nil + expect(Dynamoid.adapter.get_item(test_table1, '2')).to be_nil end it 'deletes through the adapter for one ID and a range key' do @@ -160,7 +160,7 @@ def test_table Dynamoid.adapter.scan(test_table3).flat_map { |i| i }.to_a.size }.from(2).to(1) - expect(Dynamoid.adapter.get_item(test_table3, '1', range_key: 1.0)).to eq nil + expect(Dynamoid.adapter.get_item(test_table3, '1', range_key: 1.0)).to be_nil end it 'deletes through the adapter for many IDs and a range key' do @@ -177,8 +177,8 @@ def test_table Dynamoid.adapter.scan(test_table3).flat_map { |i| i }.to_a.size }.from(4).to(2) - expect(Dynamoid.adapter.get_item(test_table3, '1', range_key: 1.0)).to eq nil - expect(Dynamoid.adapter.get_item(test_table3, '2', range_key: 1.0)).to eq nil + expect(Dynamoid.adapter.get_item(test_table3, '1', range_key: 1.0)).to be_nil + expect(Dynamoid.adapter.get_item(test_table3, '2', range_key: 1.0)).to be_nil end end end diff --git a/spec/dynamoid/associations/has_one_spec.rb b/spec/dynamoid/associations/has_one_spec.rb index 0acba68f..ff11771a 100644 --- a/spec/dynamoid/associations/has_one_spec.rb +++ b/spec/dynamoid/associations/has_one_spec.rb @@ -28,7 +28,7 @@ it 'returns only one object when associated' do magazine.sponsor.create - expect(magazine.sponsor).not_to be_a_kind_of Array + expect(magazine.sponsor).not_to be_a Array end it 'delegates equality to its source record' do diff --git a/spec/dynamoid/criteria/chain_spec.rb b/spec/dynamoid/criteria/chain_spec.rb index 73fd154d..448f39de 100644 --- a/spec/dynamoid/criteria/chain_spec.rb +++ b/spec/dynamoid/criteria/chain_spec.rb @@ -451,7 +451,7 @@ def request_params end # http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.ScanFilter.html - describe 'Scan conditions ' do + describe 'Scan conditions' do let(:model) do new_class do field :age, :integer @@ -932,7 +932,7 @@ def request_params obj2 = klass.create(count: 2) obj3 = klass.create(count: 3) - expect(klass.where('count.gt': '1').all).to match_array([obj2, obj3]) + expect(klass.where('count.gt': '1').all).to contain_exactly(obj2, obj3) end it 'type casts collection of condition values' do @@ -940,7 +940,7 @@ def request_params obj2 = klass.create(count: 2) obj3 = klass.create(count: 3) - expect(klass.where('count.in': %w[1 2]).all).to match_array([obj1, obj2]) + expect(klass.where('count.in': %w[1 2]).all).to contain_exactly(obj1, obj2) end end @@ -1169,7 +1169,7 @@ def request_params context 'store_attribute_with_nil_value = true', config: { store_attribute_with_nil_value: true } do it 'supports "eq nil" check' do - expect(model.where('name': nil).to_a).to eq [@johndoe] + expect(model.where(name: nil).to_a).to eq [@johndoe] end it 'supports "in [nil]" check' do @@ -1193,7 +1193,7 @@ def request_params end it 'does not support "eq nil" check' do - expect(model.where('name': nil).to_a).to eq [] + expect(model.where(name: nil).to_a).to eq [] end it 'does not supports "in [nil]" check' do @@ -1258,7 +1258,7 @@ def request_params expect do klass_with_callback.where(name: 'Alex').to_a - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end @@ -1287,8 +1287,8 @@ def request_params it 'yields one page at a time' do expect { |b| model.where(id: '1').find_by_pages(&b) }.to yield_successive_args( - [all(be_kind_of(model)), { last_evaluated_key: an_instance_of(Hash) }], - [all(be_kind_of(model)), { last_evaluated_key: nil }], + [all(be_a(model)), { last_evaluated_key: an_instance_of(Hash) }], + [all(be_a(model)), { last_evaluated_key: nil }], ) end @@ -1330,7 +1330,7 @@ def request_params expect do klass_with_callback.where(name: 'Alex').find_by_pages { |*| } - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end @@ -1748,7 +1748,7 @@ def request_params expect do klass_with_callback.first - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end @@ -2112,7 +2112,7 @@ def request_params field :age, :integer local_secondary_index range_key: :age, - name: :age_index, projected_attributes: :all + name: :age_index, projected_attributes: :all end end @@ -2143,7 +2143,7 @@ def request_params field :age, :integer global_secondary_index hash_key: :owner_id, range_key: :age, - name: :age_index, projected_attributes: :all + name: :age_index, projected_attributes: :all end end let(:chain) { described_class.new(klass_with_global_secondary_index) } diff --git a/spec/dynamoid/criteria_spec.rb b/spec/dynamoid/criteria_spec.rb index 23c90e59..f2e730af 100644 --- a/spec/dynamoid/criteria_spec.rb +++ b/spec/dynamoid/criteria_spec.rb @@ -42,14 +42,14 @@ it 'passes each to all members' do expect { |b| User.each(&b) }.to yield_successive_args( - be_kind_of(User).and(have_attributes('new_record' => false)), - be_kind_of(User).and(have_attributes('new_record' => false)) + be_a(User).and(have_attributes('new_record' => false)), + be_a(User).and(have_attributes('new_record' => false)) ) end it 'passes find_by_pages to all members' do expect { |b| User.find_by_pages(&b) }.to yield_successive_args( - [all(be_kind_of(User)), { last_evaluated_key: nil }] + [all(be_a(User)), { last_evaluated_key: nil }] ) end diff --git a/spec/dynamoid/document_spec.rb b/spec/dynamoid/document_spec.rb index 8d7a1fcd..5f585863 100644 --- a/spec/dynamoid/document_spec.rb +++ b/spec/dynamoid/document_spec.rb @@ -326,7 +326,7 @@ def city=(value) it 'sets default value at the creation' do travel 1.hour do obj = model.create - expect(obj.expired_at).to eq(Time.now.to_i + 30 * 60) + expect(obj.expired_at).to eq(Time.now.to_i + (30 * 60)) end end @@ -335,7 +335,7 @@ def city=(value) travel 1.hour do obj.update_attributes(expired_at: nil) - expect(obj.expired_at).to eq(Time.now.to_i + 30 * 60) + expect(obj.expired_at).to eq(Time.now.to_i + (30 * 60)) end end diff --git a/spec/dynamoid/dumping_spec.rb b/spec/dynamoid/dumping_spec.rb index a8a478c4..569677e4 100644 --- a/spec/dynamoid/dumping_spec.rb +++ b/spec/dynamoid/dumping_spec.rb @@ -1269,8 +1269,8 @@ def self.dynamoid_load(string) it 'stores integer value as Number' do obj = klass.create(count: 10) - expect(reload(obj).count).to eql(BigDecimal(10)) - expect(raw_attributes(obj)[:count]).to eql(BigDecimal(10)) + expect(reload(obj).count).to eql(BigDecimal('10')) + expect(raw_attributes(obj)[:count]).to eql(BigDecimal('10')) end it 'stores float value Number' do diff --git a/spec/dynamoid/finders_spec.rb b/spec/dynamoid/finders_spec.rb index 79f35ff7..31649047 100644 --- a/spec/dynamoid/finders_spec.rb +++ b/spec/dynamoid/finders_spec.rb @@ -222,7 +222,7 @@ expect( klass_with_date.find([[obj1.id, obj1.published_on], [obj2.id, obj2.published_on]]) - ).to match_array([obj1, obj2]) + ).to contain_exactly(obj1, obj2) end it 'raises MissingRangeKey when range key is not specified' do @@ -380,7 +380,7 @@ expect do klass_with_callback.find(object.id) - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end @@ -510,7 +510,7 @@ expect do klass_with_callback.find_all([object.id]) - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end diff --git a/spec/dynamoid/identity_map_spec.rb b/spec/dynamoid/identity_map_spec.rb index b5cfbad9..1bda7d91 100644 --- a/spec/dynamoid/identity_map_spec.rb +++ b/spec/dynamoid/identity_map_spec.rb @@ -30,7 +30,7 @@ it 'clears cache on delete' do tweet = Tweet.create(tweet_id: 'x', group: 'one') tweet.delete - expect(Tweet.find_by_id('x', range_key: 'one')).to be nil + expect(Tweet.find_by_id('x', range_key: 'one')).to be_nil end end diff --git a/spec/dynamoid/loadable_spec.rb b/spec/dynamoid/loadable_spec.rb index 6c9d8b71..48443c8e 100644 --- a/spec/dynamoid/loadable_spec.rb +++ b/spec/dynamoid/loadable_spec.rb @@ -98,7 +98,7 @@ expect do object.reload - end.to output('run after_initialize' + 'run after_find').to_stdout + end.to output('run after_initializerun after_find').to_stdout end end end diff --git a/spec/dynamoid/persistence_spec.rb b/spec/dynamoid/persistence_spec.rb index 26d57b25..e101c650 100644 --- a/spec/dynamoid/persistence_spec.rb +++ b/spec/dynamoid/persistence_spec.rb @@ -777,7 +777,7 @@ def around_create_callback expect do klass_with_callback.create(name: 'Alex') - end.to output('start around_create' + 'finish around_create').to_stdout + end.to output('start around_createfinish around_create').to_stdout end it 'runs before_save callback' do @@ -816,7 +816,7 @@ def around_save_callback expect do klass_with_callback.create(name: 'Alex') - end.to output('start around_save' + 'finish around_save').to_stdout + end.to output('start around_savefinish around_save').to_stdout end it 'runs before_validation callback' do @@ -1218,7 +1218,7 @@ def around_update_callback expect do klass_with_callback.update!(model.id, name: '[Updated]') - end.to output('start around_update' + 'finish around_update').to_stdout + end.to output('start around_updatefinish around_update').to_stdout end it 'runs before_save callback' do @@ -1271,7 +1271,7 @@ def around_save_callback expect do klass_with_callback.update!(model.id, name: '[Updated]') - end.to output('start around_save' + 'finish around_save').to_stdout + end.to output('start around_savefinish around_save').to_stdout }.to output.to_stdout end @@ -1609,7 +1609,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :created_at, :updated_at) expect { - document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.to change { document_class.find(obj.id).title }.to('New title') end @@ -1618,7 +1618,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :published_on, :created_at, :updated_at) expect { - result = document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + result = document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.not_to change { document_class.find(obj.id).title } end @@ -1629,7 +1629,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :created_at, :updated_at) expect { - result = document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + result = document_class.update_fields(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.not_to change { document_class.find(obj.id).title } end end @@ -1881,7 +1881,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :created_at, :updated_at) expect { - document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.to change { document_class.find(obj.id).title }.to('New title') end @@ -1890,7 +1890,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :published_on, :created_at, :updated_at) expect { - result = document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + result = document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.not_to change { document_class.find(obj.id).title } end @@ -1901,7 +1901,7 @@ def around_update_callback expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :created_at, :updated_at) expect { - result = document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: [:version, :published_on] }) + result = document_class.upsert(obj.id, { title: 'New title' }, { unless_exists: %i[version published_on] }) }.not_to change { document_class.find(obj.id).title } end end @@ -2552,7 +2552,7 @@ def around_create_callback end obj = klass_with_callback.new(name: 'Alex') - expect { obj.save }.to output('start around_create' + 'finish around_create').to_stdout + expect { obj.save }.to output('start around_createfinish around_create').to_stdout end it 'runs callbacks in the proper order' do @@ -2638,7 +2638,7 @@ def around_update_callback end obj = klass_with_callback.create(name: 'Alex') - expect { obj.save }.to output('start around_update' + 'finish around_update').to_stdout + expect { obj.save }.to output('start around_updatefinish around_update').to_stdout end it 'runs callbacks in the proper order' do @@ -2725,7 +2725,7 @@ def around_save_callback end obj = klass_with_callback.new(name: 'Alex') - expect { obj.save }.to output('start around_save' + 'finish around_save').to_stdout + expect { obj.save }.to output('start around_savefinish around_save').to_stdout end it 'runs before_validation callback' do @@ -3165,7 +3165,7 @@ def around_update_callback expect do obj.update_attribute(:name, 'Alexey') - end.to output('start around_update' + 'finish around_update').to_stdout + end.to output('start around_updatefinish around_update').to_stdout end it 'runs before_save callback' do @@ -3218,7 +3218,7 @@ def around_save_callback expect do obj.update_attribute(:name, 'Alexey') - end.to output('start around_save' + 'finish around_save').to_stdout + end.to output('start around_savefinish around_save').to_stdout }.to output.to_stdout end @@ -3450,7 +3450,7 @@ def around_update_callback end model = klass_with_callbacks.create(name: 'John') - expected_output = \ + expected_output = 'run before_save' \ 'run before_update' \ 'run after_update' \ @@ -3638,7 +3638,7 @@ def around_update_callback expect do obj.update_attributes!(name: 'Alexey') - end.to output('start around_update' + 'finish around_update').to_stdout + end.to output('start around_updatefinish around_update').to_stdout end it 'runs before_save callback' do @@ -3691,7 +3691,7 @@ def around_save_callback expect do obj.update_attributes!(name: 'Alexey') - end.to output('start around_save' + 'finish around_save').to_stdout + end.to output('start around_savefinish around_save').to_stdout }.to output.to_stdout end @@ -4309,7 +4309,7 @@ def before_save_callback; end expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :created_at, :updated_at) expect { - obj.update(unless_exists: [:version, :published_on]) { |t| t.set(title: 'New title') } + obj.update(unless_exists: %i[version published_on]) { |t| t.set(title: 'New title') } }.to change { document_class.find(obj.id).title }.to('New title') end @@ -4318,7 +4318,7 @@ def before_save_callback; end expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :published_on, :created_at, :updated_at) expect { - obj.update(unless_exists: [:version, :published_on]) { |t| t.set(title: 'New title') } + obj.update(unless_exists: %i[version published_on]) { |t| t.set(title: 'New title') } }.not_to change { document_class.find(obj.id).title } end @@ -4329,7 +4329,7 @@ def before_save_callback; end expect(raw_attributes(obj).keys).to contain_exactly(:id, :title, :version, :created_at, :updated_at) expect { - obj.update(unless_exists: [:version, :published_on]) { |t| t.set(title: 'New title') } + obj.update(unless_exists: %i[version published_on]) { |t| t.set(title: 'New title') } }.not_to change { document_class.find(obj.id).title } end end @@ -4501,7 +4501,7 @@ def around_update_callback model.update do |t| t.add(count: 3) end - end.to output('start around_update' + 'finish around_update').to_stdout + end.to output('start around_updatefinish around_update').to_stdout end it 'runs callbacks in the proper order' do @@ -4591,7 +4591,7 @@ def around_destroy_callback obj = klass_with_callback.create - expect { obj.destroy }.to output('start around_destroy' + 'finish around_destroy').to_stdout + expect { obj.destroy }.to output('start around_destroyfinish around_destroy').to_stdout end end end diff --git a/spec/dynamoid/sti_spec.rb b/spec/dynamoid/sti_spec.rb index 8ac7b275..3220209a 100644 --- a/spec/dynamoid/sti_spec.rb +++ b/spec/dynamoid/sti_spec.rb @@ -23,7 +23,7 @@ end end - it 'enables only own attributes in a base class ' do + it 'enables only own attributes in a base class' do expect(class_a.attributes.keys).to match_array(%i[id type a created_at updated_at]) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 66213d66..c0929312 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,14 +14,14 @@ DEBUG = ENV['DEBUG'] == 'true' ruby_version = Gem::Version.new(RUBY_VERSION) -minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == engine } +minimum_version = ->(version, engine = 'ruby') { ruby_version >= Gem::Version.new(version) && engine == RUBY_ENGINE } actual_version = lambda do |major, minor| actual = Gem::Version.new(ruby_version) major == actual.segments[0] && minor == actual.segments[1] && RUBY_ENGINE == 'ruby' end debugging = minimum_version.call('2.7') && DEBUG RUN_COVERAGE = minimum_version.call('2.6') && (ENV['COVER_ALL'] || ENV['CI_CODECOV'] || ENV['CI'].nil?) -ALL_FORMATTERS = actual_version.call(2, 7) && (ENV['COVER_ALL'] || ENV['CI_CODECOV'] || ENV['CI']) +ALL_FORMATTERS = actual_version.call(2, 7) && (ENV['COVER_ALL'] || ENV['CI_CODECOV'] || ENV['CI']) # rubocop:disable Style/FetchEnvVar if DEBUG if debugging @@ -64,7 +64,7 @@ Aws.config.update( region: 'us-west-2', - credentials: Aws::Credentials.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY']) + credentials: Aws::Credentials.new(ENV.fetch('ACCESS_KEY'), ENV.fetch('SECRET_KEY')) ) Dynamoid.configure do |config| diff --git a/spec/support/config.rb b/spec/support/config.rb index 6a801c98..0b0d2b92 100644 --- a/spec/support/config.rb +++ b/spec/support/config.rb @@ -7,13 +7,13 @@ config.each do |key, value| config_old[key] = Dynamoid::Config.send(key) - Dynamoid::Config.send("#{key}=", value) + Dynamoid::Config.send(:"#{key}=", value) end example.run - config.each do |key, _| - Dynamoid::Config.send("#{key}=", config_old[key]) + config.each_key do |key| + Dynamoid::Config.send(:"#{key}=", config_old[key]) end end end diff --git a/spec/support/helpers/new_class_helper.rb b/spec/support/helpers/new_class_helper.rb index 1fc463f9..a099f9b7 100644 --- a/spec/support/helpers/new_class_helper.rb +++ b/spec/support/helpers/new_class_helper.rb @@ -3,7 +3,7 @@ # Declaration DSL of partition key and sort key is weird. # So let's use helpers to simplify class declaration in specs. module NewClassHelper - def new_class(options = {}, &blk) + def new_class(options = {}, &block) table_name = options[:table_name] || :"documents_#{Time.now.to_i}_#{rand(1000)}" class_name = (options[:class_name] || table_name).to_s.classify partition_key = options[:partition_key] @@ -34,7 +34,7 @@ def self.name @class_name end end - klass.class_exec(options, &blk) if block_given? + klass.class_exec(options, &block) if block klass end end From 3422a9ec0b2044962459b1626ac7d0c4e40d2945 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 18:34:08 +0200 Subject: [PATCH 10/13] Manually correct Rubocop warnings --- lib/dynamoid/adapter_plugin/aws_sdk_v3.rb | 4 ++-- lib/dynamoid/associations/belongs_to.rb | 12 ++++++------ lib/dynamoid/config/options.rb | 24 +++++++++++------------ lib/dynamoid/document.rb | 2 +- lib/dynamoid/type_casting.rb | 7 ++++--- spec/dynamoid/dirty_spec.rb | 5 ----- spec/dynamoid/fields_spec.rb | 4 +++- spec/dynamoid/log/formatter/debug_spec.rb | 2 +- 8 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb index 72c3219c..8bb51ad5 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb @@ -584,7 +584,7 @@ def truncate(table_name) end def count(table_name) - describe_table(table_name, true).item_count + describe_table(table_name, reload: true).item_count end # Run PartiQL query. @@ -642,7 +642,7 @@ def expected_stanza(conditions = nil) # # New, semi-arbitrary API to get data on the table # - def describe_table(table_name, reload = false) + def describe_table(table_name, reload: false) (!reload && table_cache[table_name]) || begin table_cache[table_name] = Table.new(client.describe_table(table_name: table_name).data) end diff --git a/lib/dynamoid/associations/belongs_to.rb b/lib/dynamoid/associations/belongs_to.rb index b7c6c76a..52c45556 100644 --- a/lib/dynamoid/associations/belongs_to.rb +++ b/lib/dynamoid/associations/belongs_to.rb @@ -39,14 +39,14 @@ def associate(hash_key) # # @since 0.2.0 def target_association - has_many_key_name = options[:inverse_of] || source.class.to_s.underscore.pluralize.to_sym - has_one_key_name = options[:inverse_of] || source.class.to_s.underscore.to_sym - unless target_class.associations[has_many_key_name].nil? - return has_many_key_name if target_class.associations[has_many_key_name][:type] == :has_many + name = options[:inverse_of] || source.class.to_s.underscore.pluralize.to_sym + if target_class.associations.dig(name, :type) == :has_many + return name end - unless target_class.associations[has_one_key_name].nil? - return has_one_key_name if target_class.associations[has_one_key_name][:type] == :has_one + name = options[:inverse_of] || source.class.to_s.underscore.to_sym + if target_class.associations.dig(name, :type) == :has_one + return name # rubocop:disable Style/RedundantReturn end end end diff --git a/lib/dynamoid/config/options.rb b/lib/dynamoid/config/options.rb index c3b21751..3b982555 100644 --- a/lib/dynamoid/config/options.rb +++ b/lib/dynamoid/config/options.rb @@ -33,21 +33,21 @@ def option(name, options = {}) defaults[name] = settings[name] = options[:default] class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def #{name} - settings[#{name.inspect}] - end + def #{name} # def endpoint + settings[#{name.inspect}] # settings["endpoint"] + end # end - def #{name}=(value) - settings[#{name.inspect}] = value - end + def #{name}=(value) # def endpoint=(value) + settings[#{name.inspect}] = value # settings["endpoint"] = value + end # end - def #{name}? - #{name} - end + def #{name}? # def endpoint? + #{name} # endpoint + end # end - def reset_#{name} - settings[#{name.inspect}] = defaults[#{name.inspect}] - end + def reset_#{name} # def reset_endpoint + settings[#{name.inspect}] = defaults[#{name.inspect}] # settings["endpoint"] = defaults["endpoint"] + end # end RUBY end diff --git a/lib/dynamoid/document.rb b/lib/dynamoid/document.rb index 4715e6b2..8591e7d0 100644 --- a/lib/dynamoid/document.rb +++ b/lib/dynamoid/document.rb @@ -260,7 +260,7 @@ def eql?(other) # # @return [Integer] def hash - hash_key.hash ^ range_value.hash + [hash_key, range_value].hash end # Return a model's hash key value. diff --git a/lib/dynamoid/type_casting.rb b/lib/dynamoid/type_casting.rb index ec3723eb..dd11c74b 100644 --- a/lib/dynamoid/type_casting.rb +++ b/lib/dynamoid/type_casting.rb @@ -57,11 +57,12 @@ def process(value) class StringTypeCaster < Base def process(value) - if value == true + case value + when true 't' - elsif value == false + when false 'f' - elsif value.is_a? String + when String value.dup else value.to_s diff --git a/spec/dynamoid/dirty_spec.rb b/spec/dynamoid/dirty_spec.rb index 5bf74c30..1c6b5cbe 100644 --- a/spec/dynamoid/dirty_spec.rb +++ b/spec/dynamoid/dirty_spec.rb @@ -10,11 +10,6 @@ end describe '#changed?' do - it 'works' do - obj = model.new(name: 'Bob') - expect(obj.name_changed?).to eq true - end - it 'returns true if any of the attributes have unsaved changes' do obj = model.new(name: 'Bob') expect(obj.changed?).to eq true diff --git a/spec/dynamoid/fields_spec.rb b/spec/dynamoid/fields_spec.rb index ea99298f..29c4d01f 100644 --- a/spec/dynamoid/fields_spec.rb +++ b/spec/dynamoid/fields_spec.rb @@ -186,14 +186,16 @@ def self.load(val) it 'writes an attribute correctly' do address.write_attribute(:city, 'Chicago') + expect(address.read_attribute(:city)).to eq 'Chicago' end it 'writes an attribute with an alias' do address[:city] = 'Chicago' + expect(address.read_attribute(:city)).to eq 'Chicago' end it 'reads a written attribute' do - address.write_attribute(:city, 'Chicago') + address.city = 'Chicago' expect(address.read_attribute(:city)).to eq 'Chicago' end diff --git a/spec/dynamoid/log/formatter/debug_spec.rb b/spec/dynamoid/log/formatter/debug_spec.rb index af8b3fd7..75971368 100644 --- a/spec/dynamoid/log/formatter/debug_spec.rb +++ b/spec/dynamoid/log/formatter/debug_spec.rb @@ -5,7 +5,7 @@ describe Dynamoid::Log::Formatter::Debug do describe '#format' do - let(:subject) { described_class.new } + subject { described_class.new } let(:logger) { Logger.new(buffer) } let(:buffer) { StringIO.new } From 5aa2d374713309599503303a05eebd1ca43f35b9 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 18:34:37 +0200 Subject: [PATCH 11/13] Disable some Rubocop rules --- .rubocop.yml | 9 ++++++++ .rubocop_gemspec.yml | 9 ++++++++ .rubocop_performance.yml | 3 +++ .rubocop_rspec.yml | 14 +++++++++++- lib/dynamoid/adapter_plugin/aws_sdk_v3.rb | 2 ++ .../adapter_plugin/aws_sdk_v3/item_updater.rb | 2 ++ lib/dynamoid/type_casting.rb | 4 ++++ spec/dynamoid/criteria/chain_spec.rb | 9 +++++--- spec/dynamoid/document_spec.rb | 2 +- spec/dynamoid/fields_spec.rb | 2 +- spec/dynamoid/indexes_spec.rb | 2 ++ spec/dynamoid/persistence_spec.rb | 22 +++++++++---------- spec/dynamoid/sti_spec.rb | 8 +++++++ spec/dynamoid/type_casting_spec.rb | 6 ++--- 14 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 .rubocop_gemspec.yml diff --git a/.rubocop.yml b/.rubocop.yml index 3dec5c25..5f3b3092 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ # We chose not to make these changes inherit_from: + - .rubocop_gemspec.yml - .rubocop_performance.yml - .rubocop_rspec.yml - .rubocop_thread_safety.yml @@ -17,6 +18,7 @@ require: AllCops: DisplayCopNames: true # Display the name of the failing cops TargetRubyVersion: 2.3 + NewCops: enable # It's a matter of taste Layout/ParameterAlignment: @@ -100,3 +102,10 @@ Naming/PredicateName: Security/YAMLLoad: Enabled: false +Lint/EmptyClass: + Exclude: + - README.md +Lint/EmptyBlock: + Exclude: + - README.md + diff --git a/.rubocop_gemspec.yml b/.rubocop_gemspec.yml new file mode 100644 index 00000000..bcdcb697 --- /dev/null +++ b/.rubocop_gemspec.yml @@ -0,0 +1,9 @@ +# specifying Ruby version would be a breaking change +# we may consider adding `required_ruby_version` in the next major release +Gemspec/RequiredRubyVersion: + Enabled: false + +# development dependencies specified in the gemspec file are shared +# by the main Gemfile and gemfiles in the gemfiles/ directory that are used on CI +Gemspec/DevelopmentDependencies: + Enabled: false diff --git a/.rubocop_performance.yml b/.rubocop_performance.yml index b65f167e..5ef13e72 100644 --- a/.rubocop_performance.yml +++ b/.rubocop_performance.yml @@ -1,3 +1,6 @@ # See: https://github.com/rubocop/rubocop-performance/issues/322 Performance/RegexpMatch: Enabled: false + +Performance/MethodObjectAsBlock: + Enabled: false diff --git a/.rubocop_rspec.yml b/.rubocop_rspec.yml index 079933da..7c1f669c 100644 --- a/.rubocop_rspec.yml +++ b/.rubocop_rspec.yml @@ -4,6 +4,9 @@ RSpec/FilePath: RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false + RSpec/NamedSubject: Enabled: false @@ -21,7 +24,7 @@ RSpec/InstanceVariable: RSpec/NestedGroups: Enabled: false - + RSpec/ExpectInHook: Enabled: false @@ -30,3 +33,12 @@ RSpec/ExpectInHook: # got # => 101.0 (0.101e3) RSpec/BeEql: Enabled: false + +RSpec/BeEq: + Enabled: false + +RSpec/StubbedMock: + Enabled: false + +RSpec/IndexedLet: + Enabled: false diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb index 8bb51ad5..65b08454 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb @@ -46,6 +46,7 @@ class AwsSdkV3 CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout].freeze # See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html + # rubocop:disable Metrics/CollectionLiteralLength RESERVED_WORDS = Set.new( %i[ ABORT ABSOLUTE ACTION ADD AFTER AGENT AGGREGATE ALL ALLOCATE ALTER ANALYZE @@ -107,6 +108,7 @@ class AwsSdkV3 WHILE WINDOW WITH WITHIN WITHOUT WORK WRAPPED WRITE YEAR ZONE ] ).freeze + # rubocop:enable Metrics/CollectionLiteralLength attr_reader :table_cache diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb index d30a5247..b9b6a248 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb @@ -102,6 +102,7 @@ def attribute_updates # The only difference is that to update item we need to track whether # attribute value is nil or not. def sanitize_attributes(attributes) + # rubocop:disable Lint/DuplicateBranch attributes.transform_values do |v| if v.is_a?(Hash) v.stringify_keys @@ -113,6 +114,7 @@ def sanitize_attributes(attributes) v end end + # rubocop:enable Lint/DuplicateBranch end end end diff --git a/lib/dynamoid/type_casting.rb b/lib/dynamoid/type_casting.rb index dd11c74b..7217e274 100644 --- a/lib/dynamoid/type_casting.rb +++ b/lib/dynamoid/type_casting.rb @@ -72,6 +72,7 @@ def process(value) class IntegerTypeCaster < Base def process(value) + # rubocop:disable Lint/DuplicateBranch if value == true 1 elsif value == false @@ -85,11 +86,13 @@ def process(value) else value.to_i end + # rubocop:enable Lint/DuplicateBranch end end class NumberTypeCaster < Base def process(value) + # rubocop:disable Lint/DuplicateBranch if value == true 1 elsif value == false @@ -105,6 +108,7 @@ def process(value) else value.to_d end + # rubocop:enable Lint/DuplicateBranch end end diff --git a/spec/dynamoid/criteria/chain_spec.rb b/spec/dynamoid/criteria/chain_spec.rb index 448f39de..d611ea9f 100644 --- a/spec/dynamoid/criteria/chain_spec.rb +++ b/spec/dynamoid/criteria/chain_spec.rb @@ -1210,6 +1210,7 @@ def request_params # https://github.com/Dynamoid/dynamoid/issues/435 context 'when inheritance field (:type by default) is a GSI hash key' do it 'works without exception' do + # rubocop:disable Lint/ConstantDefinitionInBlock UserWithGSI = new_class class_name: 'UserWithGSI' do field :type @@ -1217,6 +1218,8 @@ def request_params range_key: :created_at, projected_attributes: :all end + # rubocop:enable Lint/ConstantDefinitionInBlock + obj = UserWithGSI.create actual = UserWithGSI.where(type: 'UserWithGSI').all.to_a @@ -1302,7 +1305,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_initialize').to_stdout end @@ -1315,7 +1318,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_find').to_stdout end @@ -1329,7 +1332,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_initializerun after_find').to_stdout end end diff --git a/spec/dynamoid/document_spec.rb b/spec/dynamoid/document_spec.rb index 5f585863..9cf992df 100644 --- a/spec/dynamoid/document_spec.rb +++ b/spec/dynamoid/document_spec.rb @@ -240,7 +240,7 @@ def city=(value) shared_examples 'it has equality testing and hashing' do it 'is equal to itself' do - expect(document).to eq document + expect(document).to eq document # rubocop:disable RSpec/IdenticalEqualityAssertion end it 'is equal to another document with the same key(s)' do diff --git a/spec/dynamoid/fields_spec.rb b/spec/dynamoid/fields_spec.rb index 29c4d01f..7ad302b8 100644 --- a/spec/dynamoid/fields_spec.rb +++ b/spec/dynamoid/fields_spec.rb @@ -129,7 +129,7 @@ def foobar_before_type_cast?; end expect(address.city).to eq 'Chicago' end - it 'declares a query attribute' do + it 'declares a query attribute' do # rubocop:disable Lint/EmptyBlock, RSpec/NoExpectationExample end it 'automatically declares id' do diff --git a/spec/dynamoid/indexes_spec.rb b/spec/dynamoid/indexes_spec.rb index d3081839..25849cfd 100644 --- a/spec/dynamoid/indexes_spec.rb +++ b/spec/dynamoid/indexes_spec.rb @@ -378,6 +378,7 @@ context 'with custom type key params' do let(:doc_class) do new_class do + # rubocop:disable Lint/ConstantDefinitionInBlock class CustomType def dynamoid_dump name @@ -387,6 +388,7 @@ def self.dynamoid_load(string) new(string.to_s) end end + # rubocop:enable Lint/ConstantDefinitionInBlock field :custom_type_field, CustomType field :custom_type_range_field, CustomType diff --git a/spec/dynamoid/persistence_spec.rb b/spec/dynamoid/persistence_spec.rb index e101c650..f1e4d6ea 100644 --- a/spec/dynamoid/persistence_spec.rb +++ b/spec/dynamoid/persistence_spec.rb @@ -868,7 +868,7 @@ def around_save_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -1336,7 +1336,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2583,7 +2583,7 @@ def around_save_callback obj = klass_with_callbacks.new(name: 'Alex') # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2670,7 +2670,7 @@ def around_save_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2887,7 +2887,7 @@ def around_save_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect { obj.save }.not_to change { obj.updated_at } end @@ -3100,7 +3100,7 @@ def around_save_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attribute(:title, 'Old title') @@ -3282,7 +3282,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_save', 'start around_save', 'run before_update', @@ -3395,7 +3395,7 @@ def around_update_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attributes(title: 'Old title') @@ -3586,7 +3586,7 @@ def around_update_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attributes!(title: 'Old title') @@ -3758,7 +3758,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -4535,7 +4535,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_update', 'start around_update', 'finish around_update', diff --git a/spec/dynamoid/sti_spec.rb b/spec/dynamoid/sti_spec.rb index 3220209a..77467502 100644 --- a/spec/dynamoid/sti_spec.rb +++ b/spec/dynamoid/sti_spec.rb @@ -47,6 +47,7 @@ describe 'persistence' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type end @@ -65,6 +66,7 @@ def self.name 'D' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -125,6 +127,7 @@ def self.name describe '`inheritance_field` document option' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do table inheritance_field: :type_new @@ -137,6 +140,7 @@ def self.name 'B' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -163,6 +167,7 @@ def self.name describe '`sti_name` support' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type @@ -178,6 +183,7 @@ def self.sti_name 'beta' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -194,9 +200,11 @@ def self.sti_name describe 'sti_class_for' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do diff --git a/spec/dynamoid/type_casting_spec.rb b/spec/dynamoid/type_casting_spec.rb index b64e3f79..38b91a82 100644 --- a/spec/dynamoid/type_casting_spec.rb +++ b/spec/dynamoid/type_casting_spec.rb @@ -445,7 +445,7 @@ end end - describe 'Raw field' do + describe 'Raw field' do # rubocop:disable Lint/EmptyBlock end describe 'Map field' do @@ -680,10 +680,10 @@ def settings.to_hash end end - describe 'Serialized field' do + describe 'Serialized field' do # rubocop:disable Lint/EmptyBlock end - describe 'Custom type field' do + describe 'Custom type field' do # rubocop:disable Lint/EmptyBlock end context 'there is no such field' do From 8f050c37a01261bdb6255cbc01b5e7b4d5df83af Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 1 Jan 2024 00:46:42 +0200 Subject: [PATCH 12/13] Fix loading aws-sdk-dynamodb gem in specs on CI on Ruby >= 3.0 Error: ``` RuntimeError: Unable to find a compatible xml library. Ensure that you have installed or added to your Gemfile one of ox, oga, libxml, nokogiri or rexml # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml/parser.rb:74:in `set_default_engine' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml/parser.rb:96:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml/parser.rb:7:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml/parser.rb:5:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml/parser.rb:3:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml.rb:8:in `require_relative' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core/xml.rb:8:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core.rb:77:in `require_relative' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-core-3.190.1/lib/aws-sdk-core.rb:77:in `' # ./vendor/bundle/ruby/3.2.0/gems/aws-sdk-dynamodb-1.98.0/lib/aws-sdk-dynamodb.rb:11:in `' # ./lib/dynamoid.rb:3:in `' ``` --- dynamoid.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/dynamoid.gemspec b/dynamoid.gemspec index c590f521..198a8dfb 100644 --- a/dynamoid.gemspec +++ b/dynamoid.gemspec @@ -59,6 +59,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler' spec.add_development_dependency 'pry', '~> 0.14' spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rexml' spec.add_development_dependency 'rspec', '~> 3.12' spec.add_development_dependency 'yard' end From 13cce10beee3350dd2ce37525d4b8df904c3af02 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 1 Jan 2024 01:12:48 +0200 Subject: [PATCH 13/13] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fbf1f71..bbc81c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Added +* [#697](https://github.com/Dynamoid/dynamoid/pull/697) Ensure Ruby 3.3 and Rails 7.1 versions are supported and added them on CI. ### Changed