Created
October 14, 2014 21:52
-
-
Save marcioj/bfb50b0b60b8e4ede962 to your computer and use it in GitHub Desktop.
Supress devise flash messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe Devise::SessionsController, :type => :controller do | |
before(:each) do | |
@request.env["devise.mapping"] = Devise.mappings[:user] | |
end | |
def action | |
post :create | |
end | |
context "action filtered" do | |
controller do | |
self.supress_devise_flash = :create | |
def create | |
set_flash_message(:notice, "message") | |
render text: "hello world" | |
end | |
end | |
before { action } | |
it { should_not set_the_flash } | |
end | |
context "action not filtered" do | |
controller do | |
self.supress_devise_flash = [] | |
def create | |
set_flash_message(:notice, "message") | |
render text: "hello world" | |
end | |
end | |
before { action } | |
it { should set_the_flash } | |
end | |
context "filtered non existent action" do | |
controller do | |
self.supress_devise_flash = [:update] | |
def create | |
set_flash_message(:notice, "message") | |
render text: "hello world" | |
end | |
end | |
before { action } | |
it { should set_the_flash } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Devise::SessionsController.supress_devise_flash = :create, :destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SupressDeviseFlashMessage | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :supress_devise_flash, instance_accessor: false | |
self.supress_devise_flash = [] | |
def set_flash_message_with_supress(*args) | |
set_flash_message_without_supress(*args) unless Array.wrap(self.class.supress_devise_flash).include?(params[:action].to_sym) | |
end | |
alias_method_chain :set_flash_message, :supress | |
end | |
end | |
DeviseController.send(:include, SupressDeviseFlashMessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment