diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-07-16 13:12:37 +0000 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-07-16 13:12:37 +0000 |
commit | 556d213cbc8b2ce44fd4d7fafde0a28804d3ae29 (patch) | |
tree | e5c6553cf1557b9f75166d4b99e71ec570acc626 /spec/lib/gitlab | |
parent | f1b257f32ba8e9118b9e5ac84fd3c97d070551bb (diff) | |
download | gitlab-ce-556d213cbc8b2ce44fd4d7fafde0a28804d3ae29.tar.gz |
Refactored WebIdeCommitsCount class
We're adding more redis base counters to the web ide and other
classes. We're refactoring this class in other to use the logic
in other places.
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb | 54 | ||||
-rw-r--r-- | spec/lib/gitlab/web_ide_commits_counter_spec.rb | 19 |
2 files changed, 54 insertions, 19 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb new file mode 100644 index 00000000000..38b4c22e186 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do + context 'when redis_key is not defined' do + subject do + Class.new.extend(described_class) + end + + describe '.increment' do + it 'raises a NotImplementedError exception' do + expect { subject.increment}.to raise_error(NotImplementedError) + end + end + + describe '.total_count' do + it 'raises a NotImplementedError exception' do + expect { subject.total_count}.to raise_error(NotImplementedError) + end + end + end + + context 'when redis_key is defined' do + subject do + counter_module = described_class + + Class.new do + extend counter_module + + def self.redis_counter_key + 'foo_redis_key' + end + end + end + + describe '.increment' do + it 'increments the web ide commits counter by 1' do + expect do + subject.increment + end.to change { subject.total_count }.from(0).to(1) + end + end + + describe '.total_count' do + it 'returns the total amount of web ide commits' do + subject.increment + subject.increment + + expect(subject.total_count).to eq(2) + end + end + end +end diff --git a/spec/lib/gitlab/web_ide_commits_counter_spec.rb b/spec/lib/gitlab/web_ide_commits_counter_spec.rb deleted file mode 100644 index c51889a1c63..00000000000 --- a/spec/lib/gitlab/web_ide_commits_counter_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::WebIdeCommitsCounter, :clean_gitlab_redis_shared_state do - describe '.increment' do - it 'increments the web ide commits counter by 1' do - expect do - described_class.increment - end.to change { described_class.total_count }.from(0).to(1) - end - end - - describe '.total_count' do - it 'returns the total amount of web ide commits' do - expect(described_class.total_count).to eq(0) - end - end -end |