2014-04-28 05:48:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NotesFinder do
|
|
|
|
let(:user) { create :user }
|
|
|
|
let(:project) { create :project }
|
|
|
|
let(:note1) { create :note_on_commit, project: project }
|
|
|
|
let(:note2) { create :note_on_commit, project: project }
|
2014-04-28 05:50:05 -04:00
|
|
|
let(:commit) { note1.noteable }
|
2014-04-28 05:48:18 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#execute' do
|
2014-04-28 06:42:01 -04:00
|
|
|
let(:params) { { target_id: commit.id, target_type: 'commit', last_fetched_at: 1.hour.ago.to_i } }
|
2014-04-28 06:16:34 -04:00
|
|
|
|
2014-04-28 05:48:18 -04:00
|
|
|
before do
|
|
|
|
note1
|
|
|
|
note2
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'finds all notes' do
|
2014-04-28 05:48:18 -04:00
|
|
|
notes = NotesFinder.new.execute(project, user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(notes.size).to eq(2)
|
2014-04-28 05:48:18 -04:00
|
|
|
end
|
2014-04-28 05:53:37 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'raises an exception for an invalid target_type' do
|
2014-04-28 06:16:34 -04:00
|
|
|
params.merge!(target_type: 'invalid')
|
2014-04-28 05:53:37 -04:00
|
|
|
expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
|
|
|
|
end
|
2014-04-28 06:13:29 -04:00
|
|
|
|
|
|
|
it 'filters out old notes' do
|
|
|
|
note2.update_attribute(:updated_at, 2.hours.ago)
|
|
|
|
notes = NotesFinder.new.execute(project, user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(notes).to eq([note1])
|
2014-04-28 06:13:29 -04:00
|
|
|
end
|
2016-06-14 13:37:41 -04:00
|
|
|
|
|
|
|
context 'confidential issue notes' do
|
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project, author: user) }
|
|
|
|
let!(:confidential_note) { create(:note, noteable: confidential_issue, project: confidential_issue.project) }
|
|
|
|
|
|
|
|
let(:params) { { target_id: confidential_issue.id, target_type: 'issue', last_fetched_at: 1.hour.ago.to_i } }
|
|
|
|
|
|
|
|
it 'returns notes if user can see the issue' do
|
|
|
|
expect(NotesFinder.new.execute(project, user, params)).to eq([confidential_note])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error if user can not see the issue' do
|
|
|
|
user = create(:user)
|
|
|
|
expect { NotesFinder.new.execute(project, user, params) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2016-06-14 21:13:58 -04:00
|
|
|
|
|
|
|
it 'raises an error for project members with guest role' do
|
|
|
|
user = create(:user)
|
|
|
|
project.team << [user, :guest]
|
|
|
|
|
|
|
|
expect { NotesFinder.new.execute(project, user, params) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2016-06-14 13:37:41 -04:00
|
|
|
end
|
2014-04-28 05:48:18 -04:00
|
|
|
end
|
|
|
|
end
|