File: deletion_spec.rb

package info (click to toggle)
ruby-database-cleaner 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 768 kB
  • sloc: ruby: 4,854; makefile: 10; sh: 4
file content (58 lines) | stat: -rw-r--r-- 1,679 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'spec_helper'
require 'database_cleaner/sequel/deletion'
require 'database_cleaner/shared_strategy'
require 'sequel'
require 'support/active_record/database_setup'

module DatabaseCleaner
  module Sequel
    describe Deletion do
      it_should_behave_like "a generic strategy"
    end

    shared_examples 'a Sequel deletion strategy' do
      let(:deletion) do
        d = Deletion.new
        d.db = db
        d
      end

      context 'when several tables have data' do
        before(:each) do
          db.create_table!(:precious_stones) { primary_key :id }
          db.create_table!(:replaceable_trifles)  { primary_key :id }
          db.create_table!(:worthless_junk)  { primary_key :id }

          db[:precious_stones].insert
          db[:replaceable_trifles].insert
          db[:worthless_junk].insert
        end

        context 'by default' do
          it 'deletes all the tables' do
            d = Deletion.new
            d.db = db
            d.clean

            expect(db[:replaceable_trifles]).to have(0).rows
            expect(db[:worthless_junk]).to have(0).rows
            expect(db[:precious_stones]).to have(0).rows
          end
        end
      end
    end

    supported_configurations = [
      { :url => 'mysql:///', :connection_options => db_config['mysql'] },
      { :url => 'postgres:///', :connection_options => db_config['postgres'] }
    ]

    supported_configurations.each do |config|
      describe "Sequel deletion (using a #{config[:url]} connection)" do
        let(:db) { ::Sequel.connect(config[:url], config[:connection_options]) }

        it_behaves_like 'a Sequel deletion strategy'
      end
    end
  end
end