update to version 5.3.0

This commit is contained in:
wang--ge 2023-11-16 16:17:56 +08:00
parent 301df621c6
commit dddcc8b513
13 changed files with 5 additions and 425 deletions

View File

@ -1,64 +0,0 @@
From c52f0483ab803fb7db6af20bf6bc80890af8d504 Mon Sep 17 00:00:00 2001
From: Josh Nichols <josh.nichols@gusto.com>
Date: Sat, 29 Jan 2022 11:01:02 -0500
Subject: [PATCH] Address differences in has_secure_password in Rails 7+
---
.../validate_presence_of_matcher_spec.rb | 40 +++++++++++++------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
index 818a57320..5c7841e67 100644
--- a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
@@ -860,22 +860,38 @@ def record_belonging_to(
end
context 'against a pre-set password in a model that has_secure_password' do
- it 'raises a CouldNotSetPasswordError' do
- user_class = define_model :user, password_digest: :string do
- has_secure_password validations: false
- validates_presence_of :password
- end
+ if Shoulda::Matchers::RailsShim.active_model_lt_7?
+ it 'raises a CouldNotSetPasswordError' do
+ user_class = define_model :user, password_digest: :string do
+ has_secure_password :password, validations: false
+ validates_presence_of :password
+ end
- user = user_class.new
- user.password = 'something'
+ user = user_class.new
+ user.password = 'something'
- assertion = lambda do
- expect(user).to validate_presence_of(:password)
+ assertion = lambda do
+ expect(user).to validate_presence_of(:password)
+ end
+
+ expect(&assertion).to raise_error(
+ Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError,
+ )
end
+ else
+ it 'does not raises a CouldNotSetPasswordError' do
+ user_class = define_model :user, password_digest: :string do
+ has_secure_password :password, validations: false
+ validates_presence_of :password
+ end
- expect(&assertion).to raise_error(
- Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError,
- )
+ user = user_class.new
+ user.password = 'something'
+
+ assertion = lambda do
+ expect(user).to validate_presence_of(:password)
+ end
+ end
end
end

View File

@ -1,53 +0,0 @@
From c52f0483ab803fb7db6af20bf6bc80890af8d504 Mon Sep 17 00:00:00 2001
From: Josh Nichols <josh.nichols@gusto.com>
Date: Sat, 29 Jan 2022 11:01:02 -0500
Subject: [PATCH] Address differences in has_secure_password in Rails 7+
---
.../validate_presence_of_matcher.rb | 4 +-
lib/shoulda/matchers/rails_shim.rb | 10 +++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
index c23302091..0c93bc3af 100644
--- a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
+++ b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
@@ -144,7 +144,7 @@ def matches?(subject)
possibly_ignore_interference_by_writer
- if secure_password_being_validated?
+ if secure_password_being_validated? && Shoulda::Matchers::RailsShim.active_model_lt_7?
ignore_interference_by_writer.default_to(when: :blank?)
disallowed_values.all? do |value|
@@ -208,7 +208,7 @@ def secure_password_being_validated?
end
def possibly_ignore_interference_by_writer
- if secure_password_being_validated?
+ if secure_password_being_validated? && RailsShim.active_model_lt_7?
ignore_interference_by_writer.default_to(when: :blank?)
end
end
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
index 2474d7363..c328d9e90 100644
--- a/lib/shoulda/matchers/rails_shim.rb
+++ b/lib/shoulda/matchers/rails_shim.rb
@@ -19,6 +19,16 @@ def active_record_version
Gem::Version.new('0')
end
+ def active_model_version
+ Gem::Version.new(::ActiveModel::VERSION::STRING)
+ rescue NameError
+ Gem::Version.new('0')
+ end
+
+ def active_model_lt_7?
+ Gem::Requirement.new('< 7').satisfied_by?(active_model_version)
+ end
+
def generate_validation_message(
record,
attribute,

View File

@ -1,28 +0,0 @@
From 7656cdf9abb4a0f7c4fd4cb9c971e474bfc0f9ee Mon Sep 17 00:00:00 2001
From: Josh Nichols <josh.nichols@gusto.com>
Date: Tue, 25 Jan 2022 13:35:35 -0500
Subject: [PATCH] Always use sqlite ~> 1.4
Rails 5.2 changed at some point to not specify a version. < 1.4 of
sqlite fails to build on Apple M1s.
---
spec/support/acceptance/helpers/step_helpers.rb | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
index fa972ecf4..530133fc5 100644
--- a/spec/support/acceptance/helpers/step_helpers.rb
+++ b/spec/support/acceptance/helpers/step_helpers.rb
@@ -23,11 +23,7 @@ def create_active_record_project
add_gem 'activerecord', active_record_version
add_gem 'rake'
- if rails_version =~ '~> 6.0'
- add_gem 'sqlite3', '~>1.4'
- else
- add_gem 'sqlite3', '~>1.3.6'
- end
+ add_gem 'sqlite3', '~>1.4'
end
def create_generic_bundler_project

View File

@ -1,24 +0,0 @@
From 0212a6e2f15214c34ea6015ea9a2718fcc24ee66 Mon Sep 17 00:00:00 2001
From: Josh Nichols <josh.nichols@gusto.com>
Date: Tue, 25 Jan 2022 11:16:07 -0500
Subject: [PATCH] Only mark classes as unloadable when Rails supports it
Rails 7.0 drops "classic" mode in favor of zeitwerk. The unloadable
method is no longer available.
---
spec/support/unit/helpers/class_builder.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb
index c7e294b86..f73fe2e3a 100644
--- a/spec/support/unit/helpers/class_builder.rb
+++ b/spec/support/unit/helpers/class_builder.rb
@@ -55,7 +55,7 @@ class #{namespace}::#{name_without_namespace} < ::#{parent_class}
RUBY
namespace.const_get(name_without_namespace).tap do |constant|
- constant.unloadable
+ constant.unloadable if constant.respond_to?(:unloadable) # if Rails is in classic mode, mark it unloadable
@_defined_modules = defined_modules | [constant]
if block

View File

@ -1,138 +0,0 @@
From 8e1303957ba2c0828c2eb2b91b9edea723d1553d Mon Sep 17 00:00:00 2001
From: Neil <me@neil.pro>
Date: Sat, 15 Jan 2022 19:37:42 -0300
Subject: [PATCH 1/3] Skip bootsnap on the test project creation
Use the Rails --skip-bootsnap option instead of commenting it on
boot.rb
---
spec/support/acceptance/helpers/step_helpers.rb | 4 ++--
spec/support/unit/rails_application.rb | 11 -----------
2 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
index fa972ecf4..878b27d3e 100644
--- a/spec/support/acceptance/helpers/step_helpers.rb
+++ b/spec/support/acceptance/helpers/step_helpers.rb
@@ -93,9 +93,9 @@ def create_rails_application
def rails_new_command
if rails_version =~ '~> 6.0'
- "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc"
+ "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
- "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc"
+ "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"
end
end
diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb
index b55b12cee..4480fd21a 100644
--- a/spec/support/unit/rails_application.rb
+++ b/spec/support/unit/rails_application.rb
@@ -77,7 +77,6 @@ def temp_view_path_for(path)
def generate
rails_new
fix_available_locales_warning
- remove_bootsnap
write_database_configuration
write_activerecord_model_with_default_connection
write_activerecord_model_with_different_connection
@@ -124,16 +123,6 @@ def fix_available_locales_warning
end
end
- def remove_bootsnap
- # Rails 5.2 introduced bootsnap, which is helpful when you're developing
- # or deploying an app, but we don't really need it (and it messes with
- # Zeus anyhow)
- fs.comment_lines_matching(
- 'config/boot.rb',
- %r{\Arequire 'bootsnap/setup'},
- )
- end
-
def write_database_configuration
YAML.dump(database.config.load_file, fs.open('config/database.yml', 'w'))
end
From df9c312134a939ab1c220b071d95fe3e32fe2601 Mon Sep 17 00:00:00 2001
From: Neil <me@neil.pro>
Date: Wed, 19 Jan 2022 07:32:15 -0300
Subject: [PATCH 2/3] Use the same `rails new` command on acceptance and unit
tests
---
spec/support/unit/rails_application.rb | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb
index 4480fd21a..511b99960 100644
--- a/spec/support/unit/rails_application.rb
+++ b/spec/support/unit/rails_application.rb
@@ -90,24 +90,9 @@ def rails_new
def rails_new_command
if rails_version > 5
- [
- 'rails',
- 'new',
- fs.project_directory.to_s,
- "--database=#{database.adapter_name}",
- '--skip-bundle',
- '--no-rc',
- '--skip-webpack-install',
- ]
+ "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
- [
- 'rails',
- 'new',
- fs.project_directory.to_s,
- "--database=#{database.adapter_name}",
- '--skip-bundle',
- '--no-rc',
- ]
+ "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"
end
end
From 2f9c975c77e8adf1ebb2f0fe921756a9527e504c Mon Sep 17 00:00:00 2001
From: Neil <me@neil.pro>
Date: Wed, 19 Jan 2022 07:32:57 -0300
Subject: [PATCH 3/3] Fix the Rails version comparison
The `=~ '~> 6.0'` comparison is evaluated to `false` on newer
versions of Rails, thus not skipping the JavaScript dependencies.
---
spec/support/acceptance/helpers/step_helpers.rb | 2 +-
spec/support/unit/rails_application.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
index 878b27d3e..818b08842 100644
--- a/spec/support/acceptance/helpers/step_helpers.rb
+++ b/spec/support/acceptance/helpers/step_helpers.rb
@@ -92,7 +92,7 @@ def create_rails_application
end
def rails_new_command
- if rails_version =~ '~> 6.0'
+ if rails_version >= 6.0
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"
diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb
index 511b99960..5f097099d 100644
--- a/spec/support/unit/rails_application.rb
+++ b/spec/support/unit/rails_application.rb
@@ -89,7 +89,7 @@ def rails_new
end
def rails_new_command
- if rails_version > 5
+ if rails_version >= 6.0
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"

View File

@ -1,42 +0,0 @@
From a1431b9859e8b8bc6810cf98687ab4c382d0adcf Mon Sep 17 00:00:00 2001
From: Josh Nichols <joshua.nichols@gmail.com>
Date: Mon, 31 Jan 2022 20:56:53 +0000
Subject: [PATCH] Use a hard-coded DateTime instead of DateTime.now. This
avoids some differences in Rails 7.0, where it can return nanoseconds,
leading things to be not quiete equal
---
.../active_model/validate_inclusion_of_matcher_spec.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb
index 80599530c..dd9b7933c 100644
--- a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb
@@ -145,7 +145,7 @@ def validation_matcher_scenario_args
end
context 'against a datetime attribute' do
- now = DateTime.now
+ now = DateTime.new(2022, 01, 01)
define_method(:now) { now }
@@ -448,6 +448,7 @@ def configure_validation_matcher(matcher)
end
it 'matches given the same array of valid values' do
+ new_now = DateTime.now
builder = build_object_allowing(possible_values)
expect_to_match_on_values(builder, possible_values)
end
@@ -785,8 +786,7 @@ def configure_validation_matcher(matcher)
include_context 'for a generic attribute'
context 'against a timestamp column' do
- now = DateTime.now
-
+ now = DateTime.new(2022, 01, 01)
define_method(:now) { now }
it_behaves_like 'it supports in_array',

View File

@ -1,22 +0,0 @@
From e0ebc2b16afc09804112a84213fdc83305427d3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
Date: Tue, 23 Aug 2022 11:34:29 +0200
Subject: [PATCH] Using local gems should be enough for testing
---
spec/support/acceptance/helpers/step_helpers.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
index 529f97fc3..73a5b3250 100644
--- a/spec/support/acceptance/helpers/step_helpers.rb
+++ b/spec/support/acceptance/helpers/step_helpers.rb
@@ -116,7 +116,7 @@ def add_rspec_to_project
def add_rspec_rails_to_project!
add_gem 'rspec-rails', rspec_rails_version
- run_command_within_bundle!('bundle install --binstubs') if rails_gt_6_0?
+ run_command_within_bundle!('bundle install --local --binstubs') if rails_gt_6_0?
run_command_within_bundle!('rails g rspec:install')
remove_from_file '.rspec', '--warnings'
end

View File

@ -1,22 +0,0 @@
From 4a2702e5a0b18cb86a8bb0d52616a44f1ef70852 Mon Sep 17 00:00:00 2001
From: Josh Nichols <josh.nichols@gusto.com>
Date: Wed, 26 Jan 2022 08:52:44 -0500
Subject: [PATCH] conditionally use unloadable in another spot
---
spec/support/unit/helpers/class_builder.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb
index f73fe2e3a..569aca74d 100644
--- a/spec/support/unit/helpers/class_builder.rb
+++ b/spec/support/unit/helpers/class_builder.rb
@@ -34,7 +34,7 @@ module #{namespace}::#{name_without_namespace}
RUBY
namespace.const_get(name_without_namespace).tap do |constant|
- constant.unloadable
+ constant.unloadable if constant.respond_to?(:unloadable) # if Rails is in classic mode, mark it unloadable
@_defined_modules = defined_modules | [constant]
if block

View File

@ -1,33 +1,14 @@
%global gem_name shoulda-matchers
Name: rubygem-%{gem_name}
Version: 5.1.0
Version: 5.3.0
Release: 1
Summary: Making tests easy on the fingers and eyes
License: MIT
URL: https://github.com/thoughtbot/shoulda-matchers
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
# git clone https://github.com/thoughtbot/shoulda-matchers.git && cd shoulda-matchers
# git archive -v -o shoulda-matchers-5.1.0-specs.tar.gz v5.1.0 spec/
# git archive -v -o shoulda-matchers-5.3.0-specs.tar.gz v5.3.0 spec/
Source1: %{gem_name}-%{version}-specs.tar.gz
# Fix bootsnap removal which is not enclosed in quotes.
# https://github.com/thoughtbot/shoulda-matchers/pull/1478
Patch0: rubygem-shoulda-matchers-5.1.0-Skip-bootsnap-on-the-test-project-creation.patch
# Fix RoR 7+ compatibility.
# https://github.com/thoughtbot/shoulda-matchers/pull/1485
Patch1: rubygem-shoulda-matchers-5.1.0-Only-mark-classes-as-unloadable-when-Rails-supports-it.patch
Patch2: rubygem-shoulda-matchers-5.1.0-conditionally-use-unloadable-in-another-spot.patch
Patch3: rubygem-shoulda-matchers-5.1.0-Use-a-hard-coded-DateTime-instead-of-DateTime.now-1.patch
Patch4: rubygem-shoulda-matchers-5.1.0-Address-differences-in-has_secure_password-in-Rails-7.patch
Patch5: rubygem-shoulda-matchers-5.1.0-Address-differences-in-has_secure_password-in-Rails-7-test.patch
# Don't try to connect to rubygems.org.
# https://github.com/thoughtbot/shoulda-matchers/pull/1504
Patch6: rubygem-shoulda-matchers-5.1.0-Using-local-gems-should-be-enough-for-testing.patch
# Use sqlite3 1.4 unconditionally.
# https://github.com/thoughtbot/shoulda-matchers/pull/1484/commits/7656cdf9abb4a0f7c4fd4cb9c971e474bfc0f9ee
Patch7: rubygem-shoulda-matchers-5.1.0-Always-use-sqlite-1.4.patch
BuildRequires: ruby(release) rubygems-devel ruby rubygem(bcrypt) rubygem(jbuilder)
BuildRequires: rubygem(puma) rubygem(rails) rubygem(rails-controller-testing) rubygem(rspec) rubygem(rspec-rails)
@ -49,17 +30,6 @@ Documentation for %{name}.
%prep
%setup -q -n %{gem_name}-%{version} -b 1
%patch4 -p1
pushd %{_builddir}
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
popd
%build
gem build ../%{gem_name}-%{version}.gemspec
@ -134,6 +104,9 @@ popd
%{gem_instdir}/shoulda-matchers.gemspec
%changelog
* Thu Nov 16 2023 Ge Wang <wang__ge@126.com> - 5.3.0-1
- update to 5.3.0
* Tue Jan 17 2023 wulei <wulei80@h-partners.com> - 5.1.0-1
- update to 5.1.0

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
shoulda-matchers-5.3.0.gem Normal file

Binary file not shown.