diff options
author | Rémy Coutable <remy@rymai.me> | 2019-04-18 22:08:04 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-05-20 14:31:58 +0200 |
commit | 4d9c76e9e44119ee2578c94b2b98bb72e80e874b (patch) | |
tree | 441a0b95536a35959f237c487cfba44f5dbdd7ed /spec/support/shared_examples/models/update_project_statistics_shared_examples.rb | |
parent | 27d207bd8fa0ca095f4008fbcc62c0b924b8c405 (diff) | |
download | gitlab-ce-4d9c76e9e44119ee2578c94b2b98bb72e80e874b.tar.gz |
Reorganize test jobs by levelreorganize-tests-jobs-by-level
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/support/shared_examples/models/update_project_statistics_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/models/update_project_statistics_shared_examples.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb new file mode 100644 index 00000000000..7a04e940ee5 --- /dev/null +++ b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require 'spec_helper' + +shared_examples_for 'UpdateProjectStatistics' do + let(:project) { subject.project } + let(:stat) { described_class.statistic_name } + let(:attribute) { described_class.statistic_attribute } + + def reload_stat + project.statistics.reload.send(stat).to_i + end + + def read_attribute + subject.read_attribute(attribute).to_i + end + + it { is_expected.to be_new_record } + + context 'when creating' do + it 'updates the project statistics' do + delta = read_attribute + + expect { subject.save! } + .to change { reload_stat } + .by(delta) + end + end + + context 'when updating' do + before do + subject.save! + end + + it 'updates project statistics' do + delta = 42 + + expect(ProjectStatistics) + .to receive(:increment_statistic) + .and_call_original + + subject.write_attribute(attribute, read_attribute + delta) + expect { subject.save! } + .to change { reload_stat } + .by(delta) + end + end + + context 'when destroying' do + before do + subject.save! + end + + it 'updates the project statistics' do + delta = -read_attribute + + expect(ProjectStatistics) + .to receive(:increment_statistic) + .and_call_original + + expect { subject.destroy } + .to change { reload_stat } + .by(delta) + end + + context 'when it is destroyed from the project level' do + it 'does not update the project statistics' do + expect(ProjectStatistics) + .not_to receive(:increment_statistic) + + project.update(pending_delete: true) + project.destroy! + end + end + end +end |