Skip to content

Instantly share code, notes, and snippets.

@jeffkreeftmeijer
Created October 30, 2014 12:22
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 jeffkreeftmeijer/13759d1c49d82febc720 to your computer and use it in GitHub Desktop.
Save jeffkreeftmeijer/13759d1c49d82febc720 to your computer and use it in GitHub Desktop.
module Concerns::Token
def self.included(base)
base.after_initialize(:set_token)
end
def set_token
self.token = SecureRandom.hex if new_record?
end
end
require_relative '../../test_helper'
describe Concerns::Token do
[Session, Discussion, Comment, Notification].each do |model|
describe "for a #{model}" do
it "automatically generates a token" do
model.new.token.length.should == 32
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment