rosa-build/spec/models/statistic_spec.rb

61 lines
1.9 KiB
Ruby
Raw Normal View History

2014-10-15 21:30:12 +01:00
require 'spec_helper'
describe Statistic do
before { stub_symlink_methods }
let(:statistic) { FactoryGirl.build(:statistic) }
context 'ensures that validations and associations exist' do
it { should belong_to(:project) }
it { should belong_to(:user) }
it { should validate_presence_of(:user_id) }
it { should validate_presence_of(:email) }
it { should validate_presence_of(:project_id) }
it { should validate_presence_of(:project_name_with_owner) }
it { should validate_presence_of(:key) }
it { should validate_presence_of(:counter) }
it { should validate_presence_of(:activity_at) }
it 'rejects duplicates' do
statistic.save
duplicate = statistic.dup
expect(duplicate).not_to be_valid
expect(duplicate.errors[:user_id]).to eq ['has already been taken']
end
end
context 'now_statsd_increment' do
it 'ensures that not raises error' do
lambda do
2.times {
Statistic.now_statsd_increment(
user_id: statistic.user_id,
project_id: statistic.project_id,
key: statistic.key,
activity_at: statistic.activity_at,
)
}
end.should_not raise_exception
2015-02-19 01:12:08 +00:00
expect(Statistic.count).to eq 1
2014-10-15 21:30:12 +01:00
expect(Statistic.first.counter).to eq 2
end
end
2014-10-22 21:23:38 +01:00
context '#for_groups' do
it 'returns projects by group ids' do
group1 = FactoryGirl.create(:group)
group2 = FactoryGirl.create(:group)
project1 = FactoryGirl.create(:project, owner: group1)
project2 = FactoryGirl.create(:project, owner: group2)
FactoryGirl.create(:statistic, project: project1)
FactoryGirl.create(:statistic, project: project2)
2015-02-19 01:12:08 +00:00
expect(Statistic.for_groups([group1.id]).count).to eq 1
expect(Statistic.for_groups([group1.id, group2]).count).to eq 2
2014-10-22 21:23:38 +01:00
end
end
2014-10-15 21:30:12 +01:00
end