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) ...@@ -42,6 +42,7 @@ v 8.12.0 (unreleased)
- Move parsing of sidekiq ps into helper !6245 (pascalbetz) - Move parsing of sidekiq ps into helper !6245 (pascalbetz)
- Added go to issue boards keyboard shortcut - Added go to issue boards keyboard shortcut
- Expose `sha` and `merge_commit_sha` in merge request API (Ben Boeckel) - 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) - Set path for all JavaScript cookies to honor GitLab's subdirectory setting !5627 (Mike Greiling)
- Fix blame table layout width - Fix blame table layout width
- Fix bug where pagination is still displayed despite all todos marked as done (ClemMakesApps) - Fix bug where pagination is still displayed despite all todos marked as done (ClemMakesApps)
...@@ -281,7 +282,6 @@ v 8.11.0 ...@@ -281,7 +282,6 @@ v 8.11.0
- Clean up unused routes (Josef Strzibny) - Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission - Fix issue on empty project to allow developers to only push to protected branches if given permission
- API: Add enpoints for pipelines - API: Add enpoints for pipelines
- Emoji can be awarded on Snippets !4456
- Add green outline to New Branch button. !5447 (winniehell) - Add green outline to New Branch button. !5447 (winniehell)
- Optimize generating of cache keys for issues and notes - Optimize generating of cache keys for issues and notes
- Fix repository push email formatting in Outlook - Fix repository push email formatting in Outlook
......
module AwardEmojiHelper module AwardEmojiHelper
def toggle_award_url(awardable) def toggle_award_url(awardable)
unless awardable.is_a?(Snippet) if @project
return url_for([:toggle_award_emoji, @project.namespace.becomes(Namespace), @project, awardable]) 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)
else else
toggle_award_emoji_snippet_url(awardable) url_for([:toggle_award_emoji, awardable])
end end
end end
end end
...@@ -98,6 +98,14 @@ module GitlabRoutingHelper ...@@ -98,6 +98,14 @@ module GitlabRoutingHelper
end end
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 ## Members
def project_members_url(project, *args) def project_members_url(project, *args)
namespace_project_project_members_url(project.namespace, project) namespace_project_project_members_url(project.namespace, project)
......
# Award Emoji # 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 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. ...@@ -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/issues/:issue_id/award_emoji/:award_id
GET /projects/:id/merge_requests/:merge_request_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: Parameters:
...@@ -119,7 +119,7 @@ This end point creates an award emoji on the specified resource ...@@ -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/issues/:issue_id/award_emoji
POST /projects/:id/merge_requests/:merge_request_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: Parameters:
......
module API module API
class AwardEmoji < Grape::API class AwardEmoji < Grape::API
before { authenticate! } before { authenticate! }
AWARDABLES = [Issue, MergeRequest, Snippet] AWARDABLES = %w[issue merge_request snippet]
resource :projects do resource :projects do
AWARDABLES.each do |awardable_type| AWARDABLES.each do |awardable_type|
awardable_string = awardable_type.to_s.underscore.pluralize awardable_string = awardable_type.pluralize
awardable_id_string = "#{awardable_type.to_s.underscore}_id" awardable_id_string = "#{awardable_type}_id"
[ ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji", [ ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji",
":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji" ":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji"
...@@ -87,7 +87,7 @@ module API ...@@ -87,7 +87,7 @@ module API
helpers do helpers do
def can_read_awardable? def can_read_awardable?
can?(current_user, ability_name(awardable), awardable) can?(current_user, read_ability(awardable), awardable)
end end
def can_award_awardable? def can_award_awardable?
...@@ -98,8 +98,7 @@ module API ...@@ -98,8 +98,7 @@ module API
@awardable ||= @awardable ||=
begin begin
if params.include?(:note_id) if params.include?(:note_id)
note_id = params[:note_id] note_id = params.delete(:note_id)
params.delete(:note_id)
awardable.notes.find(note_id) awardable.notes.find(note_id)
elsif params.include?(:issue_id) elsif params.include?(:issue_id)
...@@ -112,16 +111,12 @@ module API ...@@ -112,16 +111,12 @@ module API
end end
end end
def ability_name(awardable) def read_ability(awardable)
case awardable case awardable
when Note when Note
ability_name(awardable.noteable) read_ability(awardable.noteable)
when Snippet else
:read_project_snippet :"read_#{awardable.class.to_s.underscore}"
when MergeRequest
:read_merge_request
when Issue
:read_issue
end end
end 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 ...@@ -232,26 +232,28 @@ describe SnippetsController do
end end
context 'award emoji on snippets' do 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 before do
sign_in(user) sign_in(another_user)
end end
describe 'POST #toggle_award_emoji' do describe 'POST #toggle_award_emoji' do
it "toggles the award emoji" do it "toggles the award emoji" do
expect do expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup") 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) expect(response.status).to eq(200)
end end
it "removes the already awarded emoji" do it "removes the already awarded emoji" do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup") post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup")
expect do expect do
post(:toggle_award_emoji, id: personal_snippet.to_param, name: "thumbsup") 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) expect(response.status).to eq(200)
end end
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe API::API, api: true do describe API::API, api: true do
include ApiHelpers include ApiHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project) } let!(:project) { create(:empty_project) }
let(:issue) { create(:issue, project: project, author: user) } let(:issue) { create(:issue, project: project) }
let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } 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