|
65 | 65 | ChildDeletionJob.initialize_job(subject) |
66 | 66 | } |
67 | 67 | before do |
| 68 | + @old_max = Rails.application.config.max_children_per_job |
| 69 | + Rails.application.config.max_children_per_job = 1 |
68 | 70 | expect(child_folder).to be_persisted |
69 | 71 | expect(child_folder.is_deleted?).to be_falsey |
70 | 72 | expect(valid_child_file).to be_persisted |
|
73 | 75 | expect(invalid_child_file.is_deleted?).to be_falsey |
74 | 76 | end |
75 | 77 |
|
| 78 | + after do |
| 79 | + Rails.application.config.max_children_per_job = @old_max |
| 80 | + end |
| 81 | + |
76 | 82 | it { |
77 | 83 | expect(subject).to be_has_children |
78 | 84 | subject.is_deleted = true |
79 | 85 | yield_called = false |
80 | | - expect(ChildDeletionJob).to receive(:initialize_job) |
81 | | - .with(subject).and_return(job_transaction) |
82 | | - expect(ChildDeletionJob).to receive(:perform_later).with(job_transaction, subject) |
| 86 | + expect(ChildDeletionJob).to receive(:initialize_job).exactly(subject.children.count) |
| 87 | + .with(subject).times.and_return(job_transaction) |
| 88 | + (1..subject.children.count).each do |page| |
| 89 | + expect(ChildDeletionJob).to receive(:perform_later).with(job_transaction, subject, page) |
| 90 | + end |
83 | 91 | subject.manage_children do |
84 | 92 | yield_called = true |
85 | 93 | end |
|
133 | 141 | end |
134 | 142 |
|
135 | 143 | describe '#delete_children' do |
136 | | - it { |
137 | | - is_expected.to respond_to(:delete_children) |
138 | | - } |
139 | | - it { |
140 | | - expect(child_folder).to be_persisted |
141 | | - expect(child_folder.is_deleted?).to be_falsey |
142 | | - expect(valid_child_file).to be_persisted |
143 | | - expect(valid_child_file.is_deleted?).to be_falsey |
144 | | - expect(invalid_child_file).to be_persisted |
145 | | - expect(invalid_child_file.is_deleted?).to be_falsey |
146 | | - subject.delete_children |
147 | | - expect(child_folder.reload).to be_truthy |
148 | | - expect(child_folder.is_deleted?).to be_truthy |
149 | | - valid_child_file.reload |
150 | | - expect(valid_child_file.is_deleted?).to be_truthy |
151 | | - invalid_child_file.reload |
152 | | - expect(invalid_child_file.is_deleted?).to be_truthy |
153 | | - } |
| 144 | + it { is_expected.not_to respond_to(:delete_children).with(0).arguments } |
| 145 | + it { is_expected.to respond_to(:delete_children).with(1).argument } |
| 146 | + |
| 147 | + context 'called', :vcr do |
| 148 | + let(:job_transaction) { ChildDeletionJob.initialize_job(subject) } |
| 149 | + let(:child_job_transaction) { ChildDeletionJob.initialize_job(child_folder) } |
| 150 | + let(:child_folder_file) { FactoryGirl.create(:data_file, parent: child_folder)} |
| 151 | + let(:page) { 1 } |
| 152 | + |
| 153 | + before do |
| 154 | + expect(child_folder).to be_persisted |
| 155 | + expect(child_folder_file).to be_persisted |
| 156 | + expect(valid_child_file.is_deleted?).to be_falsey |
| 157 | + @old_max = Rails.application.config.max_children_per_job |
| 158 | + Rails.application.config.max_children_per_job = subject.children.count + child_folder.children.count |
| 159 | + end |
| 160 | + |
| 161 | + after do |
| 162 | + Rails.application.config.max_children_per_job = @old_max |
| 163 | + end |
| 164 | + |
| 165 | + it { |
| 166 | + subject.current_transaction = job_transaction |
| 167 | + expect(ChildDeletionJob).to receive(:initialize_job) |
| 168 | + .with(child_folder) |
| 169 | + .and_return(child_job_transaction) |
| 170 | + expect(ChildDeletionJob).to receive(:perform_later) |
| 171 | + .with(child_job_transaction, child_folder, page).and_call_original |
| 172 | + subject.delete_children(page) |
| 173 | + expect(child_folder.reload).to be_truthy |
| 174 | + expect(child_folder.is_deleted?).to be_truthy |
| 175 | + expect(valid_child_file.reload).to be_truthy |
| 176 | + expect(valid_child_file.is_deleted?).to be_truthy |
| 177 | + } |
| 178 | + end |
| 179 | + |
154 | 180 | end |
155 | | -end |
| 181 | + end |
0 commit comments