Sha256: 226b85f687f0eb5026da5971ec73f003fa146ecf979232e40a9c6a8ebb748186

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe UrlStore::CompactEncoder do
  before do
    @encoder = UrlStore::CompactEncoder.new('asdasdsa')
    @data = {:x => 1, 'asdadadadas' => 'asdasdadawvxcxcxcvjs', 'dasdasdadsadad' => 'asdasdwxczvvcjjkdfjkdf'}
  end

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

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

  it "generates shorter codes than pure base64" do
    hash_length = 40
    @encoder.encode(@data).size.should < (Base64.encode64(Marshal.dump(@data)).size + hash_length)
  end

  it "can encode/decode with yaml" do
    @encoder = UrlStore::CompactEncoder.new('asdasdsa', :serializer => :yaml)
    @encoder.decode(@encoder.encode(@data)).should == @data
  end

  it "can hash with other hasher" do
    @encoder = UrlStore::CompactEncoder.new('asdasdsa', :hasher => 'MD5')
    @encoder.decode(@encoder.encode(@data)).should == @data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
url_store-0.2.0 spec/url_store/compact_encoder_spec.rb