Sha256: 130f4f9d1ce6609ae95e160753ed9cd7c830dad79b35ca502e05df882e8d02fa

Contents?: true

Size: 1.82 KB

Versions: 27

Compression:

Stored size: 1.82 KB

Contents

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

module DatabaseCleaner
  module Ohm

    class Widget < ::Ohm::Model
      attribute :name
    end

    class Gadget < ::Ohm::Model
      attribute :name
    end

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

      before(:each) do
        @redis.flushdb
      end

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

      def create_widget(attrs={})
        Widget.new({:name => 'some widget'}.merge(attrs)).save
      end

      def create_gadget(attrs={})
        Gadget.new({:name => 'some gadget'}.merge(attrs)).save
      end

      it "truncates all keys by default" do
        create_widget
        create_gadget
        @redis.keys.size.should eq 6
        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 6
          Truncation.new(:only => ['*Widget*']).clean
          @redis.keys.size.should eq 3
          @redis.get('DatabaseCleaner::Ohm::Gadget:id').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 6
          Truncation.new(:except => ['*Widget*']).clean
          @redis.keys.size.should eq 3
          @redis.get('DatabaseCleaner::Ohm::Widget:id').should eq '1'
        end
      end
    end
  end
end

Version data entries

27 entries across 22 versions & 4 rubygems

Version Path
database_cleaner-1.6.2 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.6.1 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.6.0 spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.5.3 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.5.2 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.5.1 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.5.0 spec/database_cleaner/ohm/truncation_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/ohm/truncation_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/ohm/truncation_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/database_cleaner-1.4.1/spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.4.1 spec/database_cleaner/ohm/truncation_spec.rb
database_cleaner-1.4.0 spec/database_cleaner/ohm/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/ohm/truncation_spec.rb