debian-mirror-gitlab/spec/finders/notes_finder_spec.rb

62 lines
2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
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 }
let(:commit) { note1.noteable }
before do
project.team << [user, :master]
end
2016-08-24 12:49:21 +05:30
describe '#execute' do
2014-09-02 18:07:02 +05:30
let(:params) { { target_id: commit.id, target_type: 'commit', last_fetched_at: 1.hour.ago.to_i } }
before do
note1
note2
end
2016-09-13 17:45:13 +05:30
it 'finds all notes' do
2014-09-02 18:07:02 +05:30
notes = NotesFinder.new.execute(project, user, params)
2015-04-26 12:48:37 +05:30
expect(notes.size).to eq(2)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'raises an exception for an invalid target_type' do
2014-09-02 18:07:02 +05:30
params.merge!(target_type: 'invalid')
expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
end
it 'filters out old notes' do
note2.update_attribute(:updated_at, 2.hours.ago)
notes = NotesFinder.new.execute(project, user, params)
2015-04-26 12:48:37 +05:30
expect(notes).to eq([note1])
2014-09-02 18:07:02 +05:30
end
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-08-24 12:49:21 +05:30
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
end
2014-09-02 18:07:02 +05:30
end
end