Sha256: 5cbfbb93592c69ae9853a10ad778ad9d64c615695c088c661092862ccdd658e6

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Backend do
  let(:redis){ double(del: '') }

  before :each do
    Backend.stub(:host)
    Backend.stub(:port)
    Backend.stub(:redis){ redis }
  end

  describe 'performance_stats' do
    before :each do
      PerformanceStats.any_instance.stub(:results){ {} }
    end

    it 'should return a hash with the stats' do
      Backend.performance_stats.should be_kind_of(Hash)
    end
  end

  describe 'search' do
    let(:keys){ ['k1', 'k2', 'k3'] }

    before :each do
      Backend.stub(:keys){ keys }
      Backend.stub(:get){ 'value' }
    end

    it 'should return an array of hashes' do
      Backend.search('*').should be_kind_of(Array)
      Backend.search('*')[0].should be_kind_of(Hash)
    end

    it 'every entry should have key and value data' do
      Backend.search('*')[0][:key].should_not be_nil
      Backend.search('*')[0][:value].should_not be_nil
    end
  end

  describe 'del' do
    it 'should not delete content if not allowed' do
      Authorization.stub(:authorized_for?).with(:remove_content){ false }
      redis.should_receive(:del).never
      Backend.del('key')
    end

    it 'should remove content if allowed' do
      Authorization.stub(:authorized_for?).with(:remove_content){ true }
      redis.should_receive(:del)
      Backend.del('key')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis_monitor-0.0.6 spec/modules/backend_spec.rb