Sha256: ddf89455164d15be519cb20870289d1a766c2c1c8ad972d908b1dae3d4ca7ab8

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'
require 'redis'
require 'database_cleaner/redis/truncation'


module DatabaseCleaner
  module Redis

    describe Truncation do
      before(:all) do
        config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../examples/config/redis.yml"))
      @redis = ::Redis.connect :url => config['test']['url']
      end

      before(:each) do
        @redis.flushdb
      end

      it "should flush the database" do
        Truncation.new.clean
      end

      def create_widget(attrs={})
        @redis.set 'Widget', 1
      end

      def create_gadget(attrs={})
        @redis.set 'Gadget', 1
      end

      it "truncates all keys by default" do
        create_widget
        create_gadget
        @redis.keys.size.should eq 2
        Truncation.new.clean
        @redis.keys.size.should eq 0
      end

      context "when keys are provided to the :only option" do
        it "only truncates the specified keys" do
          create_widget
          create_gadget
          @redis.keys.size.should eq 2
          Truncation.new(:only => ['Widge*']).clean
          @redis.keys.size.should eq 1
          @redis.get('Gadget').should eq '1'
        end
      end

      context "when keys are provided to the :except option" do
        it "truncates all but the specified keys" do
          create_widget
          create_gadget
          @redis.keys.size.should eq 2
          Truncation.new(:except => ['Widg*']).clean
          @redis.keys.size.should eq 1
          @redis.get('Widget').should eq '1'
        end
      end
    end
  end
end

Version data entries

15 entries across 10 versions & 3 rubygems

Version Path
database_cleaner-1.5.1 spec/database_cleaner/redis/truncation_spec.rb
database_cleaner-1.5.0 spec/database_cleaner/redis/truncation_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/redis/truncation_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/redis/truncation_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/redis/truncation_spec.rb
database_cleaner-1.4.1 spec/database_cleaner/redis/truncation_spec.rb
database_cleaner-1.4.0 spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/database_cleaner-1.2.0/spec/database_cleaner/redis/truncation_spec.rb
database_cleaner-1.3.0 spec/database_cleaner/redis/truncation_spec.rb
database_cleaner-1.2.0 spec/database_cleaner/redis/truncation_spec.rb