Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test_helper'
- class ApplicationControllerTest < ActionController::TestCase
- class FooController < ApplicationController
- before_filter :authenticate, :only => [:require_authenticated]
- def show_current_session
- render :inline => "<p>#{current_session.inspect}</p>"
- end
- def show_current_user
- render :inline => "<p>#{current_user.inspect}</p>"
- end
- def show_signed_in
- render :inline => "<p>#{signed_in?.to_s}</p>"
- end
- def denying_access
- self.deny_access
- end
- def require_authenticated
- render :inline => '<p>Authenticated</p>'
- end
- end
- tests FooController
- ActionController::Routing::Routes.draw do |map|
- map.resource :foo, :controller => 'application_controller_test/foo',
- :member => { :show_current_session => :get,
- :show_current_user => :get,
- :show_signed_in => :get,
- :denying_access => :get,
- :require_authenticated => :get }
- end
- context "when checking if signed in" do
- context "when signed in" do
- setup do
- activate_authlogic
- Session.create Factory(:user)
- get :show_signed_in
- end
- should 'return true' do
- assert_select 'p', 'true'
- end
- end
- end
- context "when retrieving the current session" do
- context "when signed in" do
- setup do
- activate_authlogic
- Session.create Factory(:user)
- get :show_current_session
- end
- should 'retrieve the session' do
- assert_select 'p', Session.find.inspect
- end
- end
- end
- context "when retrieving the current user" do
- context "when signed in" do
- setup do
- activate_authlogic
- Session.create Factory(:user)
- get :show_current_user
- end
- should 'retrieve the user' do
- assert_select 'p', Session.find.user.inspect
- end
- end
- end
- context "on actions requiring authentication" do
- context "when signed in" do
- setup do
- activate_authlogic
- Session.create Factory(:user)
- get :require_authenticated
- end
- should_respond_with :success
- should "perform the action" do
- assert_select 'p', 'Authenticated'
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment