diff options
author | Airat Shigapov <contact@airatshigapov.com> | 2016-10-23 19:00:03 +0300 |
---|---|---|
committer | Airat Shigapov <contact@airatshigapov.com> | 2016-10-24 22:56:28 +0300 |
commit | ae099857b00c8d9ed48397b782ac6410114183a6 (patch) | |
tree | a36b96f468627665fde51131331386110870075c /spec/requests/api/users_spec.rb | |
parent | e15f15d5a8fe91746a7c0a038d16a99d682c1b22 (diff) |
Rewrite events order spec to simulate wrong order without changing ids
Diffstat (limited to 'spec/requests/api/users_spec.rb')
-rw-r--r-- | spec/requests/api/users_spec.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index e911cedb522..f07460bbc25 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -959,23 +959,24 @@ describe API::API, api: true do end end - context 'when there are multiple events' do - let(:old_note) { create(:note_on_issue, project: project) } - let(:new_event) { note.events.first } - let(:old_event) { old_note.events.first } + context 'when there are multiple events from different projects' do + let(:another_project) { create(:empty_project) } + let(:notes) { create_list(:note_on_issue, 5, project: [project, another_project].sample) } before do - EventCreateService.new.leave_note(old_note, user) + another_project.add_user(user, :developer) - new_event.update(id: 1000) - old_event.update(id: 900) + notes.each { |note| EventCreateService.new.leave_note(note, user) } end it 'returns them in the correct order (from newest to oldest determined by ID field)' do get api("/users/#{user.id}/events", user) - expect(json_response[0]['target_id']).to eq(note.id) - expect(json_response[1]['target_id']).to eq(old_note.id) + comment_events = json_response.select { |e| e['action_name'] == 'commented on' } + + notes.reverse.each_with_index do |note, i| + expect(note.id).to eq(comment_events[i]['target_id']) + end end end end |