|
13 | 13 |
|
14 | 14 | describe '#analyse!' do
|
15 | 15 | context 'raise exception' do
|
16 |
| - subject { described_class.new(models: [TestIntModel], days_count: 10) } |
| 16 | + let(:logger) { Logger.new('/dev/null') } |
| 17 | + subject { described_class.new(logger: logger, models: [TestIntModel], days_count: 10) } |
17 | 18 |
|
18 | 19 | context 'empty table' do
|
19 | 20 | it { expect { subject.analyse! }.not_to raise_error }
|
20 | 21 | end
|
21 | 22 |
|
22 | 23 | context 'unsupported type of primary key' do
|
23 | 24 | let(:today) { Time.now }
|
24 |
| - let(:logger) { Logger.new('/dev/null') } |
25 | 25 | before do
|
26 | 26 | (1..7).each do |t|
|
27 | 27 | record = TestStringModel.new(created_at: today - day * t, updated_at: today - day * t)
|
|
87 | 87 | end
|
88 | 88 | end
|
89 | 89 | end
|
90 |
| - |
91 |
| - describe '#analyse' do |
92 |
| - context 'signalize to logger' do |
93 |
| - let!(:logger) { Logger.new('/dev/null') } |
94 |
| - |
95 |
| - subject { described_class.new(logger: logger, models: [TestIntModel], days_count: 10) } |
96 |
| - |
97 |
| - context 'empty table' do |
98 |
| - it 'doesnt log to warn' do |
99 |
| - expect(logger).not_to receive(:warn) |
100 |
| - subject.analyse |
101 |
| - end |
102 |
| - end |
103 |
| - |
104 |
| - context 'not empty table' do |
105 |
| - let(:today) { Time.now } |
106 |
| - |
107 |
| - context 'overflow far' do |
108 |
| - before do |
109 |
| - (1..7).each do |t| |
110 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
111 |
| - end |
112 |
| - end |
113 |
| - |
114 |
| - after do |
115 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
116 |
| - TestIntModel.destroy_all |
117 |
| - end |
118 |
| - |
119 |
| - it 'doesnt log to warn' do |
120 |
| - expect(logger).not_to receive(:warn) |
121 |
| - subject.analyse |
122 |
| - end |
123 |
| - end |
124 |
| - |
125 |
| - context 'overflow soon' do |
126 |
| - before do |
127 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 16};}) |
128 |
| - (1..7).each do |t| |
129 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
130 |
| - end |
131 |
| - end |
132 |
| - |
133 |
| - after do |
134 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
135 |
| - TestIntModel.destroy_all |
136 |
| - end |
137 |
| - |
138 |
| - it 'log about owerflow' do |
139 |
| - expect(logger).to receive(:warn) |
140 |
| - .with("Owerflowed tables: #{[]}. Overflow soon tables: #{[TestIntModel.table_name]}") |
141 |
| - subject.analyse |
142 |
| - end |
143 |
| - end |
144 |
| - |
145 |
| - context 'overflowed' do |
146 |
| - before do |
147 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 6};}) |
148 |
| - (1..7).each do |t| |
149 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
150 |
| - end |
151 |
| - end |
152 |
| - |
153 |
| - after do |
154 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
155 |
| - TestIntModel.destroy_all |
156 |
| - end |
157 |
| - |
158 |
| - it 'log about owerflow' do |
159 |
| - expect(logger).to receive(:warn) |
160 |
| - .with("Owerflowed tables: #{[TestIntModel.table_name]}. Overflow soon tables: #{[]}") |
161 |
| - subject.analyse |
162 |
| - end |
163 |
| - end |
164 |
| - end |
165 |
| - end |
166 |
| - |
167 |
| - context 'custom signalizer' do |
168 |
| - let!(:signalizer) { double(:signalizer, signalize: true) } |
169 |
| - |
170 |
| - subject { described_class.new(signalizer: signalizer, models: [TestIntModel], days_count: 10) } |
171 |
| - |
172 |
| - context 'empty table' do |
173 |
| - it 'doesnt log to warn' do |
174 |
| - expect(signalizer).not_to receive(:signalize) |
175 |
| - subject.analyse |
176 |
| - end |
177 |
| - end |
178 |
| - |
179 |
| - context 'not empty table' do |
180 |
| - let(:today) { Time.now } |
181 |
| - |
182 |
| - context 'overflow far' do |
183 |
| - before do |
184 |
| - (1..7).each do |t| |
185 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
186 |
| - end |
187 |
| - end |
188 |
| - |
189 |
| - after do |
190 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
191 |
| - TestIntModel.destroy_all |
192 |
| - end |
193 |
| - |
194 |
| - it 'doesnt log to warn' do |
195 |
| - expect(signalizer).not_to receive(:signalize) |
196 |
| - subject.analyse |
197 |
| - end |
198 |
| - end |
199 |
| - |
200 |
| - context 'overflow soon' do |
201 |
| - before do |
202 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 16};}) |
203 |
| - (1..7).each do |t| |
204 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
205 |
| - end |
206 |
| - end |
207 |
| - |
208 |
| - after do |
209 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
210 |
| - TestIntModel.destroy_all |
211 |
| - end |
212 |
| - |
213 |
| - it 'log about owerflow' do |
214 |
| - expect(signalizer).to receive(:signalize) |
215 |
| - .with("Owerflowed tables: #{[]}. Overflow soon tables: #{[TestIntModel.table_name]}") |
216 |
| - subject.analyse |
217 |
| - end |
218 |
| - end |
219 |
| - |
220 |
| - context 'overflowed' do |
221 |
| - before do |
222 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH #{max_int - 6};}) |
223 |
| - (1..7).each do |t| |
224 |
| - TestIntModel.create!(created_at: today - day * t, updated_at: today - day * t) |
225 |
| - end |
226 |
| - end |
227 |
| - |
228 |
| - after do |
229 |
| - TestIntModel.connection.execute(%Q{ALTER SEQUENCE "int_test_id_seq" RESTART WITH 1;}) |
230 |
| - TestIntModel.destroy_all |
231 |
| - end |
232 |
| - |
233 |
| - it 'log about owerflow' do |
234 |
| - expect(signalizer).to receive(:signalize) |
235 |
| - .with("Owerflowed tables: #{[TestIntModel.table_name]}. Overflow soon tables: #{[]}") |
236 |
| - subject.analyse |
237 |
| - end |
238 |
| - end |
239 |
| - end |
240 |
| - end |
241 |
| - end |
242 | 90 | end
|
0 commit comments