Sha256: c684279bd83ec3f89c2fe31b5209072680c85bb6caa9b158f51f4279e7f637b1

Contents?: true

Size: 1.86 KB

Versions: 11

Compression:

Stored size: 1.86 KB

Contents

require "spec_helper"

describe ApplicationController do
  let(:user) {
    User.create(
      :login => "johndoe",
      :email => "john@doe.com",
      :password => "test",
      :password_confirmation => "test"
    )
  }

  context "redirecting logged users" do
    context "using hash" do
      controller do
        redirect_logged_user :to => { :controller => "dashboard" }

        def index
          render :text => "Rendered"
        end
      end

      it "should redirect logged users" do
        session[:user_id] = user.id
        get :index

        response.code.should match(/302/)
        response.should redirect_to("/dashboard")
      end
    end

    context "using block" do
      controller do
        redirect_logged_user :to => proc { dashboard_path }

        def index
          render :text => "Rendered"
        end
      end

      it "should redirect logged users" do
        session[:user_id] = user.id
        get :index

        response.code.should match(/302/)
        response.should redirect_to("/dashboard")
      end
    end

    context "using configuration" do
      controller do
        redirect_logged_user

        def index
          render :text => "Rendered"
        end
      end

      it "should redirect logged users" do
        SimpleAuth::Config.logged_url = proc { dashboard_path }
        session[:user_id] = user.id
        get :index

        response.code.should match(/302/)
        response.should redirect_to("/dashboard")
      end
    end

    context "when unlogged" do
      controller do
        redirect_logged_user :to => { :controller => "dashboard" }

        def index
          render :text => "Rendered"
        end
      end

      it "should render page" do
        session[:user_id] = nil
        get :index

        response.code.should match(/200/)
        response.body.should == "Rendered"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
simple_auth-1.5.0 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.5 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.4 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.3 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.2 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.1 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.4.0 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.3.3 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.3.2 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.3.1 spec/controllers/redirect_logged_user_spec.rb
simple_auth-1.3.0 spec/controllers/redirect_logged_user_spec.rb