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
|
||||
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
|
||||
|
||||
* 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
|
||||
[#917]: https://github.com/thoughtbot/shoulda-matchers/pulls/917
|
||||
[#867]: https://github.com/thoughtbot/shoulda-matchers/issues/867
|
||||
[#1054]: https://github.com/thoughtbot/shoulda-matchers/pulls/1054
|
||||
|
||||
### Improvements
|
||||
|
||||
|
|
|
@ -20,11 +20,15 @@ module Shoulda
|
|||
# should_not use_before_filter(:prevent_ssl)
|
||||
# end
|
||||
#
|
||||
# @note This method is only available when using shoulda-matchers under
|
||||
# Rails 4.x.
|
||||
# @return [CallbackMatcher]
|
||||
#
|
||||
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
|
||||
# callback is defined within your controller.
|
||||
|
@ -45,11 +49,15 @@ module Shoulda
|
|||
# should_not use_after_filter(:destroy_user)
|
||||
# end
|
||||
#
|
||||
# @note This method is only available when using shoulda-matchers under
|
||||
# Rails 4.x.
|
||||
# @return [CallbackMatcher]
|
||||
#
|
||||
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
|
||||
# callback is defined within your controller.
|
||||
|
@ -120,11 +128,15 @@ module Shoulda
|
|||
# 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]
|
||||
#
|
||||
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
|
||||
# callback is defined within your controller.
|
||||
|
|
|
@ -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 @@ module Shoulda
|
|||
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(
|
||||
|
|
|
@ -8,7 +8,11 @@ module UnitTests
|
|||
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
|
||||
|
|
|
@ -31,7 +31,7 @@ module UnitTests
|
|||
rails_version >= 4.2
|
||||
end
|
||||
|
||||
def rails_lte_5?
|
||||
def rails_lt_5?
|
||||
rails_version < 5
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,6 +54,7 @@ describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller
|
|||
end
|
||||
end
|
||||
|
||||
if action_pack_lt_5?
|
||||
describe '#use_before_filter' do
|
||||
it_behaves_like 'CallbackMatcher', :before, :filter
|
||||
end
|
||||
|
@ -65,8 +66,8 @@ describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller
|
|||
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
|
||||
|
@ -78,5 +79,4 @@ describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller
|
|||
describe '#use_around_action' do
|
||||
it_behaves_like 'CallbackMatcher', :around, :action
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue