package upgrade
This commit is contained in:
parent
0282e4c06a
commit
0115a8caa3
@ -1,255 +0,0 @@
|
||||
diff -Nur a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
|
||||
--- a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb 2022-03-02 17:38:38.274324841 +0800
|
||||
+++ b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb 2022-03-02 17:48:15.220014811 +0800
|
||||
@@ -562,7 +562,8 @@
|
||||
|
||||
def has_been_qualified?
|
||||
@submatchers.any? do |submatcher|
|
||||
- submatcher.class.parent == NumericalityMatchers
|
||||
+ Shoulda::Matchers::RailsShim.parent_of(submatcher.class) ==
|
||||
+ NumericalityMatchers
|
||||
end
|
||||
end
|
||||
|
||||
diff -Nur a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
|
||||
--- a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb 2022-03-02 17:38:38.274324841 +0800
|
||||
+++ b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb 2022-03-02 17:48:15.220014811 +0800
|
||||
@@ -134,9 +134,8 @@
|
||||
private
|
||||
|
||||
def secure_password_being_validated?
|
||||
- defined?(::ActiveModel::SecurePassword) &&
|
||||
- @subject.class.ancestors.include?(::ActiveModel::SecurePassword::InstanceMethodsOnActivation) &&
|
||||
- @attribute == :password
|
||||
+ Shoulda::Matchers::RailsShim.digestible_attributes_in(@subject).
|
||||
+ include?(@attribute)
|
||||
end
|
||||
|
||||
def disallows_and_double_checks_value_of!(value, message)
|
||||
diff -Nur a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb
|
||||
--- a/lib/shoulda/matchers/active_record/association_matcher.rb 2022-03-02 17:38:38.278324908 +0800
|
||||
+++ b/lib/shoulda/matchers/active_record/association_matcher.rb 2022-03-02 17:57:16.205124877 +0800
|
||||
@@ -1182,13 +1182,11 @@
|
||||
def class_has_foreign_key?(klass)
|
||||
if options.key?(:foreign_key)
|
||||
option_verifier.correct_for_string?(:foreign_key, options[:foreign_key])
|
||||
+ elsif column_names_for(klass).include?(foreign_key)
|
||||
+ true
|
||||
else
|
||||
- if klass.column_names.include?(foreign_key)
|
||||
- true
|
||||
- else
|
||||
- @missing = "#{klass} does not have a #{foreign_key} foreign key."
|
||||
- false
|
||||
- end
|
||||
+ @missing = "#{klass} does not have a #{foreign_key} foreign key."
|
||||
+ false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1226,6 +1224,11 @@
|
||||
def submatchers_match?
|
||||
failing_submatchers.empty?
|
||||
end
|
||||
+ def column_names_for(klass)
|
||||
+ klass.column_names
|
||||
+ rescue ::ActiveRecord::StatementInvalid
|
||||
+ []
|
||||
+ end
|
||||
end
|
||||
end
|
||||
end
|
||||
diff -Nur a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb
|
||||
--- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb 2022-03-02 17:38:38.278324908 +0800
|
||||
+++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb 2022-03-02 17:48:15.224014878 +0800
|
||||
@@ -502,10 +502,11 @@
|
||||
end
|
||||
|
||||
def ensure_secure_password_set(instance)
|
||||
- if has_secure_password?
|
||||
- instance.password = "password"
|
||||
- instance.password_confirmation = "password"
|
||||
- end
|
||||
+ Shoulda::Matchers::RailsShim.digestible_attributes_in(instance).
|
||||
+ each do |attribute|
|
||||
+ instance.send("#{attribute}=", 'password')
|
||||
+ instance.send("#{attribute}_confirmation=", 'password')
|
||||
+ end
|
||||
end
|
||||
|
||||
def update_existing_record!(value)
|
||||
@@ -529,9 +530,7 @@
|
||||
end
|
||||
|
||||
def has_secure_password?
|
||||
- model.ancestors.map(&:to_s).include?(
|
||||
- 'ActiveModel::SecurePassword::InstanceMethodsOnActivation'
|
||||
- )
|
||||
+ Shoulda::Matchers::RailsShim.has_secure_password?(subject, @attribute)
|
||||
end
|
||||
|
||||
def build_new_record
|
||||
diff -Nur a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb 2022-03-02 17:38:38.274324841 +0800
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb 2022-03-02 17:48:15.224014878 +0800
|
||||
@@ -107,6 +107,43 @@
|
||||
end
|
||||
end
|
||||
|
||||
+ def parent_of(mod)
|
||||
+ if mod.respond_to?(:module_parent)
|
||||
+ mod.module_parent
|
||||
+ else
|
||||
+ mod.parent
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def has_secure_password?(record, attribute_name)
|
||||
+ if secure_password_module
|
||||
+ attribute_name == :password &&
|
||||
+ record.class.ancestors.include?(secure_password_module)
|
||||
+ else
|
||||
+ record.respond_to?("authenticate_#{attribute_name}")
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def digestible_attributes_in(record)
|
||||
+ record.methods.inject([]) do |array, method_name|
|
||||
+ match = method_name.to_s.match(
|
||||
+ /\A(\w+)_(?:confirmation|digest)=\Z/,
|
||||
+ )
|
||||
+
|
||||
+ if match
|
||||
+ array.concat([match[1].to_sym])
|
||||
+ else
|
||||
+ array
|
||||
+ end
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def secure_password_module
|
||||
+ ::ActiveModel::SecurePassword::InstanceMethodsOnActivation
|
||||
+ rescue NameError
|
||||
+ nil
|
||||
+ end
|
||||
+
|
||||
private
|
||||
|
||||
def simply_generate_validation_message(
|
||||
diff -Nur a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb
|
||||
--- a/spec/support/unit/helpers/class_builder.rb 2022-03-02 17:38:38.270324774 +0800
|
||||
+++ b/spec/support/unit/helpers/class_builder.rb 2022-03-02 17:48:15.224014878 +0800
|
||||
@@ -18,18 +18,15 @@
|
||||
end
|
||||
|
||||
def reset
|
||||
- remove_defined_classes
|
||||
+ remove_defined_modules
|
||||
+ defined_modules.clear
|
||||
end
|
||||
|
||||
def define_module(module_name, &block)
|
||||
module_name = module_name.to_s.camelize
|
||||
+ namespace, name_without_namespace = parse_constant_name(module_name)
|
||||
|
||||
- namespace, name_without_namespace =
|
||||
- ClassBuilder.parse_constant_name(module_name)
|
||||
-
|
||||
- if namespace.const_defined?(name_without_namespace, false)
|
||||
- namespace.__send__(:remove_const, name_without_namespace)
|
||||
- end
|
||||
+ remove_defined_module(module_name)
|
||||
|
||||
eval <<-RUBY
|
||||
module #{namespace}::#{name_without_namespace}
|
||||
@@ -38,6 +35,7 @@
|
||||
|
||||
namespace.const_get(name_without_namespace).tap do |constant|
|
||||
constant.unloadable
|
||||
+ @_defined_modules = defined_modules | [constant]
|
||||
|
||||
if block
|
||||
constant.module_eval(&block)
|
||||
@@ -47,13 +45,9 @@
|
||||
|
||||
def define_class(class_name, parent_class = Object, &block)
|
||||
class_name = class_name.to_s.camelize
|
||||
+ namespace, name_without_namespace = parse_constant_name(class_name)
|
||||
|
||||
- namespace, name_without_namespace =
|
||||
- ClassBuilder.parse_constant_name(class_name)
|
||||
-
|
||||
- if namespace.const_defined?(name_without_namespace, false)
|
||||
- namespace.__send__(:remove_const, name_without_namespace)
|
||||
- end
|
||||
+ remove_defined_module(class_name)
|
||||
|
||||
eval <<-RUBY
|
||||
class #{namespace}::#{name_without_namespace} < ::#{parent_class}
|
||||
@@ -62,6 +56,7 @@
|
||||
|
||||
namespace.const_get(name_without_namespace).tap do |constant|
|
||||
constant.unloadable
|
||||
+ @_defined_modules = defined_modules | [constant]
|
||||
|
||||
if block
|
||||
if block.arity == 0
|
||||
@@ -82,8 +77,21 @@
|
||||
|
||||
private
|
||||
|
||||
- def remove_defined_classes
|
||||
- ::ActiveSupport::Dependencies.clear
|
||||
+ def remove_defined_modules
|
||||
+ defined_modules.reverse_each { |mod| remove_defined_module(mod.name) }
|
||||
+ ActiveSupport::Dependencies.clear
|
||||
+ end
|
||||
+
|
||||
+ def remove_defined_module(module_name)
|
||||
+ namespace, name_without_namespace = parse_constant_name(module_name)
|
||||
+
|
||||
+ if namespace.const_defined?(name_without_namespace, false)
|
||||
+ namespace.__send__(:remove_const, name_without_namespace)
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def defined_modules
|
||||
+ @_defined_modules ||= []
|
||||
end
|
||||
end
|
||||
end
|
||||
diff -Nur a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
|
||||
--- a/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb 2022-03-02 17:38:38.262324640 +0800
|
||||
+++ b/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb 2022-03-02 18:04:41.336620792 +0800
|
||||
@@ -1,20 +1,18 @@
|
||||
require 'unit_spec_helper'
|
||||
|
||||
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher, type: :model do
|
||||
- if active_model_3_1?
|
||||
- it 'matches when the subject configures has_secure_password with default options' do
|
||||
- working_model = define_model(:example, password_digest: :string) { has_secure_password }
|
||||
- expect(working_model.new).to have_secure_password
|
||||
- end
|
||||
+ it 'matches when the subject configures has_secure_password with default options' do
|
||||
+ working_model = define_model(:example, password_digest: :string) { has_secure_password }
|
||||
+ expect(working_model.new).to have_secure_password
|
||||
+ end
|
||||
|
||||
- it 'does not match when the subject does not authenticate a password' do
|
||||
- no_secure_password = define_model(:example)
|
||||
- expect(no_secure_password.new).not_to have_secure_password
|
||||
- end
|
||||
+ it 'does not match when the subject does not authenticate a password' do
|
||||
+ no_secure_password = define_model(:example)
|
||||
+ expect(no_secure_password.new).not_to have_secure_password
|
||||
+ end
|
||||
|
||||
- it 'does not match when the subject is missing the password_digest attribute' do
|
||||
- no_digest_column = define_model(:example) { has_secure_password }
|
||||
- expect(no_digest_column.new).not_to have_secure_password
|
||||
- end
|
||||
+ it 'does not match when the subject is missing the password_digest attribute' do
|
||||
+ no_digest_column = define_model(:example) { has_secure_password }
|
||||
+ expect(no_digest_column.new).not_to have_secure_password
|
||||
end
|
||||
end
|
||||
@ -1,253 +0,0 @@
|
||||
diff -Nur a/spec/support/unit/active_record/create_table.rb b/spec/support/unit/active_record/create_table.rb
|
||||
--- a/spec/support/unit/active_record/create_table.rb 2022-03-02 15:43:54.402107119 +0800
|
||||
+++ b/spec/support/unit/active_record/create_table.rb 2022-03-02 15:47:54.230150787 +0800
|
||||
@@ -47,7 +47,7 @@
|
||||
column_options = {}
|
||||
end
|
||||
|
||||
- table.column(column_name, column_type, column_options)
|
||||
+ table.column(column_name, column_type, **column_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
diff -Nur a/spec/support/unit/helpers/model_builder.rb b/spec/support/unit/helpers/model_builder.rb
|
||||
--- a/spec/support/unit/helpers/model_builder.rb 2022-03-02 15:43:54.410107254 +0800
|
||||
+++ b/spec/support/unit/helpers/model_builder.rb 2022-03-02 15:47:54.230150787 +0800
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
begin
|
||||
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
||||
- connection.create_table(table_name, options, &block)
|
||||
+ connection.create_table(table_name, **options, &block)
|
||||
created_tables << table_name
|
||||
connection
|
||||
rescue Exception => e
|
||||
diff -Nur 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
|
||||
--- a/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb 2022-03-02 15:43:54.634111031 +0800
|
||||
+++ b/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb 2022-03-02 15:55:07.113449499 +0800
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :integer, value: 1),
|
||||
+ **options.merge(column_type: :integer, value: 1),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(
|
||||
+ **options.merge(
|
||||
column_type: :integer,
|
||||
column_options: { limit: 2 },
|
||||
value: 1
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :float, value: 1.0),
|
||||
+ **options.merge(column_type: :float, value: 1.0),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -118,7 +118,7 @@
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :decimal, value: BigDecimal('1.0')),
|
||||
+ **options.merge(column_type: :decimal, value: BigDecimal('1.0')),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -149,7 +149,7 @@
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :date, value: today),
|
||||
+ **options.merge(column_type: :date, value: today),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -177,7 +177,7 @@
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :datetime, value: now),
|
||||
+ **options.merge(column_type: :datetime, value: now),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -204,7 +204,7 @@
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :time, value: default_time),
|
||||
+ **options.merge(column_type: :time, value: default_time),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -225,7 +225,7 @@
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :string),
|
||||
+ **options.merge(column_type: :string),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -731,7 +731,7 @@
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :timestamp, value: now),
|
||||
+ **options.merge(column_type: :timestamp, value: now),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -772,7 +772,7 @@
|
||||
end
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
- super(options.merge(column_options: { null: true }, value: true))
|
||||
+ super(**options.merge(column_options: { null: true }, value: true))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -792,13 +792,13 @@
|
||||
end
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
- super(options.merge(column_options: { null: false }))
|
||||
+ super(**options.merge(column_options: { null: false }))
|
||||
end
|
||||
end
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :boolean),
|
||||
+ **options.merge(column_type: :boolean),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -820,7 +820,7 @@
|
||||
include_context 'against a boolean attribute for true and false'
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
- build_object_with_generic_attribute(options.merge(value: true))
|
||||
+ build_object_with_generic_attribute(**options.merge(value: true))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -828,7 +828,7 @@
|
||||
include_context 'against a boolean attribute for true and false'
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
- build_object_with_generic_attribute(options.merge(value: false))
|
||||
+ build_object_with_generic_attribute(**options.merge(value: false))
|
||||
end
|
||||
end
|
||||
|
||||
diff -Nur a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb 2022-03-02 15:43:54.630110963 +0800
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb 2022-03-02 15:59:12.837592578 +0800
|
||||
@@ -282,13 +282,13 @@
|
||||
def belonging_to_parent(options = {})
|
||||
define_model :parent
|
||||
define_model :child, parent_id: :integer do
|
||||
- belongs_to :parent, options
|
||||
+ belongs_to :parent, **options
|
||||
end.new
|
||||
end
|
||||
|
||||
def belonging_to_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name, "#{assoc_name}_id" => :integer do
|
||||
- belongs_to assoc_name, options
|
||||
+ belongs_to assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -575,14 +575,14 @@
|
||||
order = options.delete(:order)
|
||||
define_association_with_order(model, :has_many, :children, order, options)
|
||||
else
|
||||
- model.has_many :children, options
|
||||
+ model.has_many :children, **options
|
||||
end
|
||||
end.new
|
||||
end
|
||||
|
||||
def having_many_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_many assoc_name, options
|
||||
+ has_many assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -833,14 +833,14 @@
|
||||
order = options.delete(:order)
|
||||
define_association_with_order(model, :has_one, :detail, order, options)
|
||||
else
|
||||
- model.has_one :detail, options
|
||||
+ model.has_one :detail, **options
|
||||
end
|
||||
end.new
|
||||
end
|
||||
|
||||
def having_one_non_existent(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_one assoc_name, options
|
||||
+ has_one assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -1202,33 +1202,17 @@
|
||||
|
||||
def having_and_belonging_to_many_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_and_belongs_to_many assoc_name, options
|
||||
+ has_and_belongs_to_many assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
|
||||
def define_association_with_conditions(model, macro, name, conditions, other_options={})
|
||||
- args = []
|
||||
- options = {}
|
||||
- if active_record_supports_relations?
|
||||
- args << proc { where(conditions) }
|
||||
- else
|
||||
- options[:conditions] = conditions
|
||||
- end
|
||||
- args << options
|
||||
- model.__send__(macro, name, *args)
|
||||
+ model.__send__(macro, name, proc { where(conditions) }, **{})
|
||||
end
|
||||
|
||||
def define_association_with_order(model, macro, name, order, other_options={})
|
||||
- args = []
|
||||
- options = {}
|
||||
- if active_record_supports_relations?
|
||||
- args << proc { order(order) }
|
||||
- else
|
||||
- options[:order] = order
|
||||
- end
|
||||
- args << options
|
||||
- model.__send__(macro, name, *args)
|
||||
+ model.__send__(macro, name, proc { order(order) }, **{})
|
||||
end
|
||||
|
||||
def dependent_options
|
||||
diff -Nur a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
|
||||
--- a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb 2022-03-02 15:43:54.434107659 +0800
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb 2022-03-02 15:47:54.230150787 +0800
|
||||
@@ -104,7 +104,7 @@
|
||||
|
||||
def with_table(column_name, column_type, options)
|
||||
create_table 'employees' do |table|
|
||||
- table.__send__(column_type, column_name, options)
|
||||
+ table.__send__(column_type, column_name, **options)
|
||||
end
|
||||
define_model_class('Employee').new
|
||||
end
|
||||
@ -1,12 +0,0 @@
|
||||
diff -Nur a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb 2022-03-02 16:34:47.793626953 +0800
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb 2022-03-02 16:38:09.209032206 +0800
|
||||
@@ -61,7 +61,7 @@
|
||||
request_params
|
||||
end
|
||||
|
||||
- context.__send__(verb, action, params)
|
||||
+ context.__send__(verb, action,**params)
|
||||
end
|
||||
|
||||
def serialized_attributes_for(model)
|
||||
@ -1,76 +0,0 @@
|
||||
From 0c07bfb039b0fe9f9863e885ee3885e48f3b39d9 Mon Sep 17 00:00:00 2001
|
||||
From: Teo Ljungberg <teo@teoljungberg.com>
|
||||
Date: Wed, 27 Dec 2017 17:20:02 +0100
|
||||
Subject: [PATCH] Use `BigDecimal()` over `BigDecimal.new`
|
||||
|
||||
As the latter is deprecated since: ruby/bigdecimal@5337373
|
||||
---
|
||||
.../active_model/validate_absence_of_matcher.rb | 2 +-
|
||||
.../active_model/validate_inclusion_of_matcher.rb | 2 +-
|
||||
.../validate_inclusion_of_matcher_spec.rb | 12 ++++++------
|
||||
3 files changed, 8 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb
|
||||
index 1c33816c0..f663f55e8 100644
|
||||
--- a/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb
|
||||
+++ b/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb
|
||||
@@ -105,7 +105,7 @@ def value
|
||||
else
|
||||
case column_type
|
||||
when :integer, :float then 1
|
||||
- when :decimal then BigDecimal.new(1, 0)
|
||||
+ when :decimal then BigDecimal(1, 0)
|
||||
when :datetime, :time, :timestamp then Time.now
|
||||
when :date then Date.new
|
||||
when :binary then '0'
|
||||
diff --git a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
index 717eecc95..4b96be052 100644
|
||||
--- a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
+++ b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
@@ -270,7 +270,7 @@ def validate_inclusion_of(attr)
|
||||
class ValidateInclusionOfMatcher < ValidationMatcher
|
||||
ARBITRARY_OUTSIDE_STRING = 'shoulda-matchers test string'
|
||||
ARBITRARY_OUTSIDE_INTEGER = 123456789
|
||||
- ARBITRARY_OUTSIDE_DECIMAL = BigDecimal.new('0.123456789')
|
||||
+ ARBITRARY_OUTSIDE_DECIMAL = BigDecimal('0.123456789')
|
||||
ARBITRARY_OUTSIDE_DATE = Date.jd(9999999)
|
||||
ARBITRARY_OUTSIDE_DATETIME = DateTime.jd(9999999)
|
||||
ARBITRARY_OUTSIDE_TIME = Time.at(9999999999)
|
||||
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 dfe895e1a..a5efb15e5 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
|
||||
@@ -107,18 +107,18 @@ def validation_matcher_scenario_args
|
||||
context 'against a decimal attribute' do
|
||||
it_behaves_like 'it supports in_array',
|
||||
possible_values: [1.0, 2.0, 3.0, 4.0, 5.0].map { |number|
|
||||
- BigDecimal.new(number.to_s)
|
||||
+ BigDecimal(number.to_s)
|
||||
},
|
||||
- zero: BigDecimal.new('0.0'),
|
||||
+ zero: BigDecimal('0.0'),
|
||||
reserved_outside_value: described_class::ARBITRARY_OUTSIDE_DECIMAL
|
||||
|
||||
it_behaves_like 'it supports in_range',
|
||||
- possible_values: BigDecimal.new('1.0') .. BigDecimal.new('5.0'),
|
||||
- zero: BigDecimal.new('0.0')
|
||||
+ possible_values: BigDecimal('1.0') .. BigDecimal('5.0'),
|
||||
+ zero: BigDecimal('0.0')
|
||||
|
||||
def build_object(options = {}, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :decimal, value: BigDecimal.new('1.0')),
|
||||
+ options.merge(column_type: :decimal, value: BigDecimal('1.0')),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -130,7 +130,7 @@ def add_outside_value_to(values)
|
||||
def validation_matcher_scenario_args
|
||||
super.deep_merge(
|
||||
column_type: :decimal,
|
||||
- default_value: BigDecimal.new('1.0')
|
||||
+ default_value: BigDecimal('1.0')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
diff -Nur a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
|
||||
--- a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb 2022-03-02 19:06:24.099019714 +0800
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb 2022-03-02 19:25:43.998524568 +0800
|
||||
@@ -79,7 +79,7 @@
|
||||
def with_index_on(column_name, index_options = {})
|
||||
create_table 'employees' do |table|
|
||||
table.integer column_name
|
||||
- end.add_index(:employees, column_name, index_options)
|
||||
+ end.add_index(:employees, column_name, **index_options)
|
||||
define_model_class('Employee').new
|
||||
end
|
||||
end
|
||||
@ -1,12 +0,0 @@
|
||||
diff -Nur a/lib/shoulda/matchers/util/word_wrap.rb b/lib/shoulda/matchers/util/word_wrap.rb
|
||||
--- a/lib/shoulda/matchers/util/word_wrap.rb 2022-03-02 17:01:03.260250272 +0800
|
||||
+++ b/lib/shoulda/matchers/util/word_wrap.rb 2022-03-02 17:00:26.059621102 +0800
|
||||
@@ -2,7 +2,7 @@
|
||||
module Matchers
|
||||
# @private
|
||||
def self.word_wrap(document, options = {})
|
||||
- Document.new(document, options).wrap
|
||||
+ Document.new(document, **options).wrap
|
||||
end
|
||||
|
||||
# @private
|
||||
@ -1,47 +0,0 @@
|
||||
From d0c032974234b4b124788cf57fe0f48d6f54a4a1 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 23:31:56 -0500
|
||||
Subject: [PATCH] Doublespeak: Define #respond_to_missing? on ObjectDouble
|
||||
|
||||
The `delegate_method` matcher uses Doublespeak internally to do its job.
|
||||
The delegate object is completely stubbed using an ObjectDouble,
|
||||
available from Doublespeak, which is shoulda-matchers's own test double
|
||||
library. ObjectDouble is a class that responds to every
|
||||
method by implementing `method_missing`.
|
||||
|
||||
Say you are using Ruby 2.4 and you are testing a class that uses the
|
||||
Forwardable module to do some delegation, and you are using
|
||||
`delegate_method` in your test. When you run your test you will a
|
||||
warning that looks something like:
|
||||
|
||||
Courier#deliver at ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/forwardable.rb:156 forwarding to private method #deliver
|
||||
|
||||
Why is this happening? When the code in your class gets exercised,
|
||||
Forwardable will delegate the delegate method in question to
|
||||
ObjectDouble, and the method will get intercepted by its
|
||||
`method_missing` method. The fact that this is actually a private method
|
||||
is what Forwardable is complaining about.
|
||||
|
||||
To fix this, all we need to do is add `respond_to_missing?` in addition
|
||||
to `method_missing?`. This is explained here:
|
||||
|
||||
https://bugs.ruby-lang.org/issues/13326
|
||||
---
|
||||
lib/shoulda/matchers/doublespeak/object_double.rb | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/doublespeak/object_double.rb b/lib/shoulda/matchers/doublespeak/object_double.rb
|
||||
index 823797b3..fe86a4a7 100644
|
||||
--- a/lib/shoulda/matchers/doublespeak/object_double.rb
|
||||
+++ b/lib/shoulda/matchers/doublespeak/object_double.rb
|
||||
@@ -18,6 +18,10 @@ def respond_to?(name, include_private = nil)
|
||||
true
|
||||
end
|
||||
|
||||
+ def respond_to_missing?(name, include_all)
|
||||
+ true
|
||||
+ end
|
||||
+
|
||||
def method_missing(method_name, *args, &block)
|
||||
call = MethodCall.new(
|
||||
method_name: method_name,
|
||||
@ -1,75 +0,0 @@
|
||||
From 03a1d213805a44a0aec99857e01cab8524aa0c05 Mon Sep 17 00:00:00 2001
|
||||
From: Dmitri Koulikoff <dima@koulikoff.ru>
|
||||
Date: Tue, 25 Jul 2017 16:45:07 +0200
|
||||
Subject: [PATCH] Deprecation for ruby 2.4 removed
|
||||
|
||||
Secondary credit: camelmasa <camelmasa@gmail.com>
|
||||
---
|
||||
.../active_model/validate_inclusion_of_matcher.rb | 10 +++++-----
|
||||
.../active_model/validate_inclusion_of_matcher_spec.rb | 4 ++--
|
||||
2 files changed, 7 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
index a1c68d79..717eecc9 100644
|
||||
--- a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
+++ b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb
|
||||
@@ -269,7 +269,7 @@ def validate_inclusion_of(attr)
|
||||
# @private
|
||||
class ValidateInclusionOfMatcher < ValidationMatcher
|
||||
ARBITRARY_OUTSIDE_STRING = 'shoulda-matchers test string'
|
||||
- ARBITRARY_OUTSIDE_FIXNUM = 123456789
|
||||
+ ARBITRARY_OUTSIDE_INTEGER = 123456789
|
||||
ARBITRARY_OUTSIDE_DECIMAL = BigDecimal.new('0.123456789')
|
||||
ARBITRARY_OUTSIDE_DATE = Date.jd(9999999)
|
||||
ARBITRARY_OUTSIDE_DATETIME = DateTime.jd(9999999)
|
||||
@@ -483,8 +483,8 @@ def outside_values
|
||||
case attribute_type
|
||||
when :boolean
|
||||
boolean_outside_values
|
||||
- when :fixnum
|
||||
- [ARBITRARY_OUTSIDE_FIXNUM]
|
||||
+ when :integer
|
||||
+ [ARBITRARY_OUTSIDE_INTEGER]
|
||||
when :decimal
|
||||
[ARBITRARY_OUTSIDE_DECIMAL]
|
||||
when :date
|
||||
@@ -538,7 +538,7 @@ def attribute_column
|
||||
|
||||
def column_type_to_attribute_type(type)
|
||||
case type
|
||||
- when :integer, :float then :fixnum
|
||||
+ when :float then :integer
|
||||
when :timestamp then :datetime
|
||||
else type
|
||||
end
|
||||
@@ -548,7 +548,7 @@ def value_to_attribute_type(value)
|
||||
case value
|
||||
when true, false then :boolean
|
||||
when BigDecimal then :decimal
|
||||
- when Fixnum then :fixnum
|
||||
+ when Integer then :integer
|
||||
when Date then :date
|
||||
when DateTime then :datetime
|
||||
when Time then :time
|
||||
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 62a322d4..5053c547 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
|
||||
@@ -25,7 +25,7 @@ def self.testing_values_of_option(option_name, &block)
|
||||
it_behaves_like 'it supports in_array',
|
||||
possible_values: (1..5).to_a,
|
||||
zero: 0,
|
||||
- reserved_outside_value: described_class::ARBITRARY_OUTSIDE_FIXNUM
|
||||
+ reserved_outside_value: described_class::ARBITRARY_OUTSIDE_INTEGER
|
||||
|
||||
it_behaves_like 'it supports in_range',
|
||||
possible_values: 1..5,
|
||||
@@ -82,7 +82,7 @@ def expect_to_match_on_values(builder, values, &block)
|
||||
it_behaves_like 'it supports in_array',
|
||||
possible_values: [1.0, 2.0, 3.0, 4.0, 5.0],
|
||||
zero: 0.0,
|
||||
- reserved_outside_value: described_class::ARBITRARY_OUTSIDE_FIXNUM
|
||||
+ reserved_outside_value: described_class::ARBITRARY_OUTSIDE_INTEGER
|
||||
|
||||
it_behaves_like 'it supports in_range',
|
||||
possible_values: 1.0..5.0,
|
||||
@ -1,230 +0,0 @@
|
||||
From c1a81d4b132a9e6091c42c3ebcd3144fc593c016 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 21:36:47 -0500
|
||||
Subject: [PATCH] Disable allow_mass_assignment_of tests under Rails 5
|
||||
|
||||
The `allow_mass_assignment_of` matcher tests `attr_accessible` and
|
||||
`attr_protected` which was moved to the `protected_attributes` gem in
|
||||
Rails 4. The gem does not work in Rails 5 and neither does the matcher,
|
||||
so there is no need to test it. (We should probably remove the matcher
|
||||
altogether eventually -- Strong Parameters have long replaced
|
||||
`protected_attributes`.)
|
||||
---
|
||||
spec/support/unit/helpers/rails_versions.rb | 4 +
|
||||
.../allow_mass_assignment_of_matcher_spec.rb | 158 +++++++++---------
|
||||
2 files changed, 84 insertions(+), 78 deletions(-)
|
||||
|
||||
diff --git a/spec/support/unit/helpers/rails_versions.rb b/spec/support/unit/helpers/rails_versions.rb
|
||||
index 5ac1562c..61b233a6 100644
|
||||
--- a/spec/support/unit/helpers/rails_versions.rb
|
||||
+++ b/spec/support/unit/helpers/rails_versions.rb
|
||||
@@ -24,5 +24,9 @@ def rails_gte_4_1?
|
||||
def rails_gte_4_2?
|
||||
rails_version >= 4.2
|
||||
end
|
||||
+
|
||||
+ def rails_lte_5?
|
||||
+ rails_version < 5
|
||||
+ end
|
||||
end
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
index 175aec92..f53c82e6 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
@@ -1,115 +1,117 @@
|
||||
require 'unit_spec_helper'
|
||||
|
||||
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :model do
|
||||
- context '#description' do
|
||||
- context 'without a role' do
|
||||
- it 'includes the attribute name' do
|
||||
- expect(described_class.new(:attr).description).
|
||||
- to eq 'allow mass assignment of attr'
|
||||
+ if rails_lte_5?
|
||||
+ context '#description' do
|
||||
+ context 'without a role' do
|
||||
+ it 'includes the attribute name' do
|
||||
+ expect(described_class.new(:attr).description).
|
||||
+ to eq 'allow mass assignment of attr'
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- if active_model_3_1?
|
||||
- context 'with a role' do
|
||||
- it 'includes the attribute name and the role' do
|
||||
- expect(described_class.new(:attr).as(:admin).description).
|
||||
- to eq 'allow mass assignment of attr as admin'
|
||||
+ if active_model_3_1?
|
||||
+ context 'with a role' do
|
||||
+ it 'includes the attribute name and the role' do
|
||||
+ expect(described_class.new(:attr).as(:admin).description).
|
||||
+ to eq 'allow mass assignment of attr as admin'
|
||||
+ end
|
||||
end
|
||||
end
|
||||
end
|
||||
- end
|
||||
|
||||
- context 'an attribute that is blacklisted from mass-assignment' do
|
||||
- it 'rejects being mass-assignable' do
|
||||
- model = define_model(:example, blacklisted: :string) do
|
||||
- attr_protected :blacklisted
|
||||
- end.new
|
||||
+ context 'an attribute that is blacklisted from mass-assignment' do
|
||||
+ it 'rejects being mass-assignable' do
|
||||
+ model = define_model(:example, blacklisted: :string) do
|
||||
+ attr_protected :blacklisted
|
||||
+ end.new
|
||||
|
||||
- expect(model).not_to allow_mass_assignment_of(:blacklisted)
|
||||
+ expect(model).not_to allow_mass_assignment_of(:blacklisted)
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- context 'an attribute that is not whitelisted for mass-assignment' do
|
||||
- it 'rejects being mass-assignable' do
|
||||
- model = define_model(:example, not_whitelisted: :string,
|
||||
- whitelisted: :string) do
|
||||
- attr_accessible :whitelisted
|
||||
- end.new
|
||||
+ context 'an attribute that is not whitelisted for mass-assignment' do
|
||||
+ it 'rejects being mass-assignable' do
|
||||
+ model = define_model(:example, not_whitelisted: :string,
|
||||
+ whitelisted: :string) do
|
||||
+ attr_accessible :whitelisted
|
||||
+ end.new
|
||||
|
||||
- expect(model).not_to allow_mass_assignment_of(:not_whitelisted)
|
||||
+ expect(model).not_to allow_mass_assignment_of(:not_whitelisted)
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- context 'an attribute that is whitelisted for mass-assignment' do
|
||||
- it 'accepts being mass-assignable' do
|
||||
- expect(define_model(:example, whitelisted: :string) do
|
||||
- attr_accessible :whitelisted
|
||||
- end.new).to allow_mass_assignment_of(:whitelisted)
|
||||
+ context 'an attribute that is whitelisted for mass-assignment' do
|
||||
+ it 'accepts being mass-assignable' do
|
||||
+ expect(define_model(:example, whitelisted: :string) do
|
||||
+ attr_accessible :whitelisted
|
||||
+ end.new).to allow_mass_assignment_of(:whitelisted)
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- context 'an attribute not included in the mass-assignment blacklist' do
|
||||
- it 'accepts being mass-assignable' do
|
||||
- model = define_model(:example, not_blacklisted: :string,
|
||||
- blacklisted: :string) do
|
||||
- attr_protected :blacklisted
|
||||
- end.new
|
||||
+ context 'an attribute not included in the mass-assignment blacklist' do
|
||||
+ it 'accepts being mass-assignable' do
|
||||
+ model = define_model(:example, not_blacklisted: :string,
|
||||
+ blacklisted: :string) do
|
||||
+ attr_protected :blacklisted
|
||||
+ end.new
|
||||
|
||||
- expect(model).to allow_mass_assignment_of(:not_blacklisted)
|
||||
+ expect(model).to allow_mass_assignment_of(:not_blacklisted)
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- unless active_model_3_2? || active_model_4_0?
|
||||
- context 'an attribute on a class with no protected attributes' do
|
||||
- it 'accepts being mass-assignable' do
|
||||
- expect(no_protected_attributes).to allow_mass_assignment_of(:attr)
|
||||
- end
|
||||
+ unless active_model_3_2? || active_model_4_0?
|
||||
+ context 'an attribute on a class with no protected attributes' do
|
||||
+ it 'accepts being mass-assignable' do
|
||||
+ expect(no_protected_attributes).to allow_mass_assignment_of(:attr)
|
||||
+ end
|
||||
|
||||
- it 'assigns a negative failure message' do
|
||||
- matcher = allow_mass_assignment_of(:attr)
|
||||
+ it 'assigns a negative failure message' do
|
||||
+ matcher = allow_mass_assignment_of(:attr)
|
||||
|
||||
- expect(matcher.matches?(no_protected_attributes)).to eq true
|
||||
+ expect(matcher.matches?(no_protected_attributes)).to eq true
|
||||
|
||||
- expect(matcher.failure_message_when_negated).not_to be_nil
|
||||
+ expect(matcher.failure_message_when_negated).not_to be_nil
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
-
|
||||
- def no_protected_attributes
|
||||
- define_model(:example, attr: :string).new
|
||||
- end
|
||||
- end
|
||||
|
||||
- context 'an attribute on a class with all protected attributes' do
|
||||
- it 'rejects being mass-assignable' do
|
||||
- expect(all_protected_attributes).not_to allow_mass_assignment_of(:attr)
|
||||
- end
|
||||
-
|
||||
- def all_protected_attributes
|
||||
- define_model(:example, attr: :string) do
|
||||
- attr_accessible nil
|
||||
- end.new
|
||||
+ def no_protected_attributes
|
||||
+ define_model(:example, attr: :string).new
|
||||
+ end
|
||||
end
|
||||
- end
|
||||
|
||||
- if active_model_3_1?
|
||||
- context 'an attribute included in the mass-assignment whitelist for admin role only' do
|
||||
+ context 'an attribute on a class with all protected attributes' do
|
||||
it 'rejects being mass-assignable' do
|
||||
- expect(mass_assignable_as_admin).not_to allow_mass_assignment_of(:attr)
|
||||
- end
|
||||
-
|
||||
- it 'accepts being mass-assignable for admin' do
|
||||
- expect(mass_assignable_as_admin).to allow_mass_assignment_of(:attr).as(:admin)
|
||||
+ expect(all_protected_attributes).not_to allow_mass_assignment_of(:attr)
|
||||
end
|
||||
|
||||
- def mass_assignable_as_admin
|
||||
+ def all_protected_attributes
|
||||
define_model(:example, attr: :string) do
|
||||
- attr_accessible :attr, as: :admin
|
||||
+ attr_accessible nil
|
||||
end.new
|
||||
end
|
||||
end
|
||||
- end
|
||||
|
||||
- def define_model(name, columns, &block)
|
||||
- super(name, columns, whitelist_attributes: false, &block)
|
||||
+ if active_model_3_1?
|
||||
+ context 'an attribute included in the mass-assignment whitelist for admin role only' do
|
||||
+ it 'rejects being mass-assignable' do
|
||||
+ expect(mass_assignable_as_admin).not_to allow_mass_assignment_of(:attr)
|
||||
+ end
|
||||
+
|
||||
+ it 'accepts being mass-assignable for admin' do
|
||||
+ expect(mass_assignable_as_admin).to allow_mass_assignment_of(:attr).as(:admin)
|
||||
+ end
|
||||
+
|
||||
+ def mass_assignable_as_admin
|
||||
+ define_model(:example, attr: :string) do
|
||||
+ attr_accessible :attr, as: :admin
|
||||
+ end.new
|
||||
+ end
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def define_model(name, columns, &block)
|
||||
+ super(name, columns, whitelist_attributes: false, &block)
|
||||
+ end
|
||||
end
|
||||
end
|
||||
@ -1,24 +0,0 @@
|
||||
From c50af24105399651b1bdbf52bddbb9c72d2b2e19 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Sat, 3 Sep 2016 21:39:02 -0600
|
||||
Subject: [PATCH] Don't protect attributes under Rails 5
|
||||
|
||||
The protected_attributes gem is not compatible for Rails 5, and we don't
|
||||
need it anyway with Strong Parameters.
|
||||
---
|
||||
spec/support/unit/model_creation_strategies/active_record.rb | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/spec/support/unit/model_creation_strategies/active_record.rb b/spec/support/unit/model_creation_strategies/active_record.rb
|
||||
index f9e268b4..ed8a83a6 100644
|
||||
--- a/spec/support/unit/model_creation_strategies/active_record.rb
|
||||
+++ b/spec/support/unit/model_creation_strategies/active_record.rb
|
||||
@@ -42,7 +42,7 @@ def define_class_for_model
|
||||
run_block(model, block)
|
||||
end
|
||||
|
||||
- if whitelist_attributes?
|
||||
+ if whitelist_attributes? && model.respond_to?(:attr_accessible)
|
||||
model.attr_accessible(*columns.keys)
|
||||
end
|
||||
|
||||
@ -1,201 +0,0 @@
|
||||
From 6ea9afc1066502fdd5c556fa9edd4ce7085169fc Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Sun, 17 Sep 2017 19:51:41 -0500
|
||||
Subject: [PATCH] Drop legacy callback matchers under Rails 5
|
||||
|
||||
Rails 5 dropped the legacy controller callbacks `before_filter`,
|
||||
`after_filter` and `around_filter`, so the matchers for these callbacks
|
||||
are useless.
|
||||
---
|
||||
.../action_controller/callback_matcher.rb | 24 +++++++++----
|
||||
lib/shoulda/matchers/rails_shim.rb | 10 +++++-
|
||||
.../unit/helpers/action_pack_versions.rb | 6 +++-
|
||||
spec/support/unit/helpers/rails_versions.rb | 2 +-
|
||||
.../callback_matcher_spec.rb | 36 +++++++++----------
|
||||
.../allow_mass_assignment_of_matcher_spec.rb | 2 +-
|
||||
6 files changed, 52 insertions(+), 28 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/action_controller/callback_matcher.rb b/lib/shoulda/matchers/action_controller/callback_matcher.rb
|
||||
index 9569945f..5b915270 100644
|
||||
--- a/lib/shoulda/matchers/action_controller/callback_matcher.rb
|
||||
+++ b/lib/shoulda/matchers/action_controller/callback_matcher.rb
|
||||
@@ -20,10 +20,14 @@ module ActionController
|
||||
# should_not use_before_filter(:prevent_ssl)
|
||||
# end
|
||||
#
|
||||
+ # @note This method is only available when using shoulda-matchers under
|
||||
+ # Rails 4.x.
|
||||
# @return [CallbackMatcher]
|
||||
#
|
||||
- def use_before_filter(callback)
|
||||
- CallbackMatcher.new(callback, :before, :filter)
|
||||
+ if RailsShim.action_pack_lt_5?
|
||||
+ def use_before_filter(callback)
|
||||
+ CallbackMatcher.new(callback, :before, :filter)
|
||||
+ end
|
||||
end
|
||||
|
||||
# The `use_after_filter` matcher is used to test that an after_filter
|
||||
@@ -45,10 +49,14 @@ def use_before_filter(callback)
|
||||
# should_not use_after_filter(:destroy_user)
|
||||
# end
|
||||
#
|
||||
+ # @note This method is only available when using shoulda-matchers under
|
||||
+ # Rails 4.x.
|
||||
# @return [CallbackMatcher]
|
||||
#
|
||||
- def use_after_filter(callback)
|
||||
- CallbackMatcher.new(callback, :after, :filter)
|
||||
+ if RailsShim.action_pack_lt_5?
|
||||
+ def use_after_filter(callback)
|
||||
+ CallbackMatcher.new(callback, :after, :filter)
|
||||
+ end
|
||||
end
|
||||
|
||||
# The `use_before_action` matcher is used to test that a before_action
|
||||
@@ -120,10 +128,14 @@ def use_after_action(callback)
|
||||
# should_not use_around_filter(:save_view_context)
|
||||
# end
|
||||
#
|
||||
+ # @note This method is only available when using shoulda-matchers under
|
||||
+ # Rails 4.x.
|
||||
# @return [CallbackMatcher]
|
||||
#
|
||||
- def use_around_filter(callback)
|
||||
- CallbackMatcher.new(callback, :around, :filter)
|
||||
+ if RailsShim.action_pack_lt_5?
|
||||
+ def use_around_filter(callback)
|
||||
+ CallbackMatcher.new(callback, :around, :filter)
|
||||
+ end
|
||||
end
|
||||
|
||||
# The `use_around_action` matcher is used to test that an around_action
|
||||
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
index 1fea4eb1..c5be6a30 100644
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb
|
||||
@@ -1,7 +1,7 @@
|
||||
module Shoulda
|
||||
module Matchers
|
||||
# @private
|
||||
- class RailsShim
|
||||
+ module RailsShim
|
||||
class << self
|
||||
def action_pack_gte_4_1?
|
||||
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||
@@ -11,12 +11,20 @@ def action_pack_gte_5?
|
||||
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||
end
|
||||
|
||||
+ def action_pack_lt_5?
|
||||
+ Gem::Requirement.new('< 5').satisfied_by?(action_pack_version)
|
||||
+ end
|
||||
+
|
||||
def action_pack_version
|
||||
Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||
+ rescue NameError
|
||||
+ Gem::Version.new('0')
|
||||
end
|
||||
|
||||
def active_record_major_version
|
||||
::ActiveRecord::VERSION::MAJOR
|
||||
+ rescue NameError
|
||||
+ Gem::Version.new('0')
|
||||
end
|
||||
|
||||
def generate_validation_message(
|
||||
diff --git a/spec/support/unit/helpers/action_pack_versions.rb b/spec/support/unit/helpers/action_pack_versions.rb
|
||||
index 86606f7b..5e6b77fa 100644
|
||||
--- a/spec/support/unit/helpers/action_pack_versions.rb
|
||||
+++ b/spec/support/unit/helpers/action_pack_versions.rb
|
||||
@@ -8,7 +8,11 @@ def self.configure_example_group(example_group)
|
||||
end
|
||||
|
||||
def action_pack_gte_5?
|
||||
- action_pack_version =~ '>= 5'
|
||||
+ action_pack_version >= 5
|
||||
+ end
|
||||
+
|
||||
+ def action_pack_lt_5?
|
||||
+ action_pack_version < 5
|
||||
end
|
||||
|
||||
def action_pack_version
|
||||
diff --git a/spec/support/unit/helpers/rails_versions.rb b/spec/support/unit/helpers/rails_versions.rb
|
||||
index 161f9628..d555378e 100644
|
||||
--- a/spec/support/unit/helpers/rails_versions.rb
|
||||
+++ b/spec/support/unit/helpers/rails_versions.rb
|
||||
@@ -25,7 +25,7 @@ def rails_gte_4_2?
|
||||
rails_version >= 4.2
|
||||
end
|
||||
|
||||
- def rails_lte_5?
|
||||
+ def rails_lt_5?
|
||||
rails_version < 5
|
||||
end
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb
|
||||
index cca0bbed..81b8249b 100644
|
||||
--- a/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb
|
||||
@@ -54,29 +54,29 @@ def add_callback(kind, callback_type, callback)
|
||||
end
|
||||
end
|
||||
|
||||
- describe '#use_before_filter' do
|
||||
- it_behaves_like 'CallbackMatcher', :before, :filter
|
||||
- end
|
||||
+ if action_pack_lt_5?
|
||||
+ describe '#use_before_filter' do
|
||||
+ it_behaves_like 'CallbackMatcher', :before, :filter
|
||||
+ end
|
||||
|
||||
- describe '#use_after_filter' do
|
||||
- it_behaves_like 'CallbackMatcher', :after, :filter
|
||||
- end
|
||||
+ describe '#use_after_filter' do
|
||||
+ it_behaves_like 'CallbackMatcher', :after, :filter
|
||||
+ end
|
||||
|
||||
- describe '#use_around_filter' do
|
||||
- it_behaves_like 'CallbackMatcher', :around, :filter
|
||||
+ describe '#use_around_filter' do
|
||||
+ it_behaves_like 'CallbackMatcher', :around, :filter
|
||||
+ end
|
||||
end
|
||||
|
||||
- if rails_4_x?
|
||||
- describe '#use_before_action' do
|
||||
- it_behaves_like 'CallbackMatcher', :before, :action
|
||||
- end
|
||||
+ describe '#use_before_action' do
|
||||
+ it_behaves_like 'CallbackMatcher', :before, :action
|
||||
+ end
|
||||
|
||||
- describe '#use_after_action' do
|
||||
- it_behaves_like 'CallbackMatcher', :after, :action
|
||||
- end
|
||||
+ describe '#use_after_action' do
|
||||
+ it_behaves_like 'CallbackMatcher', :after, :action
|
||||
+ end
|
||||
|
||||
- describe '#use_around_action' do
|
||||
- it_behaves_like 'CallbackMatcher', :around, :action
|
||||
- end
|
||||
+ describe '#use_around_action' do
|
||||
+ it_behaves_like 'CallbackMatcher', :around, :action
|
||||
end
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
index f53c82e6..3c374f3c 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'unit_spec_helper'
|
||||
|
||||
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :model do
|
||||
- if rails_lte_5?
|
||||
+ if action_pack_lt_5?
|
||||
context '#description' do
|
||||
context 'without a role' do
|
||||
it 'includes the attribute name' do
|
||||
@ -1,32 +0,0 @@
|
||||
From df04f8704abc3754c63c488433dac8c30573da6b Mon Sep 17 00:00:00 2001
|
||||
From: Michael de Silva <michael@mwdesilva.com>
|
||||
Date: Tue, 18 Oct 2016 05:32:20 +0530
|
||||
Subject: [PATCH] Fix #913 for Serialize Matcher error undefined method
|
||||
`cast_type' in Rails 5
|
||||
|
||||
This patch is based on the discussed held in issue #913, and a solution
|
||||
that I've proposed and others have confirmed as good to go :clap:.
|
||||
|
||||
Ref: https://github.com/thoughtbot/shoulda-matchers/issues/913#issuecomment-219187051
|
||||
---
|
||||
lib/shoulda/matchers/rails_shim.rb | 6 ++++--
|
||||
1 file changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
index 5159468c..471d9049 100644
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb
|
||||
@@ -23,9 +23,11 @@ def self.serialized_attributes_for(model)
|
||||
if defined?(::ActiveRecord::Type::Serialized)
|
||||
# Rails 5+
|
||||
model.columns.select do |column|
|
||||
- column.cast_type.is_a?(::ActiveRecord::Type::Serialized)
|
||||
+ model.type_for_attribute(column.name).is_a?(
|
||||
+ ::ActiveRecord::Type::Serialized,
|
||||
+ )
|
||||
end.inject({}) do |hash, column|
|
||||
- hash[column.name.to_s] = column.cast_type.coder
|
||||
+ hash[column.name.to_s] = model.type_for_attribute(column.name).coder
|
||||
hash
|
||||
end
|
||||
else
|
||||
@ -1,25 +0,0 @@
|
||||
From 3dbf2e5646d6b769c6392cdb71003d0f4aee2304 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 22:20:00 -0500
|
||||
Subject: [PATCH] Rails 5: Fix built-in-test custom models w/ attrs
|
||||
|
||||
When a model was built in a unit test and it was configured to have
|
||||
attributes, when those attributes are set later, the test would blow up
|
||||
because we were not using `write_attribute` correctly.
|
||||
---
|
||||
spec/support/unit/model_creators/basic.rb | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/spec/support/unit/model_creators/basic.rb b/spec/support/unit/model_creators/basic.rb
|
||||
index c2fded58..3791fd83 100644
|
||||
--- a/spec/support/unit/model_creators/basic.rb
|
||||
+++ b/spec/support/unit/model_creators/basic.rb
|
||||
@@ -80,7 +80,7 @@ def possibly_override_attribute_writer_method_for(model)
|
||||
)
|
||||
|
||||
if respond_to?(:write_attribute)
|
||||
- write_attribute(new_value)
|
||||
+ write_attribute(attribute_name, new_value)
|
||||
else
|
||||
super(new_value)
|
||||
end
|
||||
@ -1,108 +0,0 @@
|
||||
From 5e1e531b8b3fd35a526e73465bd4de64c22a1763 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 23:09:20 -0500
|
||||
Subject: [PATCH] Rails 5: Fix failing association matcher tests
|
||||
|
||||
---
|
||||
.../association_matchers/option_verifier.rb | 17 +++++++++++------
|
||||
.../unit/helpers/active_record_versions.rb | 8 ++++++++
|
||||
.../active_record/association_matcher_spec.rb | 11 +++++------
|
||||
3 files changed, 24 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb b/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb
|
||||
index 999feb7a..3ad93b76 100644
|
||||
--- a/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb
|
||||
+++ b/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb
|
||||
@@ -34,15 +34,16 @@ def correct_for_relation_clause?(name, expected_value)
|
||||
|
||||
def correct_for?(*args)
|
||||
expected_value, name, type = args.reverse
|
||||
+
|
||||
if expected_value.nil?
|
||||
true
|
||||
else
|
||||
- expected_value = type_cast(
|
||||
+ type_cast_expected_value = type_cast(
|
||||
type,
|
||||
expected_value_for(type, name, expected_value)
|
||||
)
|
||||
actual_value = type_cast(type, actual_value_for(name))
|
||||
- expected_value == actual_value
|
||||
+ type_cast_expected_value == actual_value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,10 +66,14 @@ def actual_value_for(name)
|
||||
|
||||
def type_cast(type, value)
|
||||
case type
|
||||
- when :string, :relation_clause then value.to_s
|
||||
- when :boolean then !!value
|
||||
- when :hash then Hash(value).stringify_keys
|
||||
- else value
|
||||
+ when :string, :relation_clause
|
||||
+ value.to_s
|
||||
+ when :boolean
|
||||
+ !!value
|
||||
+ when :hash
|
||||
+ Hash(value).stringify_keys
|
||||
+ else
|
||||
+ value
|
||||
end
|
||||
end
|
||||
|
||||
diff --git a/spec/support/unit/helpers/active_record_versions.rb b/spec/support/unit/helpers/active_record_versions.rb
|
||||
index 94e21f2e..d682b235 100644
|
||||
--- a/spec/support/unit/helpers/active_record_versions.rb
|
||||
+++ b/spec/support/unit/helpers/active_record_versions.rb
|
||||
@@ -20,5 +20,13 @@ def active_record_supports_has_secure_password?
|
||||
def active_record_supports_array_columns?
|
||||
active_record_version > 4.2
|
||||
end
|
||||
+
|
||||
+ def active_record_supports_relations?
|
||||
+ active_record_version >= 4
|
||||
+ end
|
||||
+
|
||||
+ def active_record_supports_more_dependent_options?
|
||||
+ active_record_version >= 4
|
||||
+ end
|
||||
end
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
index b51f9b4e..f383487a 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
@@ -1210,7 +1210,7 @@ def having_and_belonging_to_many_non_existent_class(model_name, assoc_name, opti
|
||||
def define_association_with_conditions(model, macro, name, conditions, other_options={})
|
||||
args = []
|
||||
options = {}
|
||||
- if Shoulda::Matchers::RailsShim.active_record_major_version == 4
|
||||
+ if active_record_supports_relations?
|
||||
args << proc { where(conditions) }
|
||||
else
|
||||
options[:conditions] = conditions
|
||||
@@ -1222,7 +1222,7 @@ def define_association_with_conditions(model, macro, name, conditions, other_opt
|
||||
def define_association_with_order(model, macro, name, order, other_options={})
|
||||
args = []
|
||||
options = {}
|
||||
- if Shoulda::Matchers::RailsShim.active_record_major_version == 4
|
||||
+ if active_record_supports_relations?
|
||||
args << proc { order(order) }
|
||||
else
|
||||
options[:order] = order
|
||||
@@ -1232,11 +1232,10 @@ def define_association_with_order(model, macro, name, order, other_options={})
|
||||
end
|
||||
|
||||
def dependent_options
|
||||
- case Rails.version
|
||||
- when /\A3/
|
||||
- [:destroy, :delete, :nullify, :restrict]
|
||||
- when /\A4/
|
||||
+ if active_record_supports_more_dependent_options?
|
||||
[:destroy, :delete, :nullify, :restrict_with_exception, :restrict_with_error]
|
||||
+ else
|
||||
+ [:destroy, :delete, :nullify, :restrict]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,61 +0,0 @@
|
||||
From 45ac5f5d754dae58708f4baef550e4986132d1ec Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 22:37:01 -0500
|
||||
Subject: [PATCH] Rails 5: Fix uniqueness tests to not use attr_accessible
|
||||
|
||||
---
|
||||
.../validate_uniqueness_of_matcher_spec.rb | 20 ++++++++++++++-----
|
||||
1 file changed, 15 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
|
||||
index 114537bc..b8a72af6 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
|
||||
@@ -1266,7 +1266,10 @@ def configure_validation_matcher(matcher)
|
||||
favoriteable_type: { type: :string, options: { null: false } }
|
||||
}
|
||||
favorite_model = define_model 'Favorite', favorite_columns do
|
||||
- attr_accessible :favoriteable
|
||||
+ if respond_to?(:attr_accessible)
|
||||
+ attr_accessible :favoriteable
|
||||
+ end
|
||||
+
|
||||
belongs_to :favoriteable, polymorphic: true
|
||||
validates :favoriteable, presence: true
|
||||
validates :favoriteable_id, uniqueness: { scope: :favoriteable_type }
|
||||
@@ -1291,7 +1294,10 @@ def configure_validation_matcher(matcher)
|
||||
favoriteable_type: { type: :string, options: { null: false } }
|
||||
}
|
||||
favorite_model = define_model 'Models::Favorite', favorite_columns do
|
||||
- attr_accessible :favoriteable
|
||||
+ if respond_to?(:attr_accessible)
|
||||
+ attr_accessible :favoriteable
|
||||
+ end
|
||||
+
|
||||
belongs_to :favoriteable, polymorphic: true
|
||||
validates :favoriteable, presence: true
|
||||
validates :favoriteable_id, uniqueness: { scope: :favoriteable_type }
|
||||
@@ -1547,8 +1553,10 @@ def define_model_validating_uniqueness(options = {}, &block)
|
||||
m.validates_uniqueness_of attribute_name,
|
||||
validation_options.merge(scope: scope_attribute_names)
|
||||
|
||||
- attributes.each do |attr|
|
||||
- m.attr_accessible(attr[:name])
|
||||
+ if m.respond_to?(:attr_accessible)
|
||||
+ attributes.each do |attr|
|
||||
+ m.attr_accessible(attr[:name])
|
||||
+ end
|
||||
end
|
||||
|
||||
block.call(m) if block
|
||||
@@ -1591,7 +1599,9 @@ def build_record_validating_scoped_uniqueness_with_enum(options = {})
|
||||
|
||||
def define_model_without_validation
|
||||
define_model(:example, attribute_name => :string) do |model|
|
||||
- model.attr_accessible(attribute_name)
|
||||
+ if model.respond_to?(:attr_accessible)
|
||||
+ model.attr_accessible(attribute_name)
|
||||
+ end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,117 +0,0 @@
|
||||
From 76e63b2638e1fcc84819bdca49d768a635346f5d Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Mon, 24 Jul 2017 22:24:12 -0500
|
||||
Subject: [PATCH] Rails 5: Fix validate_inclusion_of tests
|
||||
|
||||
---
|
||||
spec/support/unit/rails_application.rb | 14 ++++++++++
|
||||
.../validate_inclusion_of_matcher_spec.rb | 27 ++++++++++---------
|
||||
2 files changed, 28 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb
|
||||
index 3dc07aa9..8e3ae625 100644
|
||||
--- a/spec/support/unit/rails_application.rb
|
||||
+++ b/spec/support/unit/rails_application.rb
|
||||
@@ -2,6 +2,7 @@
|
||||
require_relative '../tests/command_runner'
|
||||
require_relative '../tests/database'
|
||||
require_relative '../tests/filesystem'
|
||||
+require_relative 'helpers/rails_versions'
|
||||
|
||||
require 'yaml'
|
||||
|
||||
@@ -75,6 +76,10 @@ def generate
|
||||
rails_new
|
||||
fix_available_locales_warning
|
||||
write_database_configuration
|
||||
+
|
||||
+ if bundle.version_of("rails") >= 5
|
||||
+ add_initializer_for_time_zone_aware_types
|
||||
+ end
|
||||
end
|
||||
|
||||
def rails_new
|
||||
@@ -97,6 +102,15 @@ def write_database_configuration
|
||||
YAML.dump(database.config.to_hash, fs.open('config/database.yml', 'w'))
|
||||
end
|
||||
|
||||
+ def add_initializer_for_time_zone_aware_types
|
||||
+ path = 'config/initializers/configure_time_zone_aware_types.rb'
|
||||
+ fs.write(path, <<~TEXT)
|
||||
+ Rails.application.configure do
|
||||
+ config.active_record.time_zone_aware_types = [:datetime, :time]
|
||||
+ end
|
||||
+ TEXT
|
||||
+ end
|
||||
+
|
||||
def load_environment
|
||||
require environment_file_path
|
||||
end
|
||||
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 d944c466..62a322d4 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
|
||||
@@ -192,20 +192,19 @@ def validation_matcher_scenario_args
|
||||
end
|
||||
|
||||
context 'against a time attribute' do
|
||||
- now = Time.now
|
||||
+ default_time = Time.zone.local(2000, 1, 1)
|
||||
|
||||
- define_method(:now) { now }
|
||||
+ define_method(:default_time) { default_time }
|
||||
|
||||
it_behaves_like 'it supports in_array',
|
||||
- possible_values: (1..5).map { |n| now + n },
|
||||
- reserved_outside_value: described_class::ARBITRARY_OUTSIDE_TIME
|
||||
+ possible_values: (1..3).map { |hour| default_time.change(hour: hour) }
|
||||
|
||||
it_behaves_like 'it supports in_range',
|
||||
- possible_values: (now .. now + 5)
|
||||
+ possible_values: (default_time.change(hour: 1) .. default_time.change(hour: 3))
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :time, value: now),
|
||||
+ options.merge(column_type: :time, value: default_time),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -215,7 +214,7 @@ def add_outside_value_to(values)
|
||||
end
|
||||
|
||||
def validation_matcher_scenario_args
|
||||
- super.deep_merge(column_type: :time, default_value: now)
|
||||
+ super.deep_merge(column_type: :time, default_value: default_time)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -434,7 +433,7 @@ def configure_validation_matcher(matcher)
|
||||
shared_examples_for 'it supports in_array' do |args|
|
||||
possible_values = args.fetch(:possible_values)
|
||||
zero = args[:zero]
|
||||
- reserved_outside_value = args.fetch(:reserved_outside_value)
|
||||
+ reserved_outside_value = args[:reserved_outside_value]
|
||||
|
||||
define_method(:valid_values) { args.fetch(:possible_values) }
|
||||
|
||||
@@ -466,12 +465,14 @@ def configure_validation_matcher(matcher)
|
||||
expect_not_to_match_on_values(builder, add_outside_value_to(possible_values))
|
||||
end
|
||||
|
||||
- it 'raises an error when valid and given value is our test outside value' do
|
||||
- error_class = Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
|
||||
- builder = build_object_allowing([reserved_outside_value])
|
||||
+ if reserved_outside_value
|
||||
+ it 'raises an error when valid and given value is our test outside value' do
|
||||
+ error_class = Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
|
||||
+ builder = build_object_allowing([reserved_outside_value])
|
||||
|
||||
- expect { expect_to_match_on_values(builder, [reserved_outside_value]) }.
|
||||
- to raise_error(error_class)
|
||||
+ expect { expect_to_match_on_values(builder, [reserved_outside_value]) }.
|
||||
+ to raise_error(error_class)
|
||||
+ end
|
||||
end
|
||||
|
||||
it_behaves_like 'it supports allow_nil', valid_values: possible_values
|
||||
@ -1,206 +0,0 @@
|
||||
From 84069646544ce701e6864458378323e1e3361140 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Sun, 17 Sep 2017 14:33:33 -0500
|
||||
Subject: [PATCH] Refactor RailsShim
|
||||
|
||||
* Satisfy Rubocop
|
||||
* Alphabetize methods
|
||||
* Use `class << self` instead of `self.` so that we can privatize one of
|
||||
the methods
|
||||
---
|
||||
lib/shoulda/matchers/rails_shim.rb | 172 +++++++++++++++++++----------
|
||||
1 file changed, 115 insertions(+), 57 deletions(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
index 471d9049..7aeab629 100644
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb
|
||||
@@ -2,71 +2,137 @@ module Shoulda
|
||||
module Matchers
|
||||
# @private
|
||||
class RailsShim
|
||||
- def self.verb_for_update
|
||||
- if action_pack_gte_4_1?
|
||||
- :patch
|
||||
- else
|
||||
- :put
|
||||
+ class << self
|
||||
+ def action_pack_gte_4_1?
|
||||
+ Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||
end
|
||||
- end
|
||||
|
||||
- def self.type_cast_default_for(model, column)
|
||||
- if model.respond_to?(:column_defaults)
|
||||
- # Rails 4.2
|
||||
- model.column_defaults[column.name]
|
||||
- else
|
||||
- column.default
|
||||
+ def action_pack_version
|
||||
+ Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||
+ end
|
||||
+
|
||||
+ def active_record_major_version
|
||||
+ ::ActiveRecord::VERSION::MAJOR
|
||||
end
|
||||
- end
|
||||
|
||||
- def self.serialized_attributes_for(model)
|
||||
- if defined?(::ActiveRecord::Type::Serialized)
|
||||
- # Rails 5+
|
||||
- model.columns.select do |column|
|
||||
- model.type_for_attribute(column.name).is_a?(
|
||||
- ::ActiveRecord::Type::Serialized,
|
||||
+ def generate_validation_message(
|
||||
+ record,
|
||||
+ attribute,
|
||||
+ type,
|
||||
+ model_name,
|
||||
+ options
|
||||
+ )
|
||||
+ if record && record.errors.respond_to?(:generate_message)
|
||||
+ record.errors.generate_message(attribute.to_sym, type, options)
|
||||
+ else
|
||||
+ simply_generate_validation_message(
|
||||
+ attribute,
|
||||
+ type,
|
||||
+ model_name,
|
||||
+ options,
|
||||
)
|
||||
- end.inject({}) do |hash, column|
|
||||
- hash[column.name.to_s] = model.type_for_attribute(column.name).coder
|
||||
- hash
|
||||
end
|
||||
- else
|
||||
- model.serialized_attributes
|
||||
+ rescue RangeError
|
||||
+ simply_generate_validation_message(
|
||||
+ attribute,
|
||||
+ type,
|
||||
+ model_name,
|
||||
+ options,
|
||||
+ )
|
||||
end
|
||||
- end
|
||||
|
||||
- def self.generate_validation_message(record, attribute, type, model_name, options)
|
||||
- if record && record.errors.respond_to?(:generate_message)
|
||||
- record.errors.generate_message(attribute.to_sym, type, options)
|
||||
- else
|
||||
- simply_generate_validation_message(attribute, type, model_name, options)
|
||||
+ def make_controller_request(context, verb, action, request_params)
|
||||
+ params =
|
||||
+ if active_record_major_version >= 5
|
||||
+ { params: request_params }
|
||||
+ else
|
||||
+ request_params
|
||||
+ end
|
||||
+
|
||||
+ context.__send__(verb, action, params)
|
||||
end
|
||||
- rescue RangeError
|
||||
- simply_generate_validation_message(attribute, type, model_name, options)
|
||||
- end
|
||||
|
||||
- def self.simply_generate_validation_message(attribute, type, model_name, options)
|
||||
- default_translation_keys = [
|
||||
- :"activerecord.errors.models.#{model_name}.#{type}",
|
||||
- :"activerecord.errors.messages.#{type}",
|
||||
- :"errors.attributes.#{attribute}.#{type}",
|
||||
- :"errors.messages.#{type}"
|
||||
- ]
|
||||
- primary_translation_key = :"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{type}"
|
||||
- translate_options = { default: default_translation_keys }.merge(options)
|
||||
- I18n.translate(primary_translation_key, translate_options)
|
||||
- end
|
||||
+ def serialized_attributes_for(model)
|
||||
+ if defined?(::ActiveRecord::Type::Serialized)
|
||||
+ # Rails 5+
|
||||
+ serialized_columns = model.columns.select do |column|
|
||||
+ model.type_for_attribute(column.name).is_a?(
|
||||
+ ::ActiveRecord::Type::Serialized,
|
||||
+ )
|
||||
+ end
|
||||
|
||||
- def self.active_record_major_version
|
||||
- ::ActiveRecord::VERSION::MAJOR
|
||||
- end
|
||||
+ serialized_columns.inject({}) do |hash, column|
|
||||
+ hash[column.name.to_s] = model.type_for_attribute(column.name).coder
|
||||
+ hash
|
||||
+ end
|
||||
+ else
|
||||
+ model.serialized_attributes
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def type_cast_default_for(model, column)
|
||||
+ if model.respond_to?(:column_defaults)
|
||||
+ # Rails 4.2
|
||||
+ model.column_defaults[column.name]
|
||||
+ else
|
||||
+ column.default
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def tables_and_views(connection)
|
||||
+ if active_record_major_version >= 5
|
||||
+ connection.data_sources
|
||||
+ else
|
||||
+ connection.tables
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ def verb_for_update
|
||||
+ if action_pack_gte_4_1?
|
||||
+ :patch
|
||||
+ else
|
||||
+ :put
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ private
|
||||
|
||||
- def self.action_pack_gte_4_1?
|
||||
- Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||
+ def simply_generate_validation_message(
|
||||
+ attribute,
|
||||
+ type,
|
||||
+ model_name,
|
||||
+ options
|
||||
+ )
|
||||
+ default_translation_keys = [
|
||||
+ :"activerecord.errors.models.#{model_name}.#{type}",
|
||||
+ :"activerecord.errors.messages.#{type}",
|
||||
+ :"errors.attributes.#{attribute}.#{type}",
|
||||
+ :"errors.messages.#{type}",
|
||||
+ ]
|
||||
+ primary_translation_key = [
|
||||
+ :activerecord,
|
||||
+ :errors,
|
||||
+ :models,
|
||||
+ model_name,
|
||||
+ :attributes,
|
||||
+ attribute,
|
||||
+ type,
|
||||
+ ]
|
||||
+ translate_options =
|
||||
+ { default: default_translation_keys }.merge(options)
|
||||
+ I18n.translate(primary_translation_key, translate_options)
|
||||
+ end
|
||||
end
|
||||
|
||||
- def self.action_pack_version
|
||||
- Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||
+ def self.make_controller_request(context, verb, action, request_params)
|
||||
+ params =
|
||||
+ if active_record_major_version >= 5
|
||||
+ { params: request_params }
|
||||
+ else
|
||||
+ request_params
|
||||
+ end
|
||||
+
|
||||
+ context.__send__(verb, action, params)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,183 +0,0 @@
|
||||
From ce9624b3c5a08b9134150e228440c771d95782b7 Mon Sep 17 00:00:00 2001
|
||||
From: Murtaza Gulamali <mygulamali@gmail.com>
|
||||
Date: Mon, 9 Jan 2017 12:31:46 +0000
|
||||
Subject: [PATCH] Scope request parameters according to Rails version
|
||||
|
||||
---
|
||||
.../action_controller/permit_matcher.rb | 7 +++-
|
||||
lib/shoulda/matchers/rails_shim.rb | 17 +++------
|
||||
.../unit/helpers/action_pack_versions.rb | 18 ++++++++++
|
||||
.../action_controller/permit_matcher_spec.rb | 36 ++++++++++++++++---
|
||||
spec/unit_spec_helper.rb | 1 +
|
||||
5 files changed, 62 insertions(+), 17 deletions(-)
|
||||
create mode 100644 spec/support/unit/helpers/action_pack_versions.rb
|
||||
|
||||
diff --git a/lib/shoulda/matchers/action_controller/permit_matcher.rb b/lib/shoulda/matchers/action_controller/permit_matcher.rb
|
||||
index 8e8b5c48..ef184aaf 100644
|
||||
--- a/lib/shoulda/matchers/action_controller/permit_matcher.rb
|
||||
+++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb
|
||||
@@ -250,7 +250,12 @@ def matches?(controller)
|
||||
parameters_double_registry.register
|
||||
|
||||
Doublespeak.with_doubles_activated do
|
||||
- context.__send__(verb, action, request_params)
|
||||
+ Shoulda::Matchers::RailsShim.make_controller_request(
|
||||
+ context,
|
||||
+ verb,
|
||||
+ action,
|
||||
+ request_params,
|
||||
+ )
|
||||
end
|
||||
|
||||
unpermitted_parameter_names.empty?
|
||||
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
index 7aeab629..1fea4eb1 100644
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb
|
||||
@@ -7,6 +7,10 @@ def action_pack_gte_4_1?
|
||||
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||
end
|
||||
|
||||
+ def action_pack_gte_5?
|
||||
+ Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||
+ end
|
||||
+
|
||||
def action_pack_version
|
||||
Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||
end
|
||||
@@ -43,7 +47,7 @@ def generate_validation_message(
|
||||
|
||||
def make_controller_request(context, verb, action, request_params)
|
||||
params =
|
||||
- if active_record_major_version >= 5
|
||||
+ if action_pack_gte_5?
|
||||
{ params: request_params }
|
||||
else
|
||||
request_params
|
||||
@@ -123,17 +127,6 @@ def simply_generate_validation_message(
|
||||
I18n.translate(primary_translation_key, translate_options)
|
||||
end
|
||||
end
|
||||
-
|
||||
- def self.make_controller_request(context, verb, action, request_params)
|
||||
- params =
|
||||
- if active_record_major_version >= 5
|
||||
- { params: request_params }
|
||||
- else
|
||||
- request_params
|
||||
- end
|
||||
-
|
||||
- context.__send__(verb, action, params)
|
||||
- end
|
||||
end
|
||||
end
|
||||
end
|
||||
diff --git a/spec/support/unit/helpers/action_pack_versions.rb b/spec/support/unit/helpers/action_pack_versions.rb
|
||||
new file mode 100644
|
||||
index 00000000..86606f7b
|
||||
--- /dev/null
|
||||
+++ b/spec/support/unit/helpers/action_pack_versions.rb
|
||||
@@ -0,0 +1,18 @@
|
||||
+module UnitTests
|
||||
+ module ActionPackVersions
|
||||
+ extend self
|
||||
+
|
||||
+ def self.configure_example_group(example_group)
|
||||
+ example_group.include(self)
|
||||
+ example_group.extend(self)
|
||||
+ end
|
||||
+
|
||||
+ def action_pack_gte_5?
|
||||
+ action_pack_version =~ '>= 5'
|
||||
+ end
|
||||
+
|
||||
+ def action_pack_version
|
||||
+ Tests::Version.new(ActionPack::VERSION::STRING)
|
||||
+ end
|
||||
+ end
|
||||
+end
|
||||
diff --git a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
index 1a1a5a55..b8857df9 100644
|
||||
--- a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
@@ -498,7 +498,12 @@ def params_with_conditional_require(params, *filters)
|
||||
|
||||
matcher.matches?(controller)
|
||||
|
||||
- expect(context).to have_received(:post).with(:create, {})
|
||||
+ expect_to_have_made_controller_request(
|
||||
+ verb: :post,
|
||||
+ action: :create,
|
||||
+ params: {},
|
||||
+ context: context,
|
||||
+ )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -511,7 +516,12 @@ def params_with_conditional_require(params, *filters)
|
||||
|
||||
matcher.matches?(controller)
|
||||
|
||||
- expect(context).to have_received(:patch).with(:update, {})
|
||||
+ expect_to_have_made_controller_request(
|
||||
+ verb: :patch,
|
||||
+ action: :update,
|
||||
+ params: {},
|
||||
+ context: context,
|
||||
+ )
|
||||
end
|
||||
else
|
||||
it 'PUTs to the controller' do
|
||||
@@ -521,7 +531,12 @@ def params_with_conditional_require(params, *filters)
|
||||
|
||||
matcher.matches?(controller)
|
||||
|
||||
- expect(context).to have_received(:put).with(:update, {})
|
||||
+ expect_to_have_made_controller_request(
|
||||
+ verb: :put,
|
||||
+ action: :update,
|
||||
+ params: {},
|
||||
+ context: context,
|
||||
+ )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -536,7 +551,12 @@ def params_with_conditional_require(params, *filters)
|
||||
|
||||
matcher.matches?(controller)
|
||||
|
||||
- expect(context).to have_received(:delete).with(:hide, {})
|
||||
+ expect_to_have_made_controller_request(
|
||||
+ verb: :delete,
|
||||
+ action: :hide,
|
||||
+ params: {},
|
||||
+ context: context,
|
||||
+ )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -598,4 +618,12 @@ def define_controller_raising_exception
|
||||
def build_context
|
||||
double('context', post: nil, put: nil, patch: nil, delete: nil)
|
||||
end
|
||||
+
|
||||
+ def expect_to_have_made_controller_request(context:, verb:, action:, params:)
|
||||
+ if action_pack_gte_5?
|
||||
+ expect(context).to have_received(verb).with(action, params: params)
|
||||
+ else
|
||||
+ expect(context).to have_received(verb).with(action, params)
|
||||
+ end
|
||||
+ end
|
||||
end
|
||||
diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb
|
||||
index ba99e6b0..dfbe21d6 100644
|
||||
--- a/spec/unit_spec_helper.rb
|
||||
+++ b/spec/unit_spec_helper.rb
|
||||
@@ -10,6 +10,7 @@
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
+ UnitTests::ActionPackVersions.configure_example_group(config)
|
||||
UnitTests::ActiveModelHelpers.configure_example_group(config)
|
||||
UnitTests::ActiveModelVersions.configure_example_group(config)
|
||||
UnitTests::ActiveResourceBuilder.configure_example_group(config)
|
||||
@ -1,91 +0,0 @@
|
||||
From b310986f9a3b7547c98e54db97600f8128e28ff5 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Thu, 28 Sep 2017 00:50:32 -0500
|
||||
Subject: [PATCH] Use correct migration class in acceptance tests
|
||||
|
||||
In Rails 5.0, migration classes changed so that they were versioned:
|
||||
instead of inheriting from `ActiveRecord::Migration`, you inherited from
|
||||
`ActiveRecord::Migration[5.0]`. The old way wasn't removed, however --
|
||||
that is, until Rails 5.1. Hence, our acceptance tests that use the old
|
||||
style no longer work under the 5.1 Appraisal.
|
||||
---
|
||||
.../multiple_libraries_integration_spec.rb | 2 +-
|
||||
spec/acceptance/rails_integration_spec.rb | 2 +-
|
||||
spec/support/acceptance/helpers.rb | 2 ++
|
||||
.../helpers/rails_migration_helpers.rb | 21 +++++++++++++++++++
|
||||
4 files changed, 25 insertions(+), 2 deletions(-)
|
||||
create mode 100644 spec/support/acceptance/helpers/rails_migration_helpers.rb
|
||||
|
||||
diff --git a/spec/acceptance/multiple_libraries_integration_spec.rb b/spec/acceptance/multiple_libraries_integration_spec.rb
|
||||
index d03babac..376e1291 100644
|
||||
--- a/spec/acceptance/multiple_libraries_integration_spec.rb
|
||||
+++ b/spec/acceptance/multiple_libraries_integration_spec.rb
|
||||
@@ -5,7 +5,7 @@
|
||||
create_rails_application
|
||||
|
||||
write_file 'db/migrate/1_create_users.rb', <<-FILE
|
||||
- class CreateUsers < ActiveRecord::Migration
|
||||
+ class CreateUsers < #{migration_class_name}
|
||||
def self.up
|
||||
create_table :users do |t|
|
||||
t.string :name
|
||||
diff --git a/spec/acceptance/rails_integration_spec.rb b/spec/acceptance/rails_integration_spec.rb
|
||||
index f18a6725..79d6e197 100644
|
||||
--- a/spec/acceptance/rails_integration_spec.rb
|
||||
+++ b/spec/acceptance/rails_integration_spec.rb
|
||||
@@ -5,7 +5,7 @@
|
||||
create_rails_application
|
||||
|
||||
write_file 'db/migrate/1_create_users.rb', <<-FILE
|
||||
- class CreateUsers < ActiveRecord::Migration
|
||||
+ class CreateUsers < #{migration_class_name}
|
||||
def self.up
|
||||
create_table :users do |t|
|
||||
t.string :name
|
||||
diff --git a/spec/support/acceptance/helpers.rb b/spec/support/acceptance/helpers.rb
|
||||
index 2b5160d6..c09a1dfa 100644
|
||||
--- a/spec/support/acceptance/helpers.rb
|
||||
+++ b/spec/support/acceptance/helpers.rb
|
||||
@@ -3,6 +3,7 @@
|
||||
require_relative 'helpers/command_helpers'
|
||||
require_relative 'helpers/gem_helpers'
|
||||
require_relative 'helpers/n_unit_helpers'
|
||||
+require_relative 'helpers/rails_migration_helpers'
|
||||
require_relative 'helpers/rails_version_helpers'
|
||||
require_relative 'helpers/rspec_helpers'
|
||||
require_relative 'helpers/ruby_version_helpers'
|
||||
@@ -23,6 +24,7 @@ def self.configure_example_group(example_group)
|
||||
include CommandHelpers
|
||||
include GemHelpers
|
||||
include NUnitHelpers
|
||||
+ include RailsMigrationHelpers
|
||||
include RailsVersionHelpers
|
||||
include RspecHelpers
|
||||
include RubyVersionHelpers
|
||||
diff --git a/spec/support/acceptance/helpers/rails_migration_helpers.rb b/spec/support/acceptance/helpers/rails_migration_helpers.rb
|
||||
new file mode 100644
|
||||
index 00000000..211bc01b
|
||||
--- /dev/null
|
||||
+++ b/spec/support/acceptance/helpers/rails_migration_helpers.rb
|
||||
@@ -0,0 +1,21 @@
|
||||
+require_relative 'gem_helpers'
|
||||
+
|
||||
+module AcceptanceTests
|
||||
+ module RailsMigrationHelpers
|
||||
+ include RailsVersionHelpers
|
||||
+
|
||||
+ def migration_class_name
|
||||
+ if rails_version >= 5
|
||||
+ "ActiveRecord::Migration[#{rails_version_for_migration}]"
|
||||
+ else
|
||||
+ 'ActiveRecord::Migration'
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ private
|
||||
+
|
||||
+ def rails_version_for_migration
|
||||
+ rails_version.to_s.split('.')[0..1].join('.')
|
||||
+ end
|
||||
+ end
|
||||
+end
|
||||
@ -1,38 +0,0 @@
|
||||
From 158839b3a60f0c2a1f243f6e65ec620be55982ee Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Tue, 26 Sep 2017 17:19:44 -0500
|
||||
Subject: [PATCH] Use `head` instead of `render: nothing` in tests
|
||||
|
||||
`render nothing: true` was removed from Rails 5.1 and has no effect
|
||||
anymore -- it was replaced with `head`.
|
||||
---
|
||||
spec/acceptance/rails_integration_spec.rb | 2 +-
|
||||
.../shoulda/matchers/action_controller/permit_matcher_spec.rb | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/spec/acceptance/rails_integration_spec.rb b/spec/acceptance/rails_integration_spec.rb
|
||||
index 8755b3a8..f18a6725 100644
|
||||
--- a/spec/acceptance/rails_integration_spec.rb
|
||||
+++ b/spec/acceptance/rails_integration_spec.rb
|
||||
@@ -26,7 +26,7 @@ class User < ActiveRecord::Base
|
||||
class ExamplesController < ApplicationController
|
||||
def show
|
||||
@example = 'hello'
|
||||
- render nothing: true
|
||||
+ head :ok
|
||||
end
|
||||
end
|
||||
FILE
|
||||
diff --git a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
index b8857df9..509a9bbd 100644
|
||||
--- a/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb
|
||||
@@ -586,7 +586,7 @@ def define_controller_with_strong_parameters(options = {}, &action_body)
|
||||
end
|
||||
end
|
||||
|
||||
- render nothing: true
|
||||
+ head :ok
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
From 26522c6b788d96c20027d794178c83f4b6a630b7 Mon Sep 17 00:00:00 2001
|
||||
From: Elliot Winkler <elliot.winkler@gmail.com>
|
||||
Date: Sat, 3 Sep 2016 21:33:50 -0600
|
||||
Subject: [PATCH] capture, silence_stream, and silence_stderr were removed in
|
||||
Rails 5
|
||||
|
||||
---
|
||||
spec/support/unit/capture.rb | 12 +++++++++---
|
||||
1 file changed, 9 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/spec/support/unit/capture.rb b/spec/support/unit/capture.rb
|
||||
index ddacfbd8..a5879954 100644
|
||||
--- a/spec/support/unit/capture.rb
|
||||
+++ b/spec/support/unit/capture.rb
|
||||
@@ -2,7 +2,9 @@ module Kernel
|
||||
# #capture, #silence_stream, and #silence_stderr are deprecated after Rails
|
||||
# 4.2 and will be removed in 5.0, so just override them completely here
|
||||
|
||||
- undef_method :capture
|
||||
+ if method_defined?(:capture)
|
||||
+ undef_method :capture
|
||||
+ end
|
||||
|
||||
def capture(stream)
|
||||
stream = stream.to_s
|
||||
@@ -20,7 +22,9 @@ def capture(stream)
|
||||
stream_io.reopen(origin_stream)
|
||||
end
|
||||
|
||||
- undef_method :silence_stream
|
||||
+ if method_defined?(:silence_stream)
|
||||
+ undef_method :silence_stream
|
||||
+ end
|
||||
|
||||
def silence_stream(stream)
|
||||
old_stream = stream.dup
|
||||
@@ -32,7 +36,9 @@ def silence_stream(stream)
|
||||
old_stream.close
|
||||
end
|
||||
|
||||
- undef_method :silence_stderr
|
||||
+ if method_defined?(:silence_stderr)
|
||||
+ undef_method :silence_stderr
|
||||
+ end
|
||||
|
||||
def silence_stderr
|
||||
silence_stream(STDERR) { yield }
|
||||
@ -0,0 +1,26 @@
|
||||
From 532bdf51581c75060f45e0d7ab52423c09b4eea1 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Mon, 8 Feb 2021 15:36:20 +0100
|
||||
Subject: [PATCH] Accept (double)quotes when removing bootsnap.
|
||||
|
||||
https://github.com/rails/rails/commit/3e0cdbeaf4e769ebd356a2c06dfae13d22283b7c
|
||||
---
|
||||
spec/support/unit/rails_application.rb | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb
|
||||
index 2f5d5dc7..3b4b02b0 100644
|
||||
--- a/spec/support/unit/rails_application.rb
|
||||
+++ b/spec/support/unit/rails_application.rb
|
||||
@@ -130,7 +130,7 @@ end
|
||||
# Zeus anyhow)
|
||||
fs.comment_lines_matching(
|
||||
'config/boot.rb',
|
||||
- %r{\Arequire 'bootsnap/setup'},
|
||||
+ %r{\Arequire ['"]bootsnap/setup['"]},
|
||||
)
|
||||
end
|
||||
|
||||
--
|
||||
2.30.0
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
From 84aff7aa2d9e5edaef43e980592e96d0fd03ce7c Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Tue, 9 Feb 2021 19:06:19 +0100
|
||||
Subject: [PATCH] Disable CPK test cases due to Rails 6.1 compatibility.
|
||||
|
||||
Relates #1396.
|
||||
---
|
||||
.../matchers/active_record/association_matcher_spec.rb | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
index 290deb0b..1e1d2444 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
@@ -1446,6 +1446,8 @@ Expected Parent to have a has_many association called children through conceptio
|
||||
end
|
||||
|
||||
it 'rejects an association with a valid :class_name and :foreign_key option (CPK), but no columns' do
|
||||
+ pending "Rails 6.1 compatibilty"
|
||||
+
|
||||
define_model :person_detail
|
||||
define_model :person do
|
||||
has_one :detail, class_name: 'PersonDetail', foreign_key: %i[company_id person_detail_id]
|
||||
@@ -1461,6 +1463,8 @@ Expected Parent to have a has_many association called children through conceptio
|
||||
end
|
||||
|
||||
it 'accepts an association with a valid :class_name and :foreign_key option (CPK)' do
|
||||
+ pending "Rails 6.1 compatibility"
|
||||
+
|
||||
define_model :person_detail, company_id: :integer, person_detail_id: :integer
|
||||
define_model :person do
|
||||
has_one :detail, class_name: 'PersonDetail', foreign_key: %i[company_id person_detail_id]
|
||||
--
|
||||
2.30.0
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
From ee069af88dd32821c83126a73bc426a30237972c Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Tue, 9 Feb 2021 16:13:41 +0100
|
||||
Subject: [PATCH] Disable test failing due to changes in Rails 6.1.
|
||||
|
||||
---
|
||||
spec/unit/shoulda/matchers/active_model/helpers_spec.rb | 2 ++
|
||||
.../shoulda/matchers/active_record/association_matcher_spec.rb | 2 ++
|
||||
2 files changed, 4 insertions(+)
|
||||
|
||||
diff --git a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb
|
||||
index 8246997c..1f508e3f 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_model/helpers_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_model/helpers_spec.rb
|
||||
@@ -81,6 +81,8 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
|
||||
|
||||
context 'if ActiveModel::Errors#generate_message behavior has changed' do
|
||||
it 'provides the right error message for validate_presence_of' do
|
||||
+ pending "Rails 6.1 change?"
|
||||
+
|
||||
stub_active_model_message_generation(
|
||||
type: :blank,
|
||||
message: 'Behavior has diverged.',
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
index 2ad3c1d1..290deb0b 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
@@ -983,6 +983,8 @@ Expected Parent to have a has_many association called children through conceptio
|
||||
end
|
||||
|
||||
it 'accepts an association with a valid :source option' do
|
||||
+ pending "Rails 6.1 require :through option"
|
||||
+
|
||||
expect(having_many_children(source: :user)).
|
||||
to have_many(:children).source(:user)
|
||||
end
|
||||
--
|
||||
2.30.0
|
||||
|
||||
@ -0,0 +1,337 @@
|
||||
From 8a4efb6a6da140a001144fffc7042f15f601c991 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Tue, 9 Feb 2021 16:09:45 +0100
|
||||
Subject: [PATCH] Fix keyword arguments for Ruby 3.0 compatibility.
|
||||
|
||||
---
|
||||
.../unit/active_record/create_table.rb | 2 +-
|
||||
spec/support/unit/helpers/model_builder.rb | 24 +++++++--------
|
||||
.../validate_inclusion_of_matcher_spec.rb | 30 +++++++++----------
|
||||
.../active_record/association_matcher_spec.rb | 20 ++++++-------
|
||||
.../have_db_column_matcher_spec.rb | 2 +-
|
||||
.../have_db_index_matcher_spec.rb | 2 +-
|
||||
6 files changed, 40 insertions(+), 40 deletions(-)
|
||||
|
||||
diff --git a/spec/support/unit/active_record/create_table.rb b/spec/support/unit/active_record/create_table.rb
|
||||
index a80ac444..e12a409c 100644
|
||||
--- a/spec/support/unit/active_record/create_table.rb
|
||||
+++ b/spec/support/unit/active_record/create_table.rb
|
||||
@@ -125,7 +125,7 @@ module UnitTests
|
||||
)
|
||||
end
|
||||
|
||||
- table.column(column_name, column_type, column_options)
|
||||
+ table.column(column_name, column_type, **column_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
diff --git a/spec/support/unit/helpers/model_builder.rb b/spec/support/unit/helpers/model_builder.rb
|
||||
index 4a7fae83..036ae9a0 100644
|
||||
--- a/spec/support/unit/helpers/model_builder.rb
|
||||
+++ b/spec/support/unit/helpers/model_builder.rb
|
||||
@@ -2,24 +2,24 @@ require_relative 'class_builder'
|
||||
|
||||
module UnitTests
|
||||
module ModelBuilder
|
||||
- def create_table(*args, &block)
|
||||
- ModelBuilder.create_table(*args, &block)
|
||||
+ def create_table(*args, **options, &block)
|
||||
+ ModelBuilder.create_table(*args, **options, &block)
|
||||
end
|
||||
|
||||
- def define_model(*args, &block)
|
||||
- ModelBuilder.define_model(*args, &block)
|
||||
+ def define_model(*args, **options, &block)
|
||||
+ ModelBuilder.define_model(*args, **options, &block)
|
||||
end
|
||||
|
||||
- def define_model_instance(*args, &block)
|
||||
- define_model(*args, &block).new
|
||||
+ def define_model_instance(*args, **options, &block)
|
||||
+ define_model(*args, **options, &block).new
|
||||
end
|
||||
|
||||
- def define_model_class(*args, &block)
|
||||
- ModelBuilder.define_model_class(*args, &block)
|
||||
+ def define_model_class(*args, **options, &block)
|
||||
+ ModelBuilder.define_model_class(*args, **options, &block)
|
||||
end
|
||||
|
||||
- def define_active_model_class(*args, &block)
|
||||
- ModelBuilder.define_active_model_class(*args, &block)
|
||||
+ def define_active_model_class(*args, **options, &block)
|
||||
+ ModelBuilder.define_active_model_class(*args, **options, &block)
|
||||
end
|
||||
|
||||
class << self
|
||||
@@ -38,13 +38,13 @@ module UnitTests
|
||||
defined_models.clear
|
||||
end
|
||||
|
||||
- def create_table(table_name, options = {}, &block)
|
||||
+ def create_table(table_name, **options, &block)
|
||||
connection =
|
||||
options.delete(:connection) || DevelopmentRecord.connection
|
||||
|
||||
begin
|
||||
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
||||
- connection.create_table(table_name, options, &block)
|
||||
+ connection.create_table(table_name, **options, &block)
|
||||
created_tables << table_name
|
||||
connection
|
||||
rescue StandardError => e
|
||||
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 733d28ee..811ff456 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
|
||||
@@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :integer, value: 1),
|
||||
+ **options.merge(column_type: :integer, value: 1),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -45,7 +45,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(
|
||||
+ **options.merge(
|
||||
column_type: :integer,
|
||||
column_options: { limit: 2 },
|
||||
value: 1,
|
||||
@@ -71,7 +71,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :float, value: 1.0),
|
||||
+ **options.merge(column_type: :float, value: 1.0),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -99,7 +99,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :decimal, value: BigDecimal('1.0')),
|
||||
+ **options.merge(column_type: :decimal, value: BigDecimal('1.0')),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -130,7 +130,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :date, value: today),
|
||||
+ **options.merge(column_type: :date, value: today),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -158,7 +158,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :datetime, value: now),
|
||||
+ **options.merge(column_type: :datetime, value: now),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -186,7 +186,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :time, value: default_time),
|
||||
+ **options.merge(column_type: :time, value: default_time),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -207,7 +207,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :string),
|
||||
+ **options.merge(column_type: :string),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -798,7 +798,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
define_method :build_object do |options = {}, &block|
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :timestamp, value: now),
|
||||
+ **options.merge(column_type: :timestamp, value: now),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -842,7 +842,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
|
||||
def build_object(**options, &block)
|
||||
super(
|
||||
- options.merge(column_options: { null: true }, value: true),
|
||||
+ **options.merge(column_options: { null: true }, value: true),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -863,13 +863,13 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
end
|
||||
|
||||
def build_object(**options, &block)
|
||||
- super(options.merge(column_options: { null: false }), &block)
|
||||
+ super(**options.merge(column_options: { null: false }), &block)
|
||||
end
|
||||
end
|
||||
|
||||
def build_object(**options, &block)
|
||||
build_object_with_generic_attribute(
|
||||
- options.merge(column_type: :boolean),
|
||||
+ **options.merge(column_type: :boolean),
|
||||
&block
|
||||
)
|
||||
end
|
||||
@@ -896,7 +896,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
include_context 'against a boolean attribute for true and false'
|
||||
|
||||
def build_object(**options, &block)
|
||||
- build_object_with_generic_attribute(options.merge(value: true), &block)
|
||||
+ build_object_with_generic_attribute(**options.merge(value: true), &block)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -904,7 +904,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
include_context 'against a boolean attribute for true and false'
|
||||
|
||||
def build_object(**options, &block)
|
||||
- build_object_with_generic_attribute(options.merge(value: false), &block)
|
||||
+ build_object_with_generic_attribute(**options.merge(value: false), &block)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1010,7 +1010,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :mode
|
||||
column_options: column_options,
|
||||
}.compact
|
||||
|
||||
- define_simple_model(model_options) do |model|
|
||||
+ define_simple_model(**model_options) do |model|
|
||||
if validation_options
|
||||
model.validates_inclusion_of(attribute_name, validation_options)
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
index 1136fdf6..2ad3c1d1 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb
|
||||
@@ -809,10 +809,10 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher, type: :model do
|
||||
parent_options = {},
|
||||
&block
|
||||
)
|
||||
- define_model(:parent, parent_options)
|
||||
+ define_model(:parent, **parent_options)
|
||||
|
||||
define_model :child, parent_id: :integer do
|
||||
- belongs_to :parent, options
|
||||
+ belongs_to :parent, **options
|
||||
|
||||
if block
|
||||
class_eval(&block)
|
||||
@@ -841,7 +841,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher, type: :model do
|
||||
|
||||
def belonging_to_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name, "#{assoc_name}_id" => :integer do
|
||||
- belongs_to assoc_name, options
|
||||
+ belongs_to assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -1256,14 +1256,14 @@ Expected Parent to have a has_many association called children through conceptio
|
||||
order = options.delete(:order)
|
||||
define_association_with_order(model, :has_many, :children, order, options)
|
||||
else
|
||||
- model.has_many :children, options
|
||||
+ model.has_many :children, nil, **options
|
||||
end
|
||||
end.new
|
||||
end
|
||||
|
||||
def having_many_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_many assoc_name, options
|
||||
+ has_many assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -1596,14 +1596,14 @@ Expected Parent to have a has_many association called children through conceptio
|
||||
order = options.delete(:order)
|
||||
define_association_with_order(model, :has_one, :detail, order, options)
|
||||
else
|
||||
- model.has_one :detail, options
|
||||
+ model.has_one :detail, **options
|
||||
end
|
||||
end.new
|
||||
end
|
||||
|
||||
def having_one_non_existent(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_one assoc_name, options
|
||||
+ has_one assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -2226,7 +2226,7 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
||||
|
||||
def having_and_belonging_to_many_non_existent_class(model_name, assoc_name, options = {})
|
||||
define_model model_name do
|
||||
- has_and_belongs_to_many assoc_name, options
|
||||
+ has_and_belongs_to_many assoc_name, **options
|
||||
end.new
|
||||
end
|
||||
end
|
||||
@@ -2238,8 +2238,8 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
||||
args << proc { where(conditions) }
|
||||
else
|
||||
options[:conditions] = conditions
|
||||
+ args << options
|
||||
end
|
||||
- args << options
|
||||
model.__send__(macro, name, *args)
|
||||
end
|
||||
|
||||
@@ -2250,8 +2250,8 @@ Expected Person to have a has_and_belongs_to_many association called relatives (
|
||||
args << proc { order(order) }
|
||||
else
|
||||
options[:order] = order
|
||||
+ args << options
|
||||
end
|
||||
- args << options
|
||||
model.__send__(macro, name, *args)
|
||||
end
|
||||
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
|
||||
index 8d56315f..47ae006e 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
|
||||
@@ -112,7 +112,7 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher, type: :model do
|
||||
|
||||
def with_table(column_name, column_type, options)
|
||||
create_table 'employees' do |table|
|
||||
- table.__send__(column_type, column_name, options)
|
||||
+ table.__send__(column_type, column_name, **options)
|
||||
end
|
||||
define_model_class('Employee').new
|
||||
end
|
||||
diff --git a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
|
||||
index 7a0ffdea..54fe4593 100644
|
||||
--- a/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
|
||||
+++ b/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
|
||||
@@ -494,7 +494,7 @@ does not.
|
||||
columns,
|
||||
parent_class: parent_class,
|
||||
customize_table: -> (table) {
|
||||
- table.index(column_name_or_names, index_options)
|
||||
+ table.index(column_name_or_names, **index_options)
|
||||
},
|
||||
)
|
||||
model.new
|
||||
--
|
||||
2.30.0
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
From 937256be204487727727cecc18519d85b91201d5 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Ga=C3=ABtan=20Masson?= <im.gaetanmasson@gmail.com>
|
||||
Date: Thu, 28 Jan 2021 20:25:05 +0100
|
||||
Subject: [PATCH] Handle argument delegation for Ruby 3
|
||||
|
||||
---
|
||||
lib/shoulda/matchers/rails_shim.rb | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
||||
index b426b575a..6cecb4b0a 100644
|
||||
--- a/lib/shoulda/matchers/rails_shim.rb
|
||||
+++ b/lib/shoulda/matchers/rails_shim.rb
|
||||
@@ -65,7 +65,7 @@ def make_controller_request(context, verb, action, request_params)
|
||||
request_params
|
||||
end
|
||||
|
||||
- context.__send__(verb, action, params)
|
||||
+ context.__send__(verb, action, **params)
|
||||
end
|
||||
|
||||
def serialized_attributes_for(model)
|
||||
@ -0,0 +1,24 @@
|
||||
From d783d864251f1ab59fad22ec56b97dc2c4f30276 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
||||
Date: Tue, 9 Feb 2021 17:32:31 +0100
|
||||
Subject: [PATCH] Remove rack-mini-profiler dependency.
|
||||
|
||||
---
|
||||
spec/support/acceptance/helpers/step_helpers.rb | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb
|
||||
index ea6f5b7f..3fe7062a 100644
|
||||
--- a/spec/support/acceptance/helpers/step_helpers.rb
|
||||
+++ b/spec/support/acceptance/helpers/step_helpers.rb
|
||||
@@ -76,6 +76,7 @@ module AcceptanceTests
|
||||
bundle.remove_gem 'debugger'
|
||||
bundle.remove_gem 'byebug'
|
||||
bundle.remove_gem 'web-console'
|
||||
+ bundle.remove_gem 'rack-mini-profiler'
|
||||
bundle.add_gem 'pg'
|
||||
end
|
||||
|
||||
--
|
||||
2.30.0
|
||||
|
||||
@ -1,38 +1,25 @@
|
||||
%global gem_name shoulda-matchers
|
||||
Name: rubygem-%{gem_name}
|
||||
Version: 3.1.2
|
||||
Release: 2
|
||||
Version: 4.5.1
|
||||
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/shoulda-matchers-%{version}.gem
|
||||
Patch0: rubygem-shoulda-matchers-3.1.2-capture-silence_stream-and-silence_stderr-were-removed-in-Rails-5.patch
|
||||
Patch1: rubygem-shoulda-matchers-3.1.2-Don-t-protect-attributes-under-Rails-5.patch
|
||||
Patch2: rubygem-shoulda-matchers-3.1.2-Fix-uniqueness-tests-to-not-use-attr_accessible.patch
|
||||
Patch3: rubygem-shoulda-matchers-3.1.2-Deprecation-for-ruby24-removed.patch
|
||||
Patch5: rubygem-shoulda-matchers-3.1.2-Fix-Serialize-Matcher-error-undefined-method-cast_type.patch
|
||||
Patch6: rubygem-shoulda-matchers-3.1.2-Refactor-RailsShim.patch
|
||||
Patch7: rubygem-shoulda-matchers-3.1.2-Scope-request-parameters-according-to-Rails-version.patch
|
||||
Patch8: rubygem-shoulda-matchers-3.1.2-Disable-allow_mass_assignment_of-tests-under-Rails-5.patch
|
||||
Patch9: rubygem-shoulda-matchers-3.1.2-Drop-legacy-callback-matchers-under-Rails-5.patch
|
||||
Patch10: rubygem-shoulda-matchers-3.1.2-Use-head-instead-of-render-nothing-in-tests.patch
|
||||
Patch11: rubygem-shoulda-matchers-3.1.2-Fix-built-in-test-custom-models-with-attrs.patch
|
||||
Patch12: rubygem-shoulda-matchers-3.1.2-Fix-failing-association-matcher-tests.patch
|
||||
Patch13: rubygem-shoulda-matchers-3.1.2-Fix-validate_inclusion_of-tests.patch
|
||||
Patch14: rubygem-shoulda-matchers-3.1.2-Use-correct-migration-class-in-acceptance-tests.patch
|
||||
Patch15: rubygem-shoulda-matchers-3.1.2-Define-respond_to_missing-on-ObjectDouble.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/commit/0c07bfb039b0fe9f9863e885ee3885e48f3b39d9
|
||||
Patch16: fix-bigdecimal-deprecated.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/pull/1427/commits/740930ee28dab97d14542d1ea7ad60e22b602ab3
|
||||
Patch17: Fix-warning-Using-the-last-argument-as-keyword-parameters-is-deprecated.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/pull/1406/commits/937256be204487727727cecc18519d85b91201d5
|
||||
Patch18: Handle-argument-delegation-for-ruby-3.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/pull/1406/commits/937256be204487727727cecc18519d85b91201d5
|
||||
Patch19: fix-ruby-2.7-warning.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/commit/ae9bf4a7355038e7e6ea13429abf815c6579f600
|
||||
Patch20: Add-minimal-support-For-rails-6.patch
|
||||
#https://github.com/thoughtbot/shoulda-matchers/commit/d39685139f878ae7295320b4707a80f16a42d427
|
||||
Patch21: fix-build-error.patch
|
||||
# git clone https://github.com/thoughtbot/shoulda-matchers.git && cd shoulda-matchers
|
||||
# git archive -v -o shoulda-matchers-4.5.1-specs.tar.gz v4.5.1 spec/
|
||||
Source1: shoulda-matchers-4.5.1-specs.tar.gz
|
||||
# Fix bootsnap removal which is not enclosed in quotes.
|
||||
# https://github.com/thoughtbot/shoulda-matchers/pull/1410
|
||||
Patch0: rubygem-shoulda-matchers-4.5.1-Remove-rack-mini-profiler-dependency.patch
|
||||
Patch1: rubygem-shoulda-matchers-4.1.2-Accept-double-quotes-when-removing-bootsnap.patch
|
||||
Patch2: rubygem-shoulda-matchers-4.5.1-Fix-keyword-arguments-for-Ruby-3.0-compatibility.patch
|
||||
Patch3: rubygem-shoulda-matchers-4.5.1-Disable-test-failing-due-to-changes-in-Rails-6.1.patch
|
||||
Patch4: rubygem-shoulda-matchers-4.5.1-Disable-CPK-test-cases-due-to-Rails-6.1-compatibilit.patch
|
||||
# Fix kwargs for Ruby 3.
|
||||
# https://github.com/thoughtbot/shoulda-matchers/pull/1406
|
||||
Patch5: rubygem-shoulda-matchers-4.5.1-Handle-argument-delegation-for-Ruby-3.patch
|
||||
|
||||
BuildRequires: ruby(release) rubygems-devel ruby rubygem(activeresource) rubygem(bcrypt)
|
||||
BuildRequires: rubygem(jbuilder) rubygem(minitest-reporters) rubygem(rails)
|
||||
BuildRequires: rubygem(rails-controller-testing) rubygem(rspec) rubygem(rspec-rails)
|
||||
@ -51,30 +38,17 @@ BuildArch: noarch
|
||||
Documentation for %{name}.
|
||||
|
||||
%prep
|
||||
%setup -q -n %{gem_name}-%{version}
|
||||
%setup -q -n %{gem_name}-%{version} -b 1
|
||||
|
||||
%patch5 -p1
|
||||
|
||||
pushd %{_builddir}
|
||||
%patch0 -p1
|
||||
%patch1 -p1
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
%patch5 -p1
|
||||
%patch6 -p1
|
||||
%patch7 -p1
|
||||
%gemspec_add_file "spec/support/unit/helpers/action_pack_versions.rb"
|
||||
%patch8 -p1
|
||||
%patch9 -p1
|
||||
%patch10 -p1
|
||||
%patch11 -p1
|
||||
%patch12 -p1
|
||||
%patch13 -p1
|
||||
%patch14 -p1
|
||||
%gemspec_add_file "spec/support/acceptance/helpers/rails_migration_helpers.rb"
|
||||
%patch15 -p1
|
||||
%patch16 -p1
|
||||
%patch17 -p1
|
||||
%patch18 -p1
|
||||
%patch19 -p1
|
||||
%patch20 -p1
|
||||
%patch21 -p1
|
||||
%patch4 -p1
|
||||
popd
|
||||
|
||||
%build
|
||||
gem build ../%{gem_name}-%{version}.gemspec
|
||||
@ -87,10 +61,10 @@ cp -a .%{gem_dir}/* \
|
||||
|
||||
%check
|
||||
pushd .%{gem_instdir}
|
||||
rm Gemfile.lock
|
||||
ln -s %{_builddir}/spec spec
|
||||
cat << GF > Gemfile
|
||||
source 'https://rubygems.org'
|
||||
gem 'activeresource'
|
||||
gem 'actiontext'
|
||||
gem 'bcrypt'
|
||||
gem 'rails'
|
||||
gem 'rails-controller-testing'
|
||||
@ -99,17 +73,21 @@ gem 'rspec-rails'
|
||||
gem 'sqlite3'
|
||||
gem 'spring'
|
||||
GF
|
||||
mv spec/unit/shoulda/matchers/{active_record/association_matcher_spec.rb,active_model/helpers_spec.rb} ./
|
||||
mv spec/acceptance/{rails_integration_spec.rb,multiple_libraries_integration_spec.rb} ./
|
||||
sed -i "/require 'pry/ s/^/#/" spec/spec_helper.rb
|
||||
sed -i "/current_bundle/ s/^/#/" spec/acceptance_spec_helper.rb
|
||||
sed -i "/assert_appraisal/ s/^/#/" spec/acceptance_spec_helper.rb
|
||||
sed -i "/current_bundle/ s/^/#/" spec/support/unit/load_environment.rb
|
||||
sed -i "/assert_appraisal/ s/^/#/" spec/support/unit/load_environment.rb
|
||||
sed -i '/rails new/ s/)/ --skip-bootsnap --skip-listen --skip-puma)/' spec/support/unit/rails_application.rb
|
||||
sed -i "/current_bundle/ s/^/#/" \
|
||||
spec/acceptance_spec_helper.rb \
|
||||
spec/support/unit/load_environment.rb
|
||||
sed -i "/CurrentBundle/ s/^/#/" \
|
||||
spec/acceptance_spec_helper.rb \
|
||||
spec/support/unit/load_environment.rb
|
||||
|
||||
sed -i "/def rails_new_command/,/^ end$/ {
|
||||
/\]/i\ '--skip-listen',
|
||||
}" spec/support/unit/rails_application.rb
|
||||
sed -i '/rails new/ s/"$/ --skip-bootsnap --skip-listen --skip-puma --skip-sprockets"/' \
|
||||
spec/support/acceptance/helpers/step_helpers.rb
|
||||
|
||||
bundle exec rspec spec/unit
|
||||
ln -sf %{_builddir}/%{gem_name}-%{version}.gemspec %{gem_name}.gemspec
|
||||
sed -i '/rails new/ s/"$/ --skip-bootsnap --skip-listen --skip-puma --skip-sprockets"/' spec/support/acceptance/helpers/step_helpers.rb
|
||||
sed -i "/bundle.add_gem 'pg'/ s/^/#/" spec/support/acceptance/helpers/step_helpers.rb
|
||||
sed -i "/add_gem 'spring-commands-rspec'/ s/^/#/" spec/support/acceptance/helpers/step_helpers.rb
|
||||
sed -i "/updating_bundle do |bundle|/a \\
|
||||
@ -117,37 +95,27 @@ sed -i "/updating_bundle do |bundle|/a \\
|
||||
sed -i "/updating_bundle do |bundle|/a \\
|
||||
bundle.remove_gem 'selenium-webdriver'" spec/support/acceptance/helpers/step_helpers.rb
|
||||
sed -i "/updating_bundle do |bundle|/a \\
|
||||
bundle.remove_gem 'chromedriver-helper'" spec/support/acceptance/helpers/step_helpers.rb
|
||||
bundle exec rspec spec/acceptance
|
||||
bundle.remove_gem 'webdrivers'" spec/support/acceptance/helpers/step_helpers.rb
|
||||
DISABLE_SPRING=true bundle exec rspec spec/acceptance
|
||||
popd
|
||||
|
||||
%files
|
||||
%dir %{gem_instdir}
|
||||
%exclude %{gem_instdir}/.*
|
||||
%exclude %{gem_instdir}/doc_config
|
||||
%license %{gem_instdir}/MIT-LICENSE
|
||||
%license %{gem_instdir}/LICENSE
|
||||
%{gem_libdir}
|
||||
%exclude %{gem_cache}
|
||||
%{gem_spec}
|
||||
|
||||
%files doc
|
||||
%doc %{gem_docdir}
|
||||
%{gem_instdir}/Appraisals
|
||||
%doc %{gem_instdir}/CONTRIBUTING.md
|
||||
%{gem_instdir}/Gemfile*
|
||||
%{gem_instdir}/NEWS.md
|
||||
%doc %{gem_instdir}/README.md
|
||||
%{gem_instdir}/Rakefile
|
||||
%{gem_instdir}/custom_plan.rb
|
||||
%doc %{gem_instdir}/docs
|
||||
%{gem_instdir}/gemfiles
|
||||
%{gem_instdir}/script
|
||||
%{gem_instdir}/shoulda-matchers.gemspec
|
||||
%{gem_instdir}/spec
|
||||
%{gem_instdir}/tasks
|
||||
%{gem_instdir}/zeus.json
|
||||
|
||||
%changelog
|
||||
* Wed Jun 29 2022 liyanan <liyanan32@h-partners.com> - 4.5.1-1
|
||||
- Upgrade to version 4.5.1
|
||||
|
||||
* Thu Mar 3 2022 liyanan <liyanan32@huawei.com> - 3.1.2-2
|
||||
- fix build error
|
||||
|
||||
|
||||
Binary file not shown.
BIN
shoulda-matchers-4.5.1-specs.tar.gz
Normal file
BIN
shoulda-matchers-4.5.1-specs.tar.gz
Normal file
Binary file not shown.
BIN
shoulda-matchers-4.5.1.gem
Normal file
BIN
shoulda-matchers-4.5.1.gem
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user