|
6 | 6 | end
|
7 | 7 |
|
8 | 8 | describe '#analyse!' do
|
| 9 | + context 'raise exception' do |
| 10 | + subject { described_class.new(models: [TestIntModel], days_count: 10) } |
| 11 | + |
| 12 | + context 'empty table' do |
| 13 | + it { expect { subject.analyse! }.not_to raise_error } |
| 14 | + end |
| 15 | + |
| 16 | + context 'not empty table' do |
| 17 | + let(:max_int) { 2_147_483_647 } |
| 18 | + let(:day) { 24 * 60 * 60 } |
| 19 | + let(:today) { Time.now } |
| 20 | + |
| 21 | + context 'overflow far' do |
| 22 | + before do |
| 23 | + (1..7).each do |t| |
| 24 | + TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + after do |
| 29 | + TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
| 30 | + TestIntModel.destroy_all |
| 31 | + end |
| 32 | + |
| 33 | + it { expect { subject.analyse! }.not_to raise_error } |
| 34 | + end |
| 35 | + |
| 36 | + context 'overflow soon' do |
| 37 | + before do |
| 38 | + TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 16};}) |
| 39 | + (1..7).each do |t| |
| 40 | + TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + after do |
| 45 | + TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
| 46 | + TestIntModel.destroy_all |
| 47 | + end |
| 48 | + |
| 49 | + it { expect { subject.analyse! }.to raise_error(described_class::Overflow) } |
| 50 | + end |
| 51 | + |
| 52 | + context 'overflowed' do |
| 53 | + before do |
| 54 | + TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 6};}) |
| 55 | + (1..7).each do |t| |
| 56 | + TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + after do |
| 61 | + TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
| 62 | + TestIntModel.destroy_all |
| 63 | + end |
| 64 | + |
| 65 | + it { expect { subject.analyse! }.to raise_error(described_class::Overflow) } |
| 66 | + end |
| 67 | + end |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + describe '#analyse' do |
9 | 72 | context 'signalize to logger' do
|
10 | 73 | let!(:logger) { double(:logger, warn: true) }
|
11 | 74 |
|
|
14 | 77 | context 'empty table' do
|
15 | 78 | it 'doesnt log anything' do
|
16 | 79 | expect(logger).not_to receive(:warn)
|
17 |
| - subject.analyse! |
| 80 | + subject.analyse |
18 | 81 | end
|
19 | 82 | end
|
20 | 83 |
|
|
37 | 100 |
|
38 | 101 | it 'doesnt log anything' do
|
39 | 102 | expect(logger).not_to receive(:warn)
|
40 |
| - subject.analyse! |
| 103 | + subject.analyse |
41 | 104 | end
|
42 | 105 | end
|
43 | 106 |
|
|
57 | 120 | it 'log about owerflow' do
|
58 | 121 | expect(logger).to receive(:warn)
|
59 | 122 | .with("Primary key in table #{TestIntModel.table_name} will overflow soon! #{TestIntModel.last.id} from #{max_int}")
|
60 |
| - subject.analyse! |
| 123 | + subject.analyse |
61 | 124 | end
|
62 | 125 | end
|
63 | 126 |
|
|
77 | 140 | it 'log about owerflow' do
|
78 | 141 | expect(logger).to receive(:warn)
|
79 | 142 | .with("Primary key in table #{TestIntModel.table_name} overflowed! #{TestIntModel.last.id} from #{max_int}")
|
80 |
| - subject.analyse! |
| 143 | + subject.analyse |
81 | 144 | end
|
82 | 145 | end
|
83 | 146 | end
|
|
91 | 154 | context 'empty table' do
|
92 | 155 | it 'doesnt log anything' do
|
93 | 156 | expect(signalizer).not_to receive(:signalize)
|
94 |
| - subject.analyse! |
| 157 | + subject.analyse |
95 | 158 | end
|
96 | 159 | end
|
97 | 160 |
|
|
114 | 177 |
|
115 | 178 | it 'doesnt log anything' do
|
116 | 179 | expect(signalizer).not_to receive(:signalize)
|
117 |
| - subject.analyse! |
| 180 | + subject.analyse |
118 | 181 | end
|
119 | 182 | end
|
120 | 183 |
|
|
134 | 197 | it 'log about owerflow' do
|
135 | 198 | expect(signalizer).to receive(:signalize)
|
136 | 199 | .with("Primary key in table #{TestIntModel.table_name} will overflow soon! #{TestIntModel.last.id} from #{max_int}")
|
137 |
| - subject.analyse! |
| 200 | + subject.analyse |
138 | 201 | end
|
139 | 202 | end
|
140 | 203 |
|
|
154 | 217 | it 'log about owerflow' do
|
155 | 218 | expect(signalizer).to receive(:signalize)
|
156 | 219 | .with("Primary key in table #{TestIntModel.table_name} overflowed! #{TestIntModel.last.id} from #{max_int}")
|
157 |
| - subject.analyse! |
| 220 | + subject.analyse |
158 | 221 | end
|
159 | 222 | end
|
160 | 223 | end
|
|
0 commit comments