summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2019-07-17 23:45:35 +0000
committerNick Thomas <nick@gitlab.com>2019-07-17 23:45:35 +0000
commitbcd2458076512ad80c6e470d9434618f27dfec3c (patch)
tree92081015f8202b37abb3e6c79808e84ce0dccbe9 /spec/lib
parentf74bd44d2a9171c51ec7c9a622d7628044791d9e (diff)
downloadgitlab-ce-bcd2458076512ad80c6e470d9434618f27dfec3c.tar.gz
Refactor RedisCounter and WebIdeCommitsCounter
This MR refactor RedisCounter and WebIdeCommitsCounter to be reused by other components.
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb54
-rw-r--r--spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb21
2 files changed, 21 insertions, 54 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
deleted file mode 100644
index 38b4c22e186..00000000000
--- a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# 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/usage_data_counters/web_ide_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
new file mode 100644
index 00000000000..fa0cf15e1b2
--- /dev/null
+++ b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_state do
+ describe '.increment_commits_count' do
+ it 'increments the web ide commits counter by 1' do
+ expect do
+ described_class.increment_commits_count
+ end.to change { described_class.total_commits_count }.by(1)
+ end
+ end
+
+ describe '.total_commits_count' do
+ it 'returns the total amount of web ide commits' do
+ 2.times { described_class.increment_commits_count }
+
+ expect(described_class.total_commits_count).to eq(2)
+ end
+ end
+end