Sha256: e0b7a344584786fd5c1e6a371d60fa222b1edfa5b386b9f2fd3e60652ee7459f

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe Tokenie do
  describe ".friendly" do
    it "generates a token with 6 characters by default" do
      SecureRandom.stub(:base64) { 'qwertytoken' }
      Tokenie.friendly.should eq('qwerty')
    end

    it "generates a token with 2 characters as passed" do
      SecureRandom.stub(:base64) { 'qwerty' }
      Tokenie.friendly(:length => 2).should eq('qw')
    end

    it "generates a friendly token" do
      SecureRandom.stub(:base64) { '+/=1lIO0o' }
      Tokenie.friendly(:length => 9).should eq('abcdefghj')
    end

    it "generates an unique token" do
      existing_tokens = ['qwerty', 'qwert2']
      generation_line = ['qwerty', 'qwert2', 'qwert3', 'qwert4']
      SecureRandom.stub(:base64) { generation_line.shift }

      token = Tokenie.friendly { |t| existing_tokens.include?(t) }
      token.should eq('qwert3')
    end

    it "raises an argument error if length is greater than 16" do
      expect {
        Tokenie.friendly(:length => 17)
      }.to raise_error("'length' must be in range (2..16)")
    end

    it "raises an argument error if length is less than 2" do
      expect {
        Tokenie.friendly(:length => 1)
      }.to raise_error("'length' must be in range (2..16)")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tokenie-0.0.3 spec/tokenie_spec.rb
tokenie-0.0.2 spec/tokenie_spec.rb