debian-mirror-gitlab/spec/models/user_interacted_project_spec.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe UserInteractedProject do
2020-11-24 15:15:51 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:author) { project.creator }
2018-03-27 19:54:05 +05:30
describe '.track' do
subject { described_class.track(event) }
2019-12-21 20:55:43 +05:30
2020-11-24 15:15:51 +05:30
let(:event) { build(:event, project: project, author: author) }
2018-03-27 19:54:05 +05:30
2020-06-23 00:09:42 +05:30
Event.actions.each_key do |action|
2018-03-27 19:54:05 +05:30
context "for all actions (event types)" do
2020-11-24 15:15:51 +05:30
let(:event) { build(:event, project: project, author: author, action: action) }
2020-03-13 15:44:24 +05:30
2018-03-27 19:54:05 +05:30
it 'creates a record' do
expect { subject }.to change { described_class.count }.from(0).to(1)
end
end
end
it 'sets project accordingly' do
subject
expect(described_class.first.project).to eq(event.project)
end
it 'sets user accordingly' do
subject
expect(described_class.first.user).to eq(event.author)
end
it 'only creates a record once per user/project' do
expect do
subject
described_class.track(event)
end.to change { described_class.count }.from(0).to(1)
end
describe 'with an event without a project' do
let(:event) { build(:event, project: nil) }
it 'ignores the event' do
expect { subject }.not_to change { described_class.count }
end
end
end
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:user_id) }
end