Skip to content

Instantly share code, notes, and snippets.

@csexton
Created July 28, 2016 14:48
Show Gist options
  • Save csexton/8c1f2e67a626de37c085c86b6845a5d6 to your computer and use it in GitHub Desktop.
Save csexton/8c1f2e67a626de37c085c86b6845a5d6 to your computer and use it in GitHub Desktop.
OAuth Provider User Cache Key
class ApplicationController < ActionController::Base
before_action :set_radius_user_cache_key
# bunch-o-auth stuff goes here
private
def set_radius_user_cache_key
if current_user
cookies[:_radius_user_cache_key] = { value: current_user.cache_key, domain: :all, tld_length: 2 }
else
cookies[:_radius_user_cache_key] = { value: "none", domain: :all, tld_length: 2 }
end
end
end
require 'rails_helper'
describe ApplicationController, :type => :controller do
let(:centurion) { create(User) }
def stub_sign_in(user)
allow(controller).to receive(:current_user).and_return(user)
sign_in user
end
controller do
public :cookies
def index
render nothing: true
end
end
describe "GET 'index'" do
it "sets the user cache key cookie" do
sign_in centurion
allow(controller).to receive(:current_user).and_return(centurion)
get 'index'
key = controller.cookies[:_radius_user_cache_key]
expect(key).to eq centurion.cache_key
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment