Sha256: 6002b1555fef1cf3bd9246a852dbec8dd67a528df266d0d1997007bfe84eb744

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

# coding: utf-8
require 'spec_helper'

describe 'User model' do
  before :all do
    @name = ('a'..'z').to_a.sample(4).join ''
    @user_jim = User.create name: @name, :age => Random.new.rand(10..100)
    @user_tom = User.create name: @name, :age => Random.new.rand(10..100)
  end

  it 'hashable' do
    hash = @user_jim.to_param
    expect(@user_jim.id).to eq User.hash_ids_decode(hash).first
  end

  it '#find single' do
    id = @user_tom.id
    hash_id = @user_tom.to_param

    expect(User.find(hash_id)).to eq User.find(id)
  end

  it '#find multiple' do
    ids = [@user_jim.id, @user_tom.id]
    hash_ids = [@user_jim.to_param, @user_tom.to_param]

    expect(User.find(ids)).to eq User.find(hash_ids)
    expect(User.find(ids.first, ids.last)).to eq User.find(hash_ids.first, hash_ids.last)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hash_ids-0.0.6 spec/models/user_spec.rb
hash_ids-0.0.5 spec/models/user_spec.rb