diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/models/product_analytics_event_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/models/product_analytics_event_spec.rb')
-rw-r--r-- | spec/models/product_analytics_event_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/models/product_analytics_event_spec.rb b/spec/models/product_analytics_event_spec.rb new file mode 100644 index 00000000000..6058df9fa13 --- /dev/null +++ b/spec/models/product_analytics_event_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ProductAnalyticsEvent, type: :model do + it { is_expected.to belong_to(:project) } + it { expect(described_class).to respond_to(:order_by_time) } + + describe 'validations' do + it { is_expected.to validate_presence_of(:project_id) } + it { is_expected.to validate_presence_of(:event_id) } + it { is_expected.to validate_presence_of(:v_collector) } + it { is_expected.to validate_presence_of(:v_etl) } + end + + describe '.timerange' do + let_it_be(:event_1) { create(:product_analytics_event, collector_tstamp: Time.zone.now - 1.day) } + let_it_be(:event_2) { create(:product_analytics_event, collector_tstamp: Time.zone.now - 5.days) } + let_it_be(:event_3) { create(:product_analytics_event, collector_tstamp: Time.zone.now - 15.days) } + + it { expect(described_class.timerange(3.days)).to match_array([event_1]) } + it { expect(described_class.timerange(7.days)).to match_array([event_1, event_2]) } + it { expect(described_class.timerange(30.days)).to match_array([event_1, event_2, event_3]) } + end +end |