Sha256: e6ddf844b6216b448a6a4a47a90e1f9685eaebe14444b4356e2fbf274c13b68e

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'helper'

class NameApp
  include Newark

  before do
    if params[:key] && params[:key] != '23'
      response.status = 403
      false
    end
  end

  def upcase(str)
    str.upcase
  end

  get '/upcaser' do
    upcase(params[:name])
  end

  get '/hello1' do
    hello
  end

  get '/fail' do
    'This should not be reached'
  end

  get '/hello2', :hello

  private

  def hello
    'Hello'
  end
end

class TestApp < MiniTest::Unit::TestCase

  include Rack::Test::Methods

  def app
    NameApp.new
  end

  def test_instance_method_access
    get '/upcaser', { name: 'mike' }
    assert last_response.ok?
    assert_equal 'MIKE', last_response.body
  end

  def test_alternate_action_invocation
    get '/hello1'
    assert last_response.ok?
    assert_equal 'Hello', last_response.body

    get '/hello2'
    assert last_response.ok?
    assert_equal 'Hello', last_response.body
  end

  def test_before_hooks_halting_execution
    get '/fail', { key: '1234' }
    refute last_response.ok?
    assert_equal 403, last_response.status
    assert_equal '', last_response.body
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newark-0.0.7 test/test_app.rb