Sha256: da87a6dbcb02f7b9f3011906424a18ebc44d230de761dba079a3ba8520240215

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require 'test_helper'
require 'camping'

Camping.goes :Markup

module Markup::Controllers
  class Index
    def get
      render :index
    end
  end
  
  class NoLayout
    def get
      render :index, :layout => false
    end
  end

  class AutoPrepend
    def get
      mab do
        img :src => '/hello.png'
      end
    end
  end

  class Compat < R '/compat/(.*?)'
    def get(type)
      mab do
        send(type) do
          body { h1 'Nice' }
        end
      end
    end
  end

  class CompatHelpers
    def get
      mab do
        helpers.R CompatHelpers
      end
    end
  end
end

module Markup::Views
  def index
    h1 "Welcome!"
  end
  
  def layout
    self << '<!DOCTYPE html>'
    html do
      head do
        title "Web Page"
      end
      
      body { yield }
    end
  end
end

class Markup::Test < TestCase
  def test_render
    get '/'
    assert_body %r{\A<!DOCTYPE html>}
    assert_body %r{<h1>Welcome!</h1>}
    assert_body %r{<title>Web Page</title>}
  end
  
  def test_no_layout
    get '/no/layout'
    assert_body %r{<h1>Welcome!</h1>}
    
    assert_reverse do
      assert_body %r{<title>Web Page</title>}
    end
  end

  def test_auto_prepend
    get '/auto/prepend', {}, 'SCRIPT_NAME' => '/mount'
    assert_body '<img src="/mount/hello.png">'
  end

  def test_compat
    warning = "xhtml_strict is no longer supported (or an active standard); using HTML5 instead\n"

    assert_output '', warning * 3 do
      get '/compat/xhtml_strict'
      assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'

      get '/compat/xhtml_transitional'
      assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'

      get '/compat/xhtml_frameset'
      assert_body '<!DOCTYPE html><html><body><h1>Nice</h1></body></html>'
    end
  end

  def test_compat_helpers
    get '/compat/helpers'
    assert_body '/compat/helpers'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
camping-2.1.532 test/app_markup.rb
camping-2.1.531 test/app_markup.rb
camping-2.1.523 test/app_markup.rb