BigW Consortium Gitlab

notes_finder_spec.rb 1.03 KB
Newer Older
Jacob Vosmaer committed
1 2 3 4 5 6 7
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 }
8
  let(:commit) { note1.noteable }
Jacob Vosmaer committed
9 10 11 12 13 14

  before do
    project.team << [user, :master]
  end

  describe :execute do
15
    let(:params)  { { target_id: commit.id, target_type: 'commit', last_fetched_at: 1.hour.ago.to_i } }
16

Jacob Vosmaer committed
17 18 19 20 21 22 23
    before do
      note1
      note2
    end

    it 'should find all notes' do
      notes = NotesFinder.new.execute(project, user, params)
24
      expect(notes.size).to eq(2)
Jacob Vosmaer committed
25
    end
26 27

    it 'should raise an exception for an invalid target_type' do
28
      params.merge!(target_type: 'invalid')
29 30
      expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
    end
31 32 33 34

    it 'filters out old notes' do
      note2.update_attribute(:updated_at, 2.hours.ago)
      notes = NotesFinder.new.execute(project, user, params)
35
      expect(notes).to eq([note1])
36
    end
Jacob Vosmaer committed
37 38
  end
end