Skip to content

Instantly share code, notes, and snippets.

@tobowers
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobowers/79ed403a1d164832da35 to your computer and use it in GitHub Desktop.
Save tobowers/79ed403a1d164832da35 to your computer and use it in GitHub Desktop.
simple set key
class Client < ActiveRecord::Base
after_initialize :set_key
private
def set_key
self.client_key ||= SecureRandom.urlsafe_base64(20, false)
end
end
require 'spec_helper'
describe Client do
describe "client_key" do
subject { client.client_key }
context "for a new client" do
let(:client) { Client.new }
it "gets a new client key" do
expect(subject).to_not be_nil
end
end
context "for a client loaded from the db"
let(:saved_client) { c = Client.new; c.save; c }
let(:client) do
Client.find(saved_client.id)
end
it "should return the existing client_id" do
expect(subject).to eq(saved_client.client_key)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment