diff options
author | Rémy Coutable <remy@rymai.me> | 2016-10-25 16:28:10 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-10-25 16:28:10 +0000 |
commit | 774548be1fbc88041d58a2e66e19971e6f678d4c (patch) | |
tree | b8447989c7c512fce9cdf68c95af8ff921aba1f4 | |
parent | 6fc544968b882b62c706fb82f3b951a27bd18eb2 (diff) | |
parent | 05084a456596c7ebf853f2963551ea5475b34928 (diff) | |
download | gitlab-ce-774548be1fbc88041d58a2e66e19971e6f678d4c.tar.gz |
Merge branch 'fix-events-api' into 'master'
Fix events order in users/:id/events endpoint
## What does this MR do?
Order of events in contributions API is currently being lost, though docs are saying:
> Get the contribution events for the specified user, sorted **from newest to oldest**.
Order becomes different after `.merge(ProjectsFinder.new.execute(current_user))` call, so I moved ordering below this line.
This MR also removes extra `.page(params[:page])` call in the method chain, since [`paginate(events)` already does it](https://gitlab.com/airat/gitlab-ce/blob/master/lib/api/helpers.rb#L112).
See merge request !7039
-rw-r--r-- | lib/api/users.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb index e868f628404..c28e07a76b7 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -333,11 +333,11 @@ module API user = User.find_by(id: declared(params).id) not_found!('User') unless user - events = user.recent_events. + events = user.events. merge(ProjectsFinder.new.execute(current_user)). references(:project). with_associations. - page(params[:page]) + recent present paginate(events), with: Entities::Event end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index d48752473f3..ae8639d78d5 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -958,6 +958,29 @@ describe API::API, api: true do expect(joined_event['author']['name']).to eq(user.name) end end + + context 'when there are multiple events from different projects' do + let(:second_note) { create(:note_on_issue, project: create(:empty_project)) } + let(:third_note) { create(:note_on_issue, project: project) } + + before do + second_note.project.add_user(user, :developer) + + [second_note, third_note].each do |note| + EventCreateService.new.leave_note(note, user) + end + end + + it 'returns events in the correct order (from newest to oldest)' do + get api("/users/#{user.id}/events", user) + + comment_events = json_response.select { |e| e['action_name'] == 'commented on' } + + expect(comment_events[0]['target_id']).to eq(third_note.id) + expect(comment_events[1]['target_id']).to eq(second_note.id) + expect(comment_events[2]['target_id']).to eq(note.id) + end + end end it 'returns a 404 error if not found' do |