This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit e0cabb67 authored by ZJ van de Weg's avatar ZJ van de Weg
Browse files

Fix latests concerns

parent 6a155c962672
......@@ -7,7 +7,9 @@ module ToggleAwardEmoji
def toggle_award_emoji
name = params.require(:name)
awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(awardable, current_user)
render json: { ok: true }
end
......
......@@ -22,10 +22,8 @@ def index
def create
@note = Notes::CreateService.new(project, current_user, note_params).execute
@note = @note.is_a?(AwardEmoji) ? @note.to_note_json : note_json(@note)
respond_to do |format|
format.json { render json: @note }
format.json { render json: note_json(@note) }
format.html { redirect_back_or_default }
end
end
......@@ -109,7 +107,14 @@ def note_to_discussion_with_diff_html(note)
end
def note_json(note)
if note.valid?
if note.is_a?(AwardEmoji)
{
valid: note.valid?,
award: true,
id: note.id,
name: note.name
}
elsif note.valid?
{
valid: true,
id: note.id,
......
......@@ -23,13 +23,4 @@ def downvote?
def upvote?
self.name == UPVOTE_NAME
end
def to_note_json
{
valid: valid?,
award: true,
id: id,
name: name
}
end
end
......@@ -6,8 +6,10 @@ def execute
note.system = false
if note.award_emoji?
return ToggleAwardEmojiService.new(project, current_user, params).
execute(note.noteable, note.award_emoji_name)
noteable = note.noteable
todo_service.new_award_emoji(noteable, current_user)
return noteable.create_award_emoji(note.award_emoji_name, current_user)
end
return unless valid_project?(note)
......
require_relative 'base_service'
class ToggleAwardEmojiService < BaseService
def execute(awardable, emoji)
todo_service.new_award_emoji(awardable, current_user)
awardable.toggle_award_emoji(emoji, current_user)
end
end
......@@ -37,9 +37,9 @@
- note_count = merge_request.mr_and_commit_notes.user.count
%li
= link_to merge_request_path(merge_request, anchor: 'notes'), class: ('merge-request-no-comments' if note_count.zero?) do
= icon('comments')
= note_count
= link_to merge_request_path(merge_request, anchor: 'notes'), class: ('merge-request-no-comments' if note_count.zero?) do
= icon('comments')
= note_count
.merge-request-info
#{merge_request.to_reference} &middot;
......
......@@ -6,4 +6,3 @@
- if @merge_requests.present?
= paginate @merge_requests, theme: "gitlab"
......@@ -8,12 +8,12 @@
it 'excludes award_emoji from comment count' do
merge_request = create(:merge_request)
project = merge_request.source_project
create(:award_emoji, awardable: merge_request, project: project)
create(:award_emoji, awardable: merge_request)
login_as :admin
visit namespace_project_merge_requests_path(project.namespace, project)
expect(merge_request.mr_and_commit_notes.count).to eq 1
expect(merge_request.mr_and_commit_notes.count).to eq 0
expect(page.all('.merge-request-no-comments').first.text).to eq "0"
end
end
......@@ -146,11 +146,11 @@
describe 'comment info' do
it 'excludes award_emoji from comment count' do
create(:award_emoji, awardable: merge_request, project: project)
create(:award_emoji, awardable: merge_request)
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
expect(merge_request.mr_and_commit_notes.count).to eq 2
expect(merge_request.mr_and_commit_notes.count).to eq 1
expect(find('.notes-tab span.badge').text).to eq "1"
end
end
......
......@@ -59,7 +59,7 @@
noteable_id: issue.id
}
expect_any_instance_of(ToggleAwardEmojiService).to receive(:execute).with(issue, "thumbsup")
expect_any_instance_of(TodoService).to receive(:new_award_emoji).with(issue, user)
Notes::CreateService.new(project, user, opts).execute
end
......
require 'spec_helper'
describe ToggleAwardEmoji, services: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
before do
project.team << [user, :master]
end
describe '#execute' do
it 'removes related todos' do
expect_any_instance_of(TodoService).to receive(:new_award_emoji).with(issue, user)
ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsdown")
end
context 'when the emoji is set' do
it 'removes the emoji' do
create(:award_emoji, awardable: issue, user: user)
expect { ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsup") }.to change { AwardEmoji.count }.by(-1)
end
end
context 'when the award is not set yet' do
it 'awards the emoji' do
expect { ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsup") }.to change { AwardEmoji.count }.by(1)
end
end
end
end
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