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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'should find all notes' do
|
|
|
|
notes = NotesFinder.new.execute(project, user, params)
|
|
|
|
notes.size.should eq(2)
|
|
|
|
end
|
2014-04-28 05:53:37 -04:00
|
|
|
|
|
|
|
it 'should raise 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)
|
|
|
|
notes.should eq([note1])
|
|
|
|
end
|
2014-04-28 05:48:18 -04:00
|
|
|
end
|
|
|
|
end
|