Sha256: 81fe33f5a4d0849a888497044ab62fc8e34ba4a7824028893332c217665ad5a8

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

module G5Authenticatable
  module Test
    module ControllerHelpers

      def login_user(user)
        @request.env["devise.mapping"] = Devise.mappings[:user]
        sign_in user
      end

      def logout_user(user)
        sign_out(user)
      end

    end
  end
end

shared_context 'auth controller', auth_controller: true do
  include G5Authenticatable::Test::ControllerHelpers
  let(:user) { FactoryGirl.create(:g5_authenticatable_user) }

  before do
    stub_valid_access_token(user.g5_access_token)
    login_user(user)
  end

  after { logout_user(user) }
end

shared_examples 'a secure controller' do

  controller do

    before_filter :authenticate_user!

    def index
      render text: 'content'
    end
  end

  context "without an authenticated user" do

    it "should be redirected" do
      get :index
      expect(response).to redirect_to('/g5_auth/users/sign_in')
    end

  end

  context 'with an authenticated user', :auth_controller do

    it 'should be successful' do
      get :index
      expect(response.body).to eq('content')
    end

  end
end

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
  config.include G5Authenticatable::Test::ControllerHelpers, type: :controller
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
g5_authenticatable-0.7.3 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.7.2 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.7.1 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.7.0 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.6.0 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.5.1 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.5.0 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.4.2 lib/g5_authenticatable/test/controller_helpers.rb
g5_authenticatable-0.4.1 lib/g5_authenticatable/test/controller_helpers.rb