Sha256: 88ee12187993b950face7694f823dcb47fcdcc04ab2fb2bf7b25b949bc72434a

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

begin
  require 'padrino-gen'
  Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{bootstrapped_admin_app,admin_controller_test,scaffold}.rb']
rescue LoadError
  # Fail silently
end

module LazyHeadGen

  # Allows testing as a logged in admin user
  #
  # param [Account] account - The account to attempt login with
  def login_as_admin(account)
    post "/admin/sessions/create", {
      :email => account.email, :password => "password"
    }
    follow_redirect!
  end

  # Standard assertions to test when an admin user is not logged in
  # and trys to view an admin page
  #
  def assert_admin_not_logged_in
    assert !ok?
    assert_equal 302, status
    assert_equal "http://example.org/admin/sessions/new", location
  end

  # Assertions to test when an admin user is not logged in
  # and trys to call a destroy action
  #
  def assert_admin_destroy_not_logged_in
    assert !ok?
    assert_equal 405, status
    assert_nil location
  end

  # Some shorthands for last_request and last_response varibles
  #
  def path
    last_request.path
  end

  def session
    last_request.env['rack.session']
  end

  def body
    last_response.body
  end

  def status
    last_response.status
  end

  def location
    last_response.original_headers["Location"]
  end

  def ok?
    last_response.ok?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lazy-head-gen-0.4.2 lib/lazy-head-gen.rb
lazy-head-gen-0.4.1 lib/lazy-head-gen.rb
lazy-head-gen-0.4.0 lib/lazy-head-gen.rb