Sha256: 2d9c6922986beb34006396538a31aa1879fd4c8aca86b83f1367056342b8037f

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

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

class Presenting::HelpersTest < ActionView::TestCase
  
  def test_presenting_a_boolean
    assert_equal 'False', present(false)
    assert_equal 'True', present(true)
  end
  
  def test_presenting_a_nil
    assert_equal "", present(nil)
  end
  
  def test_presenting_an_array_creates_an_ordered_list
    assert present(['hello', 'world']) =~ %r|^<ol>.*</ol>$|
  end
  
  def test_presenting_an_array_presents_the_members
    assert present([true]).include?("<li>True</li>")
  end
  
  def test_presenting_a_hash_creates_a_definition_list
    assert present({1 => 'a'}) =~ %r|^<dl>.*</dl>$|
  end
  
  def test_presenting_a_hash_sorts_by_hash_keys
    assert present({1 => 'a', 4 => 'd', 3 => 'c', 2 => 'b'}) =~ /^.*a.*b.*c.*d.*$/
  end
  
  def test_presenting_a_hash_presents_the_values
    assert present({1 => true}).include?("<dd>True</dd>")
  end
  
  def test_presenting_a_time
    assert_equal 'Fri, 13 Feb 2009 02:31:00 +0000', present(Time.zone.parse('2009-02-13 02:31 AM UTC'))
  end
  
  def test_presenting_a_date
    assert_equal '2009-02-13', present(Time.zone.parse('2009-02-13 02:31 AM UTC').to_date)
  end
  
  def test_presenting_a_string
    assert_equal "hello world", present("hello world")
  end
  
  def test_presenting_a_named_method
    assert_equal "<span>hello world</span>", present('hello world', :in_a_span)
  end

  def test_presenting_a_symbol
    assert_equal "<span></span>", present(:in_a_span)
  end

  def test_presenting_a_named_presentation
    self.expects(:controller).returns(ActionView::TestCase::TestController.new)
    Presentation::Grid.any_instance.expects(:render)
    present('hello', :grid)
  end
  
  def test_presenting_an_unknown_presentation
    assert_raises ArgumentError do
      present(@users, :unknown)
    end
  end
  
  protected
  
  def present_in_a_span(str, options = {})
    "<span>#{str}</span>"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
presenting-3.0.0 test/helpers_test.rb
presenting-2.1.0 test/helpers_test.rb
presenting-2.0.3 test/helpers_test.rb
presenting-2.0.2 test/helpers_test.rb