Commit e8dd0d54 authored by Z.J. van de Weg's avatar Z.J. van de Weg Committed by Fatih Acet

Fix tests for Snippets toggling awards

Also incorporate feedback
parent 412ff80b
......@@ -42,6 +42,7 @@ v 8.12.0 (unreleased)
- Move parsing of sidekiq ps into helper !6245 (pascalbetz)
- Added go to issue boards keyboard shortcut
- Expose `sha` and `merge_commit_sha` in merge request API (Ben Boeckel)
- Emoji can be awarded on Snippets !4456
- Set path for all JavaScript cookies to honor GitLab's subdirectory setting !5627 (Mike Greiling)
- Fix blame table layout width
- Fix bug where pagination is still displayed despite all todos marked as done (ClemMakesApps)
......@@ -281,7 +282,6 @@ v 8.11.0
- Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission
- API: Add enpoints for pipelines
- Emoji can be awarded on Snippets !4456
- Add green outline to New Branch button. !5447 (winniehell)
- Optimize generating of cache keys for issues and notes
- Fix repository push email formatting in Outlook
......
module AwardEmojiHelper
def toggle_award_url(awardable)
unless awardable.is_a?(Snippet)
return url_for([:toggle_award_emoji, @project.namespace.becomes(Namespace), @project, awardable])
end
if awardable.is_a?(ProjectSnippet)
toggle_award_emoji_namespace_project_snippet_path(@project.namespace.becomes(Namespace), @project, awardable)
if @project
url_for([:toggle_award_emoji, @project.namespace.becomes(Namespace), @project, awardable])
else
toggle_award_emoji_snippet_url(awardable)
url_for([:toggle_award_emoji, awardable])
end
end
end
......@@ -98,6 +98,14 @@ module GitlabRoutingHelper
end
end
def toggle_award_emoji_personal_snippet_path(*args)
toggle_award_emoji_snippet_path(*args)
end
def toggle_award_emoji_namespace_project_project_snippet_path(*args)
toggle_award_emoji_namespace_project_snippet_path(*args)
end
## Members
def project_members_url(project, *args)
namespace_project_project_members_url(project.namespace, project)
......
# Award Emoji
> [Introduced][ce-4575] in GitLab 8.9, Snippet support in 8.11
> [Introduced][ce-4575] in GitLab 8.9, Snippet support in 8.12
An awarded emoji tells a thousand words, and can be awarded on issues, merge
......@@ -76,7 +76,7 @@ Gets a single award emoji from an issue, snippet, or merge request.
```
GET /projects/:id/issues/:issue_id/award_emoji/:award_id
GET /projects/:id/merge_requests/:merge_request_id/award_emoji/:award_id
GET /projects/:id/snippets/:snippets_id/award_emoji/:award_id
GET /projects/:id/snippets/:snippet_id/award_emoji/:award_id
```
Parameters:
......@@ -119,7 +119,7 @@ This end point creates an award emoji on the specified resource
```
POST /projects/:id/issues/:issue_id/award_emoji
POST /projects/:id/merge_requests/:merge_request_id/award_emoji
POST /projects/:id/snippets/:snippets_id/award_emoji
POST /projects/:id/snippets/:snippet_id/award_emoji
```
Parameters:
......
module API
class AwardEmoji < Grape::API
before { authenticate! }
AWARDABLES = [Issue, MergeRequest, Snippet]
AWARDABLES = %w[issue merge_request snippet]
resource :projects do
AWARDABLES.each do |awardable_type|
awardable_string = awardable_type.to_s.underscore.pluralize
awardable_id_string = "#{awardable_type.to_s.underscore}_id"
awardable_string = awardable_type.pluralize
awardable_id_string = "#{awardable_type}_id"
[ ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji",
":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji"
......@@ -87,7 +87,7 @@ module API
helpers do
def can_read_awardable?
can?(current_user, ability_name(awardable), awardable)
can?(current_user, read_ability(awardable), awardable)
end
def can_award_awardable?
......@@ -98,8 +98,7 @@ module API
@awardable ||=
begin
if params.include?(:note_id)
note_id = params[:note_id]
params.delete(:note_id)
note_id = params.delete(:note_id)
awardable.notes.find(note_id)
elsif params.include?(:issue_id)
......@@ -112,16 +111,12 @@ module API
end
end
def ability_name(awardable)
def read_ability(awardable)
case awardable
when Note
ability_name(awardable.noteable)
when Snippet
:read_project_snippet
when MergeRequest
:read_merge_request
when Issue
:read_issue
read_ability(awardable.noteable)
else
:"read_#{awardable.class.to_s.underscore}"
end
end
end
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -232,26 +232,28 @@ describe SnippetsController do
end
context 'award emoji on snippets' do
let(:personal_snippet) { create(:personal_snippet, :private, author: user) }
let(:personal_snippet) { create(:personal_snippet, :public, author: user) }
let(:another_user) { create(:user) }
before do
sign_in(user)
sign_in(another_user)
end
describe 'POST #toggle_award_emoji' do
it "toggles the award emoji" do
expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
end.to change { personal_snippet.award_emoji.count }.by(1)
end.to change { personal_snippet.award_emoji.count }.from(0).to(1)
expect(response.status).to eq(200)
end
it "removes the already awarded emoji" do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
end.to change { personal_snippet.award_emoji.count }.by(-1)
end.to change { personal_snippet.award_emoji.count }.from(1).to(0)
expect(response.status).to eq(200)
end
......
......@@ -3,8 +3,8 @@ require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project) }
let(:issue) { create(:issue, project: project, author: user) }
let!(:project) { create(:empty_project) }
let(:issue) { create(:issue, project: project) }
let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment