Sha256: 2c5ebfc2f296647345c4768136400059a5ffa192ffbfa02dbb8709607f228c49

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

# encoding: utf-8
require "spec_helper"
require "cgi"

describe UrlStore do
  before do
    @secret = 'not the standart sssecrettt1231231áßðáïíœï©óáßïáöððííïö'
    UrlStore.defaults = {:secret  => @secret}
    @data = {:x => 11212, :y => 'asdasda sdasdasdASDJKSAJDLSKDLKDS', 'asdasd' => 12312312, 12.12 => 123123212312123, :asdasdasd => '2134 adasdasóáößðóöáåöäóðᜩöóöfóöåäfóöéåfó'}
  end

  it "generates same code for same data" do
    UrlStore.encode(@data).should == UrlStore.encode(@data)
  end

  it "can decode / encode" do
    UrlStore.decode(UrlStore.encode(@data)).should == @data
  end

  it "cannot decode altered data" do
    encoded = UrlStore.encode(@data)
    UrlStore.decode(encoded+'x').should == nil
  end

  it "uses a lot of different chars" do
    UrlStore.encode(@data).split('').uniq.size.should >= 61
  end

  it "uses url-save characters" do
    encoded = UrlStore.encode(@data)
    CGI.escape(encoded).gsub('%3B',';').gsub('%7C','|').should == encoded
  end

  it "cannot decode with wrong secret" do
    encoded = UrlStore.encode(@data)
    UrlStore.defaults = {:secret => 'xxx'}
    UrlStore.decode(encoded).should == nil
  end

  it "warns when default secret is used" do
    UrlStore.defaults = {:secret => UrlStore::SECRET}
    $stderr.should_receive(:write).at_least(1)
    UrlStore.encode(1)
  end

  it "can compress" do
    x = 'a'*100
    UrlStore.encode(x).size.should <= x.size
  end

  it "can serialize using a different method" do
    old = UrlStore.encode(@data)
    UrlStore.defaults = {:serializer => :yaml, :secret => @secret}
    UrlStore.encode(@data).size.should_not == old.size
  end

  it "can serialize using different hasher" do
    old = UrlStore.encode(@data)
    UrlStore.defaults = {:hasher => 'MD5', :secret => @secret}
    UrlStore.encode(@data).size.should_not == old.size
  end

  it "has a VERSION" do
    UrlStore::VERSION.should =~ /^\d+\.\d+\.\d+$/
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
url_store-0.3.4 spec/url_store_spec.rb