Commit ee626520 authored by Ruben Davila's avatar Ruben Davila

Don't track historical data when there isn't a license or it's trial

parent 43a570dc
......@@ -203,6 +203,10 @@ class License < ActiveRecord::Base
restricted_attr(:trueup_to)].all?(&:present?)
end
def trial?
restricted_attr(:trial)
end
private
def restricted_attr(name, default = nil)
......
......@@ -4,6 +4,8 @@ class HistoricalDataWorker
def perform
return if Gitlab::Geo.secondary?
return if License.current.nil? || License.current&.trial?
HistoricalData.track!
end
end
......@@ -15,9 +15,19 @@ FactoryGirl.define do
end
notify_users_at { |l| l.expires_at }
notify_admins_at { |l| l.expires_at }
trait :trial do
restrictions do
{ trial: true }
end
end
end
factory :license do
data { build(:gitlab_license).export }
end
factory :trial_license, class: License do
data { build(:gitlab_license, :trial).export }
end
end
require 'spec_helper'
describe HistoricalDataWorker do
subject { described_class.new }
describe '#perform' do
context 'with a trial license' do
before do
FactoryGirl.create(:trial_license)
end
it 'does not track historical data' do
expect(HistoricalData).not_to receive(:track!)
subject.perform
end
end
context 'with a non trial license' do
before do
FactoryGirl.create(:license)
end
it 'tracks historical data' do
expect(HistoricalData).to receive(:track!)
subject.perform
end
end
context 'with a Geo secondary node' do
it 'does not track historical data' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
expect(HistoricalData).not_to receive(:track!)
subject.perform
end
end
context 'when there is not a license key' do
it 'does not track historical data' do
License.destroy_all
expect(HistoricalData).not_to receive(:track!)
subject.perform
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment