Sha256: 55085046837d2f1a3b86a334604e6c9e0523b1d566ffa0903573b66f187fc050

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

require "spec_helper"

describe Hash do

  it "should #merge_to_max values" do
    hash = {:count => 1}
    expect(hash.merge_to_max(:sum, 3)).to be true
    expect(hash).to eq({:count => 1, :sum => 3})
    expect(hash.merge_to_max(:count, 4)).to be true
    expect(hash).to eq({:count => 4, :sum => 3})
    expect(hash.merge_to_max(:count, 3)).to be false
    expect(hash.merge_to_max(:count, 'test')).to be false
    expect(hash.merge_to_max(:view, 'test')).to be false
    expect(hash).to eq({:count => 4, :sum => 3})
    hash[:view] = 'test'
    expect(hash.merge_to_max(:view, 3)).to be false
  end

  it "should #merge_to_max! hashes" do
    hash = { :count => 1, :sum => 2}

    expect(hash.clone.merge_to_max!({:mult => 3, :sum => 2, :count => 2})).to eq({:count => 2, :sum => 2, :mult => 3})
    expect(hash.clone.merge_to_max!({:mult => 3, :sum => 3, :count => 2})).to eq({:count => 2, :sum => 3, :mult => 3})
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redisrank-0.1.0 spec/core_ext/hash_spec.rb