Sha256: 58f0d6a5c253a89cafad49849e51c2fbe2493112ed0313ae8eb9a542dc06b101

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe Mongoid::Ids::Generator do
  describe "#generate" do
    it "generates lowercase characters" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%c")).to match(/[a-z]/) }
    end

    it "generates uppercase characters" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%C")).to match(/[A-Z]/) }
    end

    it "generates digits" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%d")).to match(/[0-9]/) }
    end

    it "generates non-zero digits" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%D")).to match(/[1-9]/) }
    end

    it "generates alphanumeric characters" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%s")).to match(/[A-Za-z0-9]/) }
    end

    it "generates upper and lowercase characters" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%w")).to match(/[A-Za-z]/) }
    end

    it "generates URL-safe punctuation" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%p")).to match(/[\.\-\_\=\+\$]/) }
    end

    it "generates patterns of a fixed length" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%s8")).to match(/[A-Za-z0-9]{8}/) }
    end

    it "generates patterns of a variable length" do
      100.times{ expect(Mongoid::Ids::Generator.generate("%s1,5")).to match(/[A-Za-z0-9]{1,5}/) }
    end

    it "generates patterns with static prefixes/suffixes" do
      100.times { expect(Mongoid::Ids::Generator.generate("prefix-%s4-suffix")).to match(/prefix\-[A-Za-z0-9]{4}\-suffix/) }
    end

    it "generates more complex patterns" do
      100.times { expect(Mongoid::Ids::Generator.generate("pre-%d4-%C3-%d4")).to match(/pre\-[0-9]{4}\-[A-Z]{3}\-[0-9]{4}/) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-ids-0.1.8 spec/mongoid/ids/generator_spec.rb
mongoid-ids-0.1.7 spec/mongoid/ids/generator_spec.rb
mongoid-ids-0.1.1 spec/mongoid/ids/generator_spec.rb