Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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