~ubuntu-branches/ubuntu/utopic/ruby-database-cleaner/utopic-proposed

« back to all changes in this revision

Viewing changes to spec/database_cleaner/generic/truncation_spec.rb

  • Committer: Package Import Robot
  • Author(s): Pirate Praveen
  • Date: 2014-05-24 01:23:06 UTC
  • Revision ID: package-import@ubuntu.com-20140524012306-1nn3zh7s867f2gn9
Tags: upstream-1.2.0
ImportĀ upstreamĀ versionĀ 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'spec_helper'
 
2
require 'database_cleaner/generic/truncation'
 
3
 
 
4
module ::DatabaseCleaner
 
5
  module Generic
 
6
    class TruncationExample
 
7
      include ::DatabaseCleaner::Generic::Truncation
 
8
 
 
9
      def only
 
10
        @only
 
11
      end
 
12
 
 
13
      def except
 
14
        @tables_to_exclude
 
15
      end
 
16
 
 
17
      def reset_ids?
 
18
        !!@reset_ids
 
19
      end
 
20
 
 
21
      def pre_count?
 
22
        !!@pre_count
 
23
      end
 
24
    end
 
25
 
 
26
    class MigrationExample < TruncationExample
 
27
      def migration_storage_names
 
28
        %w[migration_storage_name]
 
29
      end
 
30
    end
 
31
 
 
32
    describe TruncationExample do
 
33
      subject(:truncation_example) { TruncationExample.new }
 
34
 
 
35
      it "will start" do
 
36
        expect { truncation_example.start }.to_not raise_error
 
37
      end
 
38
 
 
39
      it "expects clean to be implemented later" do
 
40
        expect { truncation_example.clean }.to raise_error(NotImplementedError)
 
41
      end
 
42
 
 
43
      context "private methods" do
 
44
        it { should_not respond_to(:tables_to_truncate) }
 
45
 
 
46
        it 'expects #tables_to_truncate to be implemented later' do
 
47
          expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
 
48
        end
 
49
 
 
50
        it { should_not respond_to(:migration_storage_names) }
 
51
        its(:migration_storage_names) { should be_empty }
 
52
      end
 
53
 
 
54
      describe "initialize" do
 
55
        it { expect{ subject }.to_not raise_error }
 
56
 
 
57
        it "should accept a hash of options" do
 
58
          expect{ TruncationExample.new {} }.to_not raise_error
 
59
        end
 
60
 
 
61
        it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError"  } ) }.to     raise_error(ArgumentError) }
 
62
        it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to     raise_error(ArgumentError) }
 
63
        it { expect{ TruncationExample.new( { :only   => "something"                           } ) }.to_not raise_error }
 
64
        it { expect{ TruncationExample.new( { :except => "something"                           } ) }.to_not raise_error }
 
65
        it { expect{ TruncationExample.new( { :pre_count => "something"                        } ) }.to_not raise_error }
 
66
        it { expect{ TruncationExample.new( { :reset_ids => "something"                        } ) }.to_not raise_error }
 
67
 
 
68
        context "" do
 
69
          subject { TruncationExample.new( { :only => ["something"] } ) }
 
70
          its(:only)   { should eq ["something"] }
 
71
          its(:except) { should eq [] }
 
72
        end
 
73
 
 
74
        context "" do
 
75
          subject { TruncationExample.new( { :except => ["something"] } ) }
 
76
          its(:only)   { should eq nil }
 
77
          its(:except) { should include("something") }
 
78
        end
 
79
 
 
80
        context "" do
 
81
          subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
 
82
          its(:reset_ids?) { should eq true }
 
83
        end
 
84
 
 
85
        context "" do
 
86
          subject { TruncationExample.new( { :reset_ids => nil } ) }
 
87
          its(:reset_ids?) { should eq false }
 
88
        end
 
89
 
 
90
        context "" do
 
91
          subject { TruncationExample.new( { :pre_count => ["something"] } ) }
 
92
          its(:pre_count?) { should eq true }
 
93
        end
 
94
 
 
95
        context "" do
 
96
          subject { TruncationExample.new( { :pre_count => nil } ) }
 
97
          its(:pre_count?) { should eq false }
 
98
        end
 
99
 
 
100
        context "" do
 
101
          subject { MigrationExample.new }
 
102
          its(:only)   { should eq nil }
 
103
          its(:except) { should eq %w[migration_storage_name] }
 
104
        end
 
105
 
 
106
        context "" do
 
107
          EXCEPT_TABLES = ["something"]
 
108
          subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
 
109
 
 
110
          it "should not modify the array of excepted tables" do
 
111
            subject.except.should include("migration_storage_name")
 
112
            EXCEPT_TABLES.should_not include("migration_storage_name")
 
113
          end
 
114
        end
 
115
      end
 
116
    end
 
117
  end
 
118
end