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|^
    .*
$| end def test_presenting_an_array_presents_the_members assert present([true]).include?("
  • True
  • ") end def test_presenting_a_hash_creates_a_definition_list assert present({1 => 'a'}) =~ %r|^
    .*
    $| 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?("
    True
    ") 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 "hello world", present('hello world', :in_a_span) end def test_presenting_a_symbol assert_equal "", 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 = {}) "#{str}" end end