Remove set_the_flash in favor of set_flash
This commit is contained in:
parent
cc2772324a
commit
801f2c7c1e
2
NEWS.md
2
NEWS.md
|
@ -13,6 +13,8 @@
|
||||||
* `ensure_inclusion_of`, `ensure_exclusion_of`, and `ensure_length_of` have been
|
* `ensure_inclusion_of`, `ensure_exclusion_of`, and `ensure_length_of` have been
|
||||||
removed in favor of their `validate_*` counterparts.
|
removed in favor of their `validate_*` counterparts.
|
||||||
|
|
||||||
|
* `set_the_flash` has been removed in favor of `set_flash`.
|
||||||
|
|
||||||
# 2.8.0
|
# 2.8.0
|
||||||
|
|
||||||
### Deprecations
|
### Deprecations
|
||||||
|
|
|
@ -149,16 +149,6 @@ module Shoulda
|
||||||
SetFlashMatcher.new
|
SetFlashMatcher.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# @deprecated Use {#set_flash} instead.
|
|
||||||
# @return [SetFlashMatcher]
|
|
||||||
def set_the_flash
|
|
||||||
Shoulda::Matchers.warn_about_deprecated_method(
|
|
||||||
:set_the_flash,
|
|
||||||
:set_flash
|
|
||||||
)
|
|
||||||
set_flash
|
|
||||||
end
|
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
class SetFlashMatcher
|
class SetFlashMatcher
|
||||||
def initialize
|
def initialize
|
||||||
|
|
|
@ -1,147 +1,133 @@
|
||||||
require 'unit_spec_helper'
|
require 'unit_spec_helper'
|
||||||
|
|
||||||
describe Shoulda::Matchers::ActionController, type: :controller do
|
describe Shoulda::Matchers::ActionController::SetFlashMatcher, type: :controller do
|
||||||
describe '#set_the_flash' do
|
it 'fails with unmatchable #to' do
|
||||||
it 'is deprecated in favor of #set_flash' do
|
expect { set_flash.to(1) }.to raise_error('cannot match against 1')
|
||||||
expect { set_the_flash }.to deprecate(:set_the_flash, :set_flash)
|
end
|
||||||
|
|
||||||
|
context 'a controller that sets a flash message' do
|
||||||
|
it 'accepts setting any flash message' do
|
||||||
|
expect(controller_with_flash(notice: 'hi')).to set_flash
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'still works regardless' do
|
it 'accepts setting the exact flash message' do
|
||||||
silence_warnings do
|
expect(controller_with_flash(notice: 'hi')).to set_flash.to('hi')
|
||||||
expect(controller_with_flash(notice: 'hi')).to set_the_flash
|
end
|
||||||
end
|
|
||||||
|
it 'accepts setting a matched flash message' do
|
||||||
|
expect(controller_with_flash(notice: 'hello')).to set_flash.to(/he/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects setting a different flash message' do
|
||||||
|
expect(controller_with_flash(notice: 'hi')).
|
||||||
|
not_to set_flash.to('other')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects setting a different pattern' do
|
||||||
|
expect(controller_with_flash(notice: 'hi')).
|
||||||
|
not_to set_flash.to(/other/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#set_flash' do
|
context 'a controller that sets a flash.now message' do
|
||||||
it 'fails with unmatchable #to' do
|
it 'rejects setting any flash message' do
|
||||||
expect { set_flash.to(1) }.to raise_error('cannot match against 1')
|
expect(controller_with_flash_now).not_to set_flash
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'a controller that sets a flash message' do
|
it 'accepts setting any flash.now message' do
|
||||||
it 'accepts setting any flash message' do
|
expect(controller_with_flash_now).to set_flash.now
|
||||||
expect(controller_with_flash(notice: 'hi')).to set_flash
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting the exact flash message' do
|
|
||||||
expect(controller_with_flash(notice: 'hi')).to set_flash.to('hi')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting a matched flash message' do
|
|
||||||
expect(controller_with_flash(notice: 'hello')).to set_flash.to(/he/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different flash message' do
|
|
||||||
expect(controller_with_flash(notice: 'hi')).
|
|
||||||
not_to set_flash.to('other')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different pattern' do
|
|
||||||
expect(controller_with_flash(notice: 'hi')).
|
|
||||||
not_to set_flash.to(/other/)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'a controller that sets a flash.now message' do
|
it 'accepts setting the exact flash.now message' do
|
||||||
it 'rejects setting any flash message' do
|
expect(controller_with_flash_now(notice: 'hi')).
|
||||||
expect(controller_with_flash_now).not_to set_flash
|
to set_flash.now.to('hi')
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting any flash.now message' do
|
|
||||||
expect(controller_with_flash_now).to set_flash.now
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting the exact flash.now message' do
|
|
||||||
expect(controller_with_flash_now(notice: 'hi')).
|
|
||||||
to set_flash.now.to('hi')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting a matched flash.now message' do
|
|
||||||
expect(controller_with_flash_now(notice: 'flasher')).
|
|
||||||
to set_flash.now.to(/lash/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different flash.now message' do
|
|
||||||
expect(controller_with_flash_now(notice: 'hi')).
|
|
||||||
not_to set_flash.now.to('other')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different flash.now pattern' do
|
|
||||||
expect(controller_with_flash_now(notice: 'hi')).
|
|
||||||
not_to set_flash.now.to(/other/)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'a controller that sets flash messages for multiple keys' do
|
it 'accepts setting a matched flash.now message' do
|
||||||
it 'accepts flash message for either key' do
|
expect(controller_with_flash_now(notice: 'flasher')).
|
||||||
controller = controller_with_flash(notice: 'one', alert: 'two')
|
to set_flash.now.to(/lash/)
|
||||||
|
|
||||||
expect(controller).to set_flash[:notice]
|
|
||||||
expect(controller).to set_flash[:alert]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects a flash message that is not one of the set keys' do
|
|
||||||
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
|
||||||
not_to set_flash[:warning]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts exact flash message of notice' do
|
|
||||||
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
|
||||||
to set_flash[:notice].to('one')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting a matched flash message of notice' do
|
|
||||||
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
|
||||||
to set_flash[:notice].to(/on/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different flash message of notice' do
|
|
||||||
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
|
||||||
not_to set_flash[:notice].to('other')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different pattern' do
|
|
||||||
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
|
||||||
not_to set_flash[:notice].to(/other/)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'a controller that sets flash and flash.now' do
|
it 'rejects setting a different flash.now message' do
|
||||||
it 'accepts setting any flash.now message' do
|
expect(controller_with_flash_now(notice: 'hi')).
|
||||||
controller = build_fake_response do
|
not_to set_flash.now.to('other')
|
||||||
flash.now[:notice] = 'value'
|
|
||||||
flash[:success] = 'great job'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(controller).to set_flash.now
|
|
||||||
expect(controller).to set_flash
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'accepts setting a matched flash.now message' do
|
|
||||||
controller = build_fake_response do
|
|
||||||
flash.now[:notice] = 'value'
|
|
||||||
flash[:success] = 'great job'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(controller).to set_flash.now.to(/value/)
|
|
||||||
expect(controller).to set_flash.to(/great/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects setting a different flash.now message' do
|
|
||||||
controller = build_fake_response do
|
|
||||||
flash.now[:notice] = 'value'
|
|
||||||
flash[:success] = 'great job'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(controller).not_to set_flash.now.to('other')
|
|
||||||
expect(controller).not_to set_flash.to('other')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'a controller that does not set a flash message' do
|
it 'rejects setting a different flash.now pattern' do
|
||||||
it 'rejects setting any flash message' do
|
expect(controller_with_flash_now(notice: 'hi')).
|
||||||
expect(controller_with_no_flashes).not_to set_flash
|
not_to set_flash.now.to(/other/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'a controller that sets flash messages for multiple keys' do
|
||||||
|
it 'accepts flash message for either key' do
|
||||||
|
controller = controller_with_flash(notice: 'one', alert: 'two')
|
||||||
|
|
||||||
|
expect(controller).to set_flash[:notice]
|
||||||
|
expect(controller).to set_flash[:alert]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects a flash message that is not one of the set keys' do
|
||||||
|
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
||||||
|
not_to set_flash[:warning]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts exact flash message of notice' do
|
||||||
|
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
||||||
|
to set_flash[:notice].to('one')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts setting a matched flash message of notice' do
|
||||||
|
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
||||||
|
to set_flash[:notice].to(/on/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects setting a different flash message of notice' do
|
||||||
|
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
||||||
|
not_to set_flash[:notice].to('other')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects setting a different pattern' do
|
||||||
|
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
||||||
|
not_to set_flash[:notice].to(/other/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'a controller that sets flash and flash.now' do
|
||||||
|
it 'accepts setting any flash.now message' do
|
||||||
|
controller = build_fake_response do
|
||||||
|
flash.now[:notice] = 'value'
|
||||||
|
flash[:success] = 'great job'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expect(controller).to set_flash.now
|
||||||
|
expect(controller).to set_flash
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts setting a matched flash.now message' do
|
||||||
|
controller = build_fake_response do
|
||||||
|
flash.now[:notice] = 'value'
|
||||||
|
flash[:success] = 'great job'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(controller).to set_flash.now.to(/value/)
|
||||||
|
expect(controller).to set_flash.to(/great/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects setting a different flash.now message' do
|
||||||
|
controller = build_fake_response do
|
||||||
|
flash.now[:notice] = 'value'
|
||||||
|
flash[:success] = 'great job'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(controller).not_to set_flash.now.to('other')
|
||||||
|
expect(controller).not_to set_flash.to('other')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'a controller that does not set a flash message' do
|
||||||
|
it 'rejects setting any flash message' do
|
||||||
|
expect(controller_with_no_flashes).not_to set_flash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue