Sha256: 500b343b7a0e73dfad75c32b4430d59ce76bfde4def96bfc2e3d54fda0478077

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class MockFlash < Hash
  def initialize(flash = {})
    flash.each { |k,v| self[k] = v }
  end

  alias_method :has?, :include?
end

class FlashTest < Test::Unit::TestCase
  include Haml::Helpers
  include Sinatra::Helpers::Haml::Flash

  attr_reader :flash

  def setup
    init_haml_helpers
    super
  end

  def test_should_not_show_message_for_empty_flash
    @flash = MockFlash.new
    flash_messages
    assert_html ''
  end

  def test_should_show_message_for_error_flash
    @flash = MockFlash.new :error => 'error message'
    flash_messages
    assert_html 'div', 1
    assert_html 'div.error', :html => 'error message', :count => 1
  end

  def test_should_show_message_for_warning_flash
    @flash = MockFlash.new :warning => 'warning message'
    flash_messages
    assert_html 'div', 1
    assert_html 'div.warning', :html => 'warning message', :count => 1
  end

  def test_should_show_message_for_notice_flash
    @flash = MockFlash.new :notice => 'notice message'
    flash_messages
    assert_html 'div', 1
    assert_html 'div.notice', :html => 'notice message', :count => 1
  end

  def test_should_show_messages_for_multiple_flash
    @flash = MockFlash.new :error => 'error message', :warning => 'warning message', :notice => 'notice message'
    flash_messages
    assert_html 'div', 3
    assert_html 'div.error', :html => 'error message', :count => 1
    assert_html 'div.warning', :html => 'warning message', :count => 1
    assert_html 'div.notice', :html => 'notice message', :count => 1
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
sbfaulkner-sinatra-helpers-0.9.1 test/haml/flash_test.rb
tdreyno-middleman-0.2.8 vendor/sinatra-helpers/test/haml/flash_test.rb
tdreyno-middleman-0.2.9 vendor/sinatra-helpers/test/haml/flash_test.rb
tdreyno-middleman-0.3.0 vendor/sinatra-helpers/test/haml/flash_test.rb
tdreyno-middleman-0.3.1 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.3.6 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.3.5 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.2.8 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.2.9 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.3.0 vendor/sinatra-helpers/test/haml/flash_test.rb
middleman-0.3.1 vendor/sinatra-helpers/test/haml/flash_test.rb