Last active
August 29, 2015 14:07
-
-
Save tobowers/79ed403a1d164832da35 to your computer and use it in GitHub Desktop.
simple set key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client < ActiveRecord::Base | |
after_initialize :set_key | |
private | |
def set_key | |
self.client_key ||= SecureRandom.urlsafe_base64(20, false) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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