Sha256: cd72d91717871077d53ded02cd8f893ce94d1b7c0b2a96347a78ab88ad5bc0b6

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe '#idy_encode' do
  context 'with no given salt' do
    let!(:model) { Article.new id: 1 }

    it 'obfuscates the id with default class salt' do
      expect(model.class.idy_encode(model.id)).to eq 'My'
    end
  end

  context 'with empty salt' do
    let!(:model) { Article.new id: 1 }
    let!(:salt)  { '' }

    it 'obfuscates the id with empty salt' do
      expect(model.class.idy_encode(model.id, salt: salt)).to eq 'jR'
    end
  end

  context 'with salt' do
    let!(:model) { Article.new id: 1 }

    context 'as string' do
      let!(:salt) { 'salt' }

      it 'obfuscates the id with given salt' do
        expect(model.class.idy_encode(model.id, salt: salt)).to eq 'XG'
      end
    end

    context 'as number' do
      let!(:salt) { 1 }

      it 'obfuscates the id with given salt as string' do
        expect(model.class.idy_encode(model.id, salt: salt)).to eq 'kL'
      end
    end
  end

  context 'with nil id' do
    let!(:model) { Article.new }

    it 'returns nil' do
      expect(model.class.idy_encode(model.id)).to be_nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
idy-0.1.3 spec/lib/idy/extension/idy_encode_spec.rb
idy-0.1.2 spec/lib/idy/extension/idy_encode_spec.rb
idy-0.1.1 spec/lib/idy/extension/idy_encode_spec.rb