2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-23 14:33:16 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe UserInteractedProject do
|
2018-02-23 14:33:16 -05:00
|
|
|
describe '.track' do
|
|
|
|
subject { described_class.track(event) }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-02-23 14:33:16 -05:00
|
|
|
let(:event) { build(:event) }
|
|
|
|
|
2020-05-28 11:08:02 -04:00
|
|
|
Event.actions.each_key do |action|
|
2018-02-23 14:33:16 -05:00
|
|
|
context "for all actions (event types)" do
|
|
|
|
let(:event) { build(:event, action: action) }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2018-02-23 14:33:16 -05:00
|
|
|
it 'creates a record' do
|
2018-02-26 06:24:02 -05:00
|
|
|
expect { subject }.to change { described_class.count }.from(0).to(1)
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets project accordingly' do
|
2018-02-23 14:56:43 -05:00
|
|
|
subject
|
2018-02-26 06:24:02 -05:00
|
|
|
expect(described_class.first.project).to eq(event.project)
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets user accordingly' do
|
2018-02-23 14:56:43 -05:00
|
|
|
subject
|
2018-02-26 06:24:02 -05:00
|
|
|
expect(described_class.first.user).to eq(event.author)
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'only creates a record once per user/project' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
described_class.track(event)
|
2018-02-26 06:24:02 -05:00
|
|
|
end.to change { described_class.count }.from(0).to(1)
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|
2018-02-23 15:24:11 -05:00
|
|
|
|
|
|
|
describe 'with an event without a project' do
|
|
|
|
let(:event) { build(:event, project: nil) }
|
|
|
|
|
|
|
|
it 'ignores the event' do
|
2018-02-26 06:24:02 -05:00
|
|
|
expect { subject }.not_to change { described_class.count }
|
2018-02-23 15:24:11 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|
|
|
|
|
2018-03-05 10:50:05 -05:00
|
|
|
it { is_expected.to validate_presence_of(:project_id) }
|
|
|
|
it { is_expected.to validate_presence_of(:user_id) }
|
2018-02-23 14:33:16 -05:00
|
|
|
end
|