Backend awardables on comments
This commit is contained in:
parent
fc809d689a
commit
2f9c2149a3
6 changed files with 61 additions and 2 deletions
|
@ -162,7 +162,7 @@ class @Notes
|
|||
renderNote: (note) ->
|
||||
unless note.valid
|
||||
if note.award
|
||||
flash = new Flash('You have already used this award emoji!', 'alert')
|
||||
flash = new Flash('You have already awarded this emoji!', 'alert')
|
||||
flash.pinTo('.header-content')
|
||||
return
|
||||
|
||||
|
|
|
@ -9,13 +9,22 @@ module ToggleAwardEmoji
|
|||
name = params.require(:name)
|
||||
|
||||
awardable.toggle_award_emoji(name, current_user)
|
||||
TodoService.new.new_award_emoji(awardable, current_user)
|
||||
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
|
||||
|
||||
render json: { ok: true }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def to_todoable(awardable)
|
||||
case awardable
|
||||
when Note
|
||||
awardable.noteable
|
||||
else
|
||||
awardable
|
||||
end
|
||||
end
|
||||
|
||||
def awardable
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Projects::NotesController < Projects::ApplicationController
|
||||
include ToggleAwardEmoji
|
||||
|
||||
# Authorize
|
||||
before_action :authorize_read_note!
|
||||
before_action :authorize_create_note!, only: [:create]
|
||||
|
@ -61,6 +63,7 @@ class Projects::NotesController < Projects::ApplicationController
|
|||
def note
|
||||
@note ||= @project.notes.find(params[:id])
|
||||
end
|
||||
alias_method :awardable, :note
|
||||
|
||||
def note_to_html(note)
|
||||
render_to_string(
|
||||
|
|
|
@ -3,6 +3,7 @@ class Note < ActiveRecord::Base
|
|||
include Gitlab::CurrentSettings
|
||||
include Participable
|
||||
include Mentionable
|
||||
include Awardable
|
||||
|
||||
default_value_for :system, false
|
||||
|
||||
|
|
36
spec/controllers/projects/notes_controller_spec.rb
Normal file
36
spec/controllers/projects/notes_controller_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require('spec_helper')
|
||||
|
||||
describe Projects::NotesController do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:project) }
|
||||
let(:issue) { create(:issue, project: project) }
|
||||
let(:note) { create(:note, noteable: issue, project: project) }
|
||||
|
||||
describe 'POST #toggle_award_emoji' do
|
||||
before do
|
||||
sign_in(user)
|
||||
project.team << [user, :developer]
|
||||
end
|
||||
|
||||
it "toggles the award emoji" do
|
||||
expect do
|
||||
post(:toggle_award_emoji, namespace_id: project.namespace.path,
|
||||
project_id: project.path, id: note.id, name: "thumbsup")
|
||||
end.to change { AwardEmoji.count }.by(1)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "removes the already let award emoji" do
|
||||
post(:toggle_award_emoji, namespace_id: project.namespace.path,
|
||||
project_id: project.path, id: note.id, name: "thumbsup")
|
||||
|
||||
expect do
|
||||
post(:toggle_award_emoji, namespace_id: project.namespace.path,
|
||||
project_id: project.path, id: note.id, name: "thumbsup")
|
||||
end.to change { AwardEmoji.count }.by(-1)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,16 @@ describe Note, models: true do
|
|||
it { is_expected.to have_many(:todos).dependent(:destroy) }
|
||||
end
|
||||
|
||||
describe 'modules' do
|
||||
subject { described_class }
|
||||
|
||||
it { is_expected.to include_module(Participable) }
|
||||
it { is_expected.to include_module(Mentionable) }
|
||||
it { is_expected.to include_module(Awardable) }
|
||||
|
||||
it { is_expected.to include_module(Gitlab::CurrentSettings) }
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
it { is_expected.to validate_presence_of(:note) }
|
||||
it { is_expected.to validate_presence_of(:project) }
|
||||
|
|
Loading…
Reference in a new issue