Commit 6c89e2fd authored by Fatih Acet's avatar Fatih Acet

Merge branch 'awardables' of gitlab.com:gitlab-org/gitlab-ce into awardables

parents a410c7af e0cabb67
...@@ -7,7 +7,9 @@ module ToggleAwardEmoji ...@@ -7,7 +7,9 @@ module ToggleAwardEmoji
def toggle_award_emoji def toggle_award_emoji
name = params.require(:name) name = params.require(:name)
awardable.toggle_award_emoji(name, current_user) awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(awardable, current_user)
render json: { ok: true } render json: { ok: true }
end end
......
...@@ -22,10 +22,8 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -22,10 +22,8 @@ class Projects::NotesController < Projects::ApplicationController
def create def create
@note = Notes::CreateService.new(project, current_user, note_params).execute @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| respond_to do |format|
format.json { render json: @note } format.json { render json: note_json(@note) }
format.html { redirect_back_or_default } format.html { redirect_back_or_default }
end end
end end
...@@ -109,7 +107,14 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -109,7 +107,14 @@ class Projects::NotesController < Projects::ApplicationController
end end
def note_json(note) 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, valid: true,
id: note.id, id: note.id,
......
...@@ -23,13 +23,4 @@ class AwardEmoji < ActiveRecord::Base ...@@ -23,13 +23,4 @@ class AwardEmoji < ActiveRecord::Base
def upvote? def upvote?
self.name == UPVOTE_NAME self.name == UPVOTE_NAME
end end
def to_note_json
{
valid: valid?,
award: true,
id: id,
name: name
}
end
end end
...@@ -6,8 +6,10 @@ module Notes ...@@ -6,8 +6,10 @@ module Notes
note.system = false note.system = false
if note.award_emoji? if note.award_emoji?
return ToggleAwardEmojiService.new(project, current_user, params). noteable = note.noteable
execute(note.noteable, note.award_emoji_name) todo_service.new_award_emoji(noteable, current_user)
return noteable.create_award_emoji(note.award_emoji_name, current_user)
end end
return unless valid_project?(note) 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
...@@ -6,4 +6,3 @@ ...@@ -6,4 +6,3 @@
- if @merge_requests.present? - if @merge_requests.present?
= paginate @merge_requests, theme: "gitlab" = paginate @merge_requests, theme: "gitlab"
...@@ -8,12 +8,12 @@ describe 'Comments', feature: true do ...@@ -8,12 +8,12 @@ describe 'Comments', feature: true do
it 'excludes award_emoji from comment count' do it 'excludes award_emoji from comment count' do
merge_request = create(:merge_request) merge_request = create(:merge_request)
project = merge_request.source_project project = merge_request.source_project
create(:award_emoji, awardable: merge_request, project: project) create(:award_emoji, awardable: merge_request)
login_as :admin login_as :admin
visit namespace_project_merge_requests_path(project.namespace, project) 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" expect(page.all('.merge-request-no-comments').first.text).to eq "0"
end end
end end
...@@ -146,11 +146,11 @@ describe 'Comments', feature: true do ...@@ -146,11 +146,11 @@ describe 'Comments', feature: true do
describe 'comment info' do describe 'comment info' do
it 'excludes award_emoji from comment count' 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) 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" expect(find('.notes-tab span.badge').text).to eq "1"
end end
end end
......
...@@ -59,7 +59,7 @@ describe Notes::CreateService, services: true do ...@@ -59,7 +59,7 @@ describe Notes::CreateService, services: true do
noteable_id: issue.id 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 Notes::CreateService.new(project, user, opts).execute
end 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