module Mache::Helpers::Rails::Flash

The {Flash} module can be included into page object classes that support flash behaviour.

rubocop:disable Naming/PredicateName

Public Class Methods

included(base) click to toggle source
# File lib/mache/helpers/rails/flash.rb, line 9
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

has_alert_message?(text) click to toggle source

Tests whether the page has an alert message.

@param text [Regexp, String] a value to match @return `true` if the page has a matching message, `false` otherwise

# File lib/mache/helpers/rails/flash.rb, line 50
def has_alert_message?(text)
  has_message?(:alert, text)
end
has_error_message?(text) click to toggle source

Tests whether the page has an error message.

@param text [Regexp, String] a value to match @return `true` if the page has a matching message, `false` otherwise

# File lib/mache/helpers/rails/flash.rb, line 58
def has_error_message?(text)
  has_message?(:error, text)
end
has_message?(type, text) click to toggle source

Tests whether the page has a flash message.

@param type [String, Symbol] a flash message type @param text [Regexp, String] a value to match @return `true` if the page has a matching message, `false` otherwise

# File lib/mache/helpers/rails/flash.rb, line 24
def has_message?(type, text)
  css_class = flash[:class] || ''
  regexp = text.is_a?(String) ? /\A#{Regexp.escape(text)}\Z/ : text
  css_class.include?(type.to_s) && flash.text.strip =~ regexp
end
has_notice_message?(text) click to toggle source

Tests whether the page has a notice message.

@param text [Regexp, String] a value to match @return `true` if the page has a matching message, `false` otherwise

# File lib/mache/helpers/rails/flash.rb, line 42
def has_notice_message?(text)
  has_message?(:notice, text)
end
has_success_message?(text) click to toggle source

Tests whether the page has a success message.

@param text [Regexp, String] a value to match @return `true` if the page has a matching message, `false` otherwise

# File lib/mache/helpers/rails/flash.rb, line 34
def has_success_message?(text)
  has_message?(:success, text)
end