Sha256: cde646d8ff38e6175284ba4b687f1a2cdd967eee1f555232e413f81bd6d149c0

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require "rails"
require "rails/all"
require 'switch_user/rails'


class ApplicationController < ActionController::Base
  def require_user
    current_user || redirect_to("/dummy/open")
  end

  def current_user
    User.find_by_id(session[SwitchUser.session_key])
  end

  def login
    user = User.find(params[:id])
    session[SwitchUser.session_key] = user.id

    redirect_to("/dummy/protected")
  end

  def logout
    session[SwitchUser.session_key] = nil

    redirect_to("/dummy/open")
  end
end

class DummyController < ApplicationController
  before_filter :require_user, :only => :protected

  def authenticated
    render :text => current_user.inspect
  end

  def open
    render :text => view_context.switch_user_select
  end

  def protected
    render :text => view_context.switch_user_select
  end
end

module MyApp
  class Application < Rails::Application
    config.active_support.deprecation = :log
    config.secret_key_base = "abc123"
    config.eager_load = true
    config.secret_token = '153572e559247c7aedd1bca5a246874d'

    # should set it
    config.action_dispatch.show_exceptions = false
  end
end
Rails.application.initialize!
Rails.application.routes.draw do
  get 'dummy/protected', :to => "dummy#protected"
  get 'dummy/open', :to => "dummy#open"
  post 'login', :to => "dummy#login"
  get 'logout', :to => "dummy#logout"
  get 'authenticated', :to => "dummy#authenticated"
  get :switch_user, :to => 'switch_user#set_current_user'
  get 'switch_user/remember_user', :to => 'switch_user#remember_user'
end

connection = ActiveRecord::Base.connection
connection.create_table :users do |t|
  t.column :email, :string
  t.column :admin, :boolean
end

class User < ActiveRecord::Base
end

connection.create_table :clients do |t|
  t.column :email, :string
end

class Client < ActiveRecord::Base
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
switch_user-1.4.0 spec/support/application.rb
switch_user-1.3.1 spec/support/application.rb
switch_user-1.3.0 spec/support/application.rb