mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
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.
This commit is contained in:
parent
4970253779
commit
6ea9afc106
7 changed files with 60 additions and 29 deletions
7
NEWS.md
7
NEWS.md
|
@ -12,6 +12,12 @@ is now:
|
||||||
* Drop support for Rails 4.0 and 4.1 as well as Ruby 2.0 and 2.1, since they've
|
* Drop support for Rails 4.0 and 4.1 as well as Ruby 2.0 and 2.1, since they've
|
||||||
been end-of-lifed. The gem now supports Ruby 2.2+ and Rails 4.2+.
|
been end-of-lifed. The gem now supports Ruby 2.2+ and Rails 4.2+.
|
||||||
|
|
||||||
|
* `use_before_filter`, `use_after_filter`, and `use_around_filter` are no longer
|
||||||
|
usable when using shoulda-matchers under Rails 5.x, as the corresponding
|
||||||
|
controller callback don't exist there.
|
||||||
|
|
||||||
|
* *PR: [#1054]*
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
* Fix association matchers when used under Rails 5.x so that they make use of
|
* Fix association matchers when used under Rails 5.x so that they make use of
|
||||||
|
@ -56,6 +62,7 @@ is now:
|
||||||
[#964]: https://github.com/thoughtbot/shoulda-matchers/pulls/964
|
[#964]: https://github.com/thoughtbot/shoulda-matchers/pulls/964
|
||||||
[#917]: https://github.com/thoughtbot/shoulda-matchers/pulls/917
|
[#917]: https://github.com/thoughtbot/shoulda-matchers/pulls/917
|
||||||
[#867]: https://github.com/thoughtbot/shoulda-matchers/issues/867
|
[#867]: https://github.com/thoughtbot/shoulda-matchers/issues/867
|
||||||
|
[#1054]: https://github.com/thoughtbot/shoulda-matchers/pulls/1054
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,14 @@ module Shoulda
|
||||||
# should_not use_before_filter(:prevent_ssl)
|
# should_not use_before_filter(:prevent_ssl)
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
# @note This method is only available when using shoulda-matchers under
|
||||||
|
# Rails 4.x.
|
||||||
# @return [CallbackMatcher]
|
# @return [CallbackMatcher]
|
||||||
#
|
#
|
||||||
def use_before_filter(callback)
|
if RailsShim.action_pack_lt_5?
|
||||||
CallbackMatcher.new(callback, :before, :filter)
|
def use_before_filter(callback)
|
||||||
|
CallbackMatcher.new(callback, :before, :filter)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The `use_after_filter` matcher is used to test that an after_filter
|
# The `use_after_filter` matcher is used to test that an after_filter
|
||||||
|
@ -45,10 +49,14 @@ module Shoulda
|
||||||
# should_not use_after_filter(:destroy_user)
|
# should_not use_after_filter(:destroy_user)
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
# @note This method is only available when using shoulda-matchers under
|
||||||
|
# Rails 4.x.
|
||||||
# @return [CallbackMatcher]
|
# @return [CallbackMatcher]
|
||||||
#
|
#
|
||||||
def use_after_filter(callback)
|
if RailsShim.action_pack_lt_5?
|
||||||
CallbackMatcher.new(callback, :after, :filter)
|
def use_after_filter(callback)
|
||||||
|
CallbackMatcher.new(callback, :after, :filter)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The `use_before_action` matcher is used to test that a before_action
|
# The `use_before_action` matcher is used to test that a before_action
|
||||||
|
@ -120,10 +128,14 @@ module Shoulda
|
||||||
# should_not use_around_filter(:save_view_context)
|
# should_not use_around_filter(:save_view_context)
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
# @note This method is only available when using shoulda-matchers under
|
||||||
|
# Rails 4.x.
|
||||||
# @return [CallbackMatcher]
|
# @return [CallbackMatcher]
|
||||||
#
|
#
|
||||||
def use_around_filter(callback)
|
if RailsShim.action_pack_lt_5?
|
||||||
CallbackMatcher.new(callback, :around, :filter)
|
def use_around_filter(callback)
|
||||||
|
CallbackMatcher.new(callback, :around, :filter)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The `use_around_action` matcher is used to test that an around_action
|
# The `use_around_action` matcher is used to test that an around_action
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Shoulda
|
module Shoulda
|
||||||
module Matchers
|
module Matchers
|
||||||
# @private
|
# @private
|
||||||
class RailsShim
|
module RailsShim
|
||||||
class << self
|
class << self
|
||||||
def action_pack_gte_4_1?
|
def action_pack_gte_4_1?
|
||||||
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||||
|
@ -11,12 +11,20 @@ module Shoulda
|
||||||
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def action_pack_lt_5?
|
||||||
|
Gem::Requirement.new('< 5').satisfied_by?(action_pack_version)
|
||||||
|
end
|
||||||
|
|
||||||
def action_pack_version
|
def action_pack_version
|
||||||
Gem::Version.new(::ActionPack::VERSION::STRING)
|
Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||||
|
rescue NameError
|
||||||
|
Gem::Version.new('0')
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_record_major_version
|
def active_record_major_version
|
||||||
::ActiveRecord::VERSION::MAJOR
|
::ActiveRecord::VERSION::MAJOR
|
||||||
|
rescue NameError
|
||||||
|
Gem::Version.new('0')
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_validation_message(
|
def generate_validation_message(
|
||||||
|
|
|
@ -8,7 +8,11 @@ module UnitTests
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_pack_gte_5?
|
def action_pack_gte_5?
|
||||||
action_pack_version =~ '>= 5'
|
action_pack_version >= 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def action_pack_lt_5?
|
||||||
|
action_pack_version < 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_pack_version
|
def action_pack_version
|
||||||
|
|
|
@ -31,7 +31,7 @@ module UnitTests
|
||||||
rails_version >= 4.2
|
rails_version >= 4.2
|
||||||
end
|
end
|
||||||
|
|
||||||
def rails_lte_5?
|
def rails_lt_5?
|
||||||
rails_version < 5
|
rails_version < 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,29 +54,29 @@ describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#use_before_filter' do
|
if action_pack_lt_5?
|
||||||
it_behaves_like 'CallbackMatcher', :before, :filter
|
describe '#use_before_filter' do
|
||||||
end
|
it_behaves_like 'CallbackMatcher', :before, :filter
|
||||||
|
|
||||||
describe '#use_after_filter' do
|
|
||||||
it_behaves_like 'CallbackMatcher', :after, :filter
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#use_around_filter' do
|
|
||||||
it_behaves_like 'CallbackMatcher', :around, :filter
|
|
||||||
end
|
|
||||||
|
|
||||||
if rails_4_x?
|
|
||||||
describe '#use_before_action' do
|
|
||||||
it_behaves_like 'CallbackMatcher', :before, :action
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#use_after_action' do
|
describe '#use_after_filter' do
|
||||||
it_behaves_like 'CallbackMatcher', :after, :action
|
it_behaves_like 'CallbackMatcher', :after, :filter
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#use_around_action' do
|
describe '#use_around_filter' do
|
||||||
it_behaves_like 'CallbackMatcher', :around, :action
|
it_behaves_like 'CallbackMatcher', :around, :filter
|
||||||
end
|
end
|
||||||
end
|
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_around_action' do
|
||||||
|
it_behaves_like 'CallbackMatcher', :around, :action
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'unit_spec_helper'
|
require 'unit_spec_helper'
|
||||||
|
|
||||||
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :model do
|
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :model do
|
||||||
if rails_lte_5?
|
if action_pack_lt_5?
|
||||||
context '#description' do
|
context '#description' do
|
||||||
context 'without a role' do
|
context 'without a role' do
|
||||||
it 'includes the attribute name' do
|
it 'includes the attribute name' do
|
||||||
|
|
Loading…
Reference in a new issue