Sha256: b1302caf868dfbd825a86a210105e76623dcec4e3ba910732bcadab0dcf791c7

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require File.expand_path('../../../../spec/helper', __FILE__)

$password = Digest::SHA1.hexdigest('pass')

class SpecHelperAuth < Ramaze::Controller
  map '/'
  helper :auth

  def index
    self.class.name
  end

  def session_inspect
    session.inspect
  end

  def secured
    "Secret content"
  end
  before(:secured){ login_required }
end

class SpecHelperAuthHash < SpecHelperAuth
  map '/hash'
  trait :auth_table => {
      'manveru' => $password
    }
end

class SpecHelperAuthMethod < SpecHelperAuth
  map '/method'
  trait :auth_table => :auth_table

  private

  def auth_table
    { 'manveru' => $password }
  end
end

class SpecHelperAuthLambda < SpecHelperAuth
  map '/lambda'
  trait :auth_table => lambda{
      { 'manveru' => $password }
    }
end

describe Ramaze::Helper::Auth do
  %w[ hash lambda method ].each do |prefix|
    describe "login" do
      behaves_like :rack_test

      it "uses a #{prefix}" do
        get "/#{prefix}/secured"
        follow_redirect!
        last_response.status.should == 200
        last_response.body.should =~ (/<form/)

        post("/#{prefix}/login", 'username' => 'manveru', 'password' => 'pass')
        follow_redirect!
        last_response.status.should == 200
        last_response.body.should == 'Secret content'

        get "/#{prefix}/secured"
        last_response.status.should == 200
        last_response.body.should == 'Secret content'

        get "/#{prefix}/logout"
        follow_redirect!
        last_response.status.should == 200
        last_response.body.should == 'SpecHelperAuth'

        get "/#{prefix}/secured"
        follow_redirect!
        last_response.status.should == 200
        last_response.body.should =~ (/<form/)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
Pistos-ramaze-2009.06.12 spec/ramaze/helper/auth.rb
manveru-ramaze-2009.07 spec/ramaze/helper/auth.rb
ramaze-2011.01.30 spec/ramaze/helper/auth.rb
ramaze-2011.01 spec/ramaze/helper/auth.rb
ramaze-2010.06.18 spec/ramaze/helper/auth.rb
ramaze-2010.04.04 spec/ramaze/helper/auth.rb
ramaze-2010.04 spec/ramaze/helper/auth.rb
ramaze-2010.03 spec/ramaze/helper/auth.rb
ramaze-2010.01 spec/ramaze/helper/auth.rb
ramaze-2009.10 spec/ramaze/helper/auth.rb
ramaze-2009.07 spec/ramaze/helper/auth.rb