class Shoulda::Matchers::ActionController::FlashStore

@private

Attributes

controller[RW]

Public Class Methods

future() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 6
def self.future
  new
end
new() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 16
def initialize
  @use_now = false
end
now() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 10
def self.now
  new.use_now!
end

Public Instance Methods

empty?() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 38
def empty?
  flash.empty?
end
has_key?(key) click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 28
def has_key?(key)
  values_to_check.include?(key.to_s)
end
has_value?(expected_value) click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 32
def has_value?(expected_value)
  values_to_check.values.any? do |actual_value|
    expected_value === actual_value
  end
end
name() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 20
def name
  if @use_now
    'flash.now'
  else
    'flash'
  end
end
use_now!() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 42
def use_now!
  @use_now = true
  self
end

Private Instance Methods

copy_discard_if_necessary(original_flash, new_flash) click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 65
def copy_discard_if_necessary(original_flash, new_flash)
  discard = original_flash.instance_variable_get('@discard').dup
  new_flash.instance_variable_set('@discard', discard)
end
copy_flashes(original_flash, new_flash) click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 60
def copy_flashes(original_flash, new_flash)
  flashes = original_flash.instance_variable_get('@flashes').dup
  new_flash.instance_variable_set('@flashes', flashes)
end
copy_of_flash_from_controller() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 53
def copy_of_flash_from_controller
  controller.flash.dup.tap do |flash|
    copy_flashes(controller.flash, flash)
    copy_discard_if_necessary(controller.flash, flash)
  end
end
flash() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 49
def flash
  @_flash ||= copy_of_flash_from_controller
end
keys_to_discard() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 74
def keys_to_discard
  flash.instance_variable_get('@discard')
end
set_values() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 70
def set_values
  flash.instance_variable_get('@flashes')
end
values_to_check() click to toggle source
# File lib/shoulda/matchers/action_controller/flash_store.rb, line 78
def values_to_check
  if @use_now
    set_values.slice(*keys_to_discard.to_a)
  else
    set_values.except(*keys_to_discard.to_a)
  end
end