package init
This commit is contained in:
parent
052a67177b
commit
2556d57cbc
@ -0,0 +1,47 @@
|
||||
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,
|
||||
@ -0,0 +1,75 @@
|
||||
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,
|
||||
@ -0,0 +1,230 @@
|
||||
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
|
||||
@ -0,0 +1,24 @@
|
||||
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
|
||||
|
||||
@ -0,0 +1,201 @@
|
||||
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
|
||||
@ -0,0 +1,32 @@
|
||||
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
|
||||
@ -0,0 +1,25 @@
|
||||
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
|
||||
@ -0,0 +1,108 @@
|
||||
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
|
||||
@ -0,0 +1,61 @@
|
||||
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
|
||||
|
||||
@ -0,0 +1,117 @@
|
||||
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
|
||||
206
rubygem-shoulda-matchers-3.1.2-Refactor-RailsShim.patch
Normal file
206
rubygem-shoulda-matchers-3.1.2-Refactor-RailsShim.patch
Normal file
@ -0,0 +1,206 @@
|
||||
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
|
||||
@ -0,0 +1,183 @@
|
||||
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)
|
||||
@ -0,0 +1,91 @@
|
||||
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
|
||||
@ -0,0 +1,38 @@
|
||||
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
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
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 }
|
||||
132
rubygem-shoulda-matchers.spec
Normal file
132
rubygem-shoulda-matchers.spec
Normal file
@ -0,0 +1,132 @@
|
||||
%global gem_name shoulda-matchers
|
||||
Name: rubygem-%{gem_name}
|
||||
Version: 3.1.2
|
||||
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
|
||||
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)
|
||||
BuildRequires: rubygem(shoulda-context) rubygem(spring) rubygem(sqlite3)
|
||||
BuildArch: noarch
|
||||
%description
|
||||
shoulda-matchers provides Test::Unit- and RSpec-compatible one-liners that
|
||||
test common Rails functionality. These tests would otherwise be much longer,
|
||||
more complex, and error-prone.
|
||||
|
||||
%package doc
|
||||
Summary: Documentation for %{name}
|
||||
Requires: %{name} = %{version}-%{release}
|
||||
BuildArch: noarch
|
||||
%description doc
|
||||
Documentation for %{name}.
|
||||
|
||||
%prep
|
||||
%setup -q -n %{gem_name}-%{version}
|
||||
%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
|
||||
|
||||
%build
|
||||
gem build ../%{gem_name}-%{version}.gemspec
|
||||
%gem_install
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}%{gem_dir}
|
||||
cp -a .%{gem_dir}/* \
|
||||
%{buildroot}%{gem_dir}/
|
||||
|
||||
%check
|
||||
pushd .%{gem_instdir}
|
||||
rm Gemfile.lock
|
||||
cat << GF > Gemfile
|
||||
source 'https://rubygems.org'
|
||||
gem 'activeresource'
|
||||
gem 'bcrypt'
|
||||
gem 'rails'
|
||||
gem 'rails-controller-testing'
|
||||
gem 'rspec'
|
||||
gem 'rspec-rails'
|
||||
gem 'sqlite3'
|
||||
gem 'spring'
|
||||
GF
|
||||
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
|
||||
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 \\
|
||||
bundle.remove_gem 'capybara'" spec/support/acceptance/helpers/step_helpers.rb
|
||||
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
|
||||
popd
|
||||
|
||||
%files
|
||||
%dir %{gem_instdir}
|
||||
%exclude %{gem_instdir}/.*
|
||||
%exclude %{gem_instdir}/doc_config
|
||||
%license %{gem_instdir}/MIT-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
|
||||
* Mon Aug 10 2020 yanan li <liyanan032@huawei.com> - 3.1.2-1
|
||||
- Package init
|
||||
5
rubygem-shoulda-matchers.yaml
Normal file
5
rubygem-shoulda-matchers.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
git_url: https://github.com/thoughtbot/shoulda-matchers.git
|
||||
version_control: github
|
||||
src_repo: thoughtbot/shoulda-matchers
|
||||
tag_prefix: "^v"
|
||||
seperator: "."
|
||||
BIN
shoulda-matchers-3.1.2.gem
Normal file
BIN
shoulda-matchers-3.1.2.gem
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user