2018-10-26 08:49:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
describe Boards::VisitsFinder do
|
|
|
|
describe '#latest' do
|
2018-10-26 08:49:16 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'when a project board' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:project_board) { create(:board, project: project) }
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
subject(:finder) { described_class.new(project_board.parent, user) }
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
it 'returns nil when there is no user' do
|
2019-06-17 08:58:48 -04:00
|
|
|
finder.current_user = nil
|
2018-10-26 08:49:16 -04:00
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
expect(finder.execute).to eq nil
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries for most recent visit' do
|
|
|
|
expect(BoardProjectRecentVisit).to receive(:latest).once
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
finder.execute
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
2019-02-27 08:08:48 -05:00
|
|
|
|
|
|
|
it 'queries for last N visits' do
|
|
|
|
expect(BoardProjectRecentVisit).to receive(:latest).with(user, project, count: 5).once
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
described_class.new(project_board.parent, user).latest(5)
|
2019-02-27 08:08:48 -05:00
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a group board' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_board) { create(:board, group: group) }
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
subject(:finder) { described_class.new(group_board.parent, user) }
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
it 'returns nil when there is no user' do
|
2019-06-17 08:58:48 -04:00
|
|
|
finder.current_user = nil
|
2018-10-26 08:49:16 -04:00
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
expect(finder.execute).to eq nil
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries for most recent visit' do
|
|
|
|
expect(BoardGroupRecentVisit).to receive(:latest).once
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
finder.latest
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
2019-02-27 08:08:48 -05:00
|
|
|
|
|
|
|
it 'queries for last N visits' do
|
|
|
|
expect(BoardGroupRecentVisit).to receive(:latest).with(user, group, count: 5).once
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
described_class.new(group_board.parent, user).latest(5)
|
2019-02-27 08:08:48 -05:00
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|