Sha256: cdbbbbab690df735c0d8f857d679e1a6fdacb91eddab510fad535396cc0882ea

Contents?: true

Size: 895 Bytes

Versions: 12

Compression:

Stored size: 895 Bytes

Contents

require 'spec_helper'
require 'cuba_api/config'
require 'cuba_api/current_user'

class SessionManager
  def to_session( user )
    @u ||= user
  end
  def from_session( data )
    u = @u.dup unless @u.nil?
    def u.login; self;end
    u
  end
end

describe CubaApi::CurrentUser do

  before do
    Cuba.reset!
    Cuba.plugin CubaApi::Config
    Cuba.plugin CubaApi::CurrentUser
    Cuba.use Rack::Session::Cookie, :secret => 'asd'
    Cuba[ :sessions ] = SessionManager.new
    Cuba.define do
      on authenticated? do
        res.write current_user
      end
      on default do
        name = current_user_name
        current_user "user1"
        res.write "logged in - #{name}"
      end
    end
  end

  it 'should authenticate' do
     _, _, resp = Cuba.call({})
    
    resp.join.must.eq "logged in - ???"

     _, _, resp = Cuba.call({})
    
    resp.join.must.eq "user1"
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cuba-api-0.6.3 spec/current_user_spec.rb
cuba-api-0.6.2 spec/current_user_spec.rb
cuba-api-0.6.1 spec/current_user_spec.rb
cuba-api-0.6.0 spec/current_user_spec.rb
cuba-api-0.5.1 spec/current_user_spec.rb
cuba-api-0.5.0 spec/current_user_spec.rb
cuba-api-0.4.0 spec/current_user_spec.rb
cuba-api-0.3.3 spec/current_user_spec.rb
cuba-api-0.3.2 spec/current_user_spec.rb
cuba-api-0.3.1 spec/current_user_spec.rb
cuba-api-0.3.0 spec/current_user_spec.rb
cuba-api-0.2.0 spec/current_user_spec.rb