summaryrefslogtreecommitdiff
path: root/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb')
-rw-r--r--spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb b/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb
new file mode 100644
index 00000000000..ffddaf1e1b2
--- /dev/null
+++ b/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Analytics::CycleAnalytics::StageEventHash, type: :model do
+ let(:stage_event_hash) { described_class.create!(hash_sha256: hash_sha256) }
+ let(:hash_sha256) { 'does_not_matter' }
+
+ describe 'associations' do
+ it { is_expected.to have_many(:cycle_analytics_project_stages) }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of(:hash_sha256) }
+ end
+
+ describe '.record_id_by_hash_sha256' do
+ it 'returns an existing id' do
+ id = stage_event_hash.id
+ same_id = described_class.record_id_by_hash_sha256(hash_sha256)
+
+ expect(same_id).to eq(id)
+ end
+
+ it 'creates a new record' do
+ expect do
+ described_class.record_id_by_hash_sha256(hash_sha256)
+ end.to change { described_class.count }.from(0).to(1)
+ end
+ end
+
+ describe '.cleanup_if_unused' do
+ it 'removes the record' do
+ described_class.cleanup_if_unused(stage_event_hash.id)
+
+ expect(described_class.find_by_id(stage_event_hash.id)).to be_nil
+ end
+
+ it 'does not remove the record' do
+ id = create(:cycle_analytics_project_stage).stage_event_hash_id
+
+ described_class.cleanup_if_unused(id)
+
+ expect(described_class.find_by_id(id)).not_to be_nil
+ end
+ end
+end