2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2018-01-26 11:07:35 -05:00
|
|
|
|
2018-02-02 16:51:03 -05:00
|
|
|
describe UserCallout do
|
2018-12-03 07:43:34 -05:00
|
|
|
let!(:callout) { create(:user_callout) }
|
|
|
|
|
2018-12-04 05:24:21 -05:00
|
|
|
it_behaves_like 'having unique enum values'
|
|
|
|
|
2018-01-26 11:07:35 -05:00
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
end
|
2018-02-01 21:07:33 -05:00
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:feature_name) }
|
2018-02-02 18:16:24 -05:00
|
|
|
it { is_expected.to validate_uniqueness_of(:feature_name).scoped_to(:user_id).ignoring_case_sensitivity }
|
2018-02-01 21:07:33 -05:00
|
|
|
end
|
2020-02-06 13:08:54 -05:00
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
describe '.with_feature_name' do
|
|
|
|
let(:second_feature_name) { described_class.feature_names.keys.second }
|
|
|
|
let(:last_feature_name) { described_class.feature_names.keys.last }
|
|
|
|
|
|
|
|
it 'returns callout for requested feature name only' do
|
|
|
|
callout1 = create(:user_callout, feature_name: second_feature_name )
|
|
|
|
create(:user_callout, feature_name: last_feature_name )
|
|
|
|
|
|
|
|
callouts = described_class.with_feature_name(second_feature_name)
|
|
|
|
|
|
|
|
expect(callouts).to match_array([callout1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.with_dismissed_after' do
|
|
|
|
let(:some_feature_name) { described_class.feature_names.keys.second }
|
|
|
|
let(:callout_dismissed_month_ago) { create(:user_callout, feature_name: some_feature_name, dismissed_at: 1.month.ago )}
|
|
|
|
|
|
|
|
it 'does not return callouts dismissed before specified date' do
|
|
|
|
callouts = described_class.with_dismissed_after(15.days.ago)
|
|
|
|
|
|
|
|
expect(callouts).to match_array([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns callouts dismissed after specified date' do
|
|
|
|
callouts = described_class.with_dismissed_after(2.months.ago)
|
|
|
|
|
|
|
|
expect(callouts).to match_array([callout_dismissed_month_ago])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-26 11:07:35 -05:00
|
|
|
end
|