Sha256: bbbd3709cff3e89b5b3e5fb8e0e3fffe58d26a92c16c9c1dc5dbf992980421c0

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))

require "ohm/utils/upgrade"

def redis
  Ohm.redis
end

setup do
  redis.flushdb

  @users = Ohm::Key.new(:User, Ohm.redis)

  10.times do
    @id = redis.incr(@users[:id])
    @user = @users[@id]

    redis.sadd @users[:all], @id

    redis.set  @user[:name], "Albert"
    redis.set  @user[:email], "albert-#{@id}@example.com"
    redis.incr @user[:views]

    redis.sadd @user[:posts], 1
    redis.sadd @user[:posts], 2

    redis.lpush @user[:comments], 3
    redis.lpush @user[:comments], 4

    redis.sadd @user[:_indices], @users[:email][Ohm::Model.encode "albert-#{@id}@example.com"]
    redis.sadd @users[:email][Ohm::Model.encode "albert-#{@id}@example.com"], @id
  end
end

test "upgrade to hashes" do
  require "stringio"

  stderr, stdout = $stderr, $stdout

  $stderr, $stdout = StringIO.new, StringIO.new

  Ohm::Utils::Upgrade.new([:User]).run

  $stderr, $stdout = stderr, stdout

  @user = @users[1]

  assert redis.get(@user[:name]).nil?
  assert redis.get(@user[:email]).nil?
  assert redis.get(@user[:views]).nil?

  assert ["1", "2"] == redis.smembers(@user[:posts])

  assert [@users[:email][Ohm::Model.encode "albert-1@example.com"]] == redis.smembers(@user[:_indices])
  assert ["1"] == redis.smembers(@users[:email][Ohm::Model.encode "albert-1@example.com"])

  assert "Albert" == redis.hget(@user, :name)
  assert "albert-1@example.com" == redis.hget(@user, :email)
  assert "1" == redis.hget(@user, :views)
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ohm-1.0.0.rc4 test/unused/upgrade_script_test.rb
ohm-1.0.0.rc3 test/unused/upgrade_script_test.rb
ohm-1.0.0.rc2 test/unused/upgrade_script_test.rb
ohm-1.0.0.rc1 test/unused/upgrade_script_test.rb
ohm-1.0.0.alpha2 test/unused/upgrade_script_test.rb
ohm-1.0.0.alpha1 test/unused/upgrade_script_test.rb
ohm-0.1.5 test/upgrade_script_test.rb
ohm-0.1.4 test/upgrade_script_test.rb
ohm-0.1.3 test/upgrade_script_test.rb
ohm-0.1.2 test/upgrade_script_test.rb
ohm-0.1.1 test/upgrade_script_test.rb
ohm-0.1.0 test/upgrade_script_test.rb
ohm-0.1.0.rc6 test/upgrade_script_test.rb