diff options
Diffstat (limited to 'spec/models/users_statistics_spec.rb')
-rw-r--r-- | spec/models/users_statistics_spec.rb | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/spec/models/users_statistics_spec.rb b/spec/models/users_statistics_spec.rb index fc23bed711f..4437a5469c6 100644 --- a/spec/models/users_statistics_spec.rb +++ b/spec/models/users_statistics_spec.rb @@ -2,7 +2,36 @@ require 'spec_helper' -RSpec.describe UsersStatistics do +describe UsersStatistics do + let(:users_statistics) { build(:users_statistics) } + + describe 'scopes' do + describe '.order_created_at_desc' do + it 'returns the entries ordered by created at descending' do + users_statistics1 = create(:users_statistics, created_at: Time.current) + users_statistics2 = create(:users_statistics, created_at: Time.current - 2.days) + users_statistics3 = create(:users_statistics, created_at: Time.current - 5.hours) + + expect(described_class.order_created_at_desc).to eq( + [ + users_statistics1, + users_statistics3, + users_statistics2 + ] + ) + end + end + end + + describe '.latest' do + it 'returns the latest entry' do + create(:users_statistics, created_at: Time.current - 1.day) + users_statistics = create(:users_statistics, created_at: Time.current) + + expect(described_class.latest).to eq(users_statistics) + end + end + describe '.create_current_stats!' do before do create_list(:user_highest_role, 4) @@ -40,4 +69,16 @@ RSpec.describe UsersStatistics do end end end + + describe '#active' do + it 'sums users statistics values without the value for blocked' do + expect(users_statistics.active).to eq(71) + end + end + + describe '#total' do + it 'sums all users statistics values' do + expect(users_statistics.total).to eq(78) + end + end end |