Commit bbcee7e8 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'pl-status-page-mvc-changes-emojis' into 'master'

Publish status page on emoji changes

See merge request gitlab-org/gitlab!28160
parents 0cd1a7e3 d46084c3
......@@ -16,7 +16,7 @@ module AwardEmojis
award = awardable.award_emoji.create(name: name, user: current_user)
if award.persisted?
TodoService.new.new_award_emoji(todoable, current_user) if todoable
after_create(award)
success(award: award)
else
error(award.errors.full_messages, award: award)
......@@ -25,6 +25,10 @@ module AwardEmojis
private
def after_create(award)
TodoService.new.new_award_emoji(todoable, current_user) if todoable
end
def todoable
strong_memoize(:todoable) do
case awardable
......@@ -40,3 +44,5 @@ module AwardEmojis
end
end
end
AwardEmojis::AddService.prepend_if_ee('EE::AwardEmojis::AddService')
......@@ -14,8 +14,16 @@ module AwardEmojis
end
award = awards.destroy_all.first # rubocop: disable DestroyAll
after_destroy(award)
success(award: award)
end
private
def after_destroy(award)
end
end
end
AwardEmojis::DestroyService.prepend_if_ee('EE::AwardEmojis::DestroyService')
# frozen_string_literal: true
module EE
module AwardEmojis
module AddService
extend ::Gitlab::Utils::Override
private
override :after_create
def after_create(award)
super
StatusPage.trigger_publish(project, current_user, award)
end
end
end
end
# frozen_string_literal: true
module EE
module AwardEmojis
module DestroyService
extend ::Gitlab::Utils::Override
private
override :after_destroy
def after_destroy(award)
super
StatusPage.trigger_publish(project, current_user, award)
end
end
end
end
......@@ -51,6 +51,7 @@ module StatusPage
case triggered_by
when Issue then eligable_issue_id_from_issue
when Note then eligable_issue_id_from_note
when AwardEmoji then eligable_issue_id_from_award_emoji
else
raise ArgumentError, "unsupported trigger type #{triggered_by.class}"
end
......@@ -89,5 +90,15 @@ module StatusPage
note.noteable_id
end
def eligable_issue_id_from_award_emoji
award_emoji = triggered_by
return unless award_emoji.name == StatusPage::AWARD_EMOJI
return unless award_emoji.awardable.is_a?(Note)
return unless award_emoji.awardable.for_issue?
award_emoji.awardable.noteable_id
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe AwardEmojis::AddService do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:awardable) { create(:note_on_issue, project: project) }
let(:name) { 'thumbsup' }
subject(:service) { described_class.new(awardable, name, user) }
describe '#execute' do
describe 'publish to status page' do
let(:execute) { service.execute }
let(:issue_id) { awardable.noteable_id }
context 'when adding succeeds' do
context 'with recognized emoji' do
let(:name) { StatusPage::AWARD_EMOJI }
include_examples 'trigger status page publish'
end
context 'with unrecognized emoji' do
let(:name) { 'x' }
include_examples 'no trigger status page publish'
end
end
context 'when adding fails' do
let(:name) { '' }
include_examples 'no trigger status page publish'
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe AwardEmojis::DestroyService do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:awardable) { create(:note_on_issue, project: project) }
let(:name) { 'thumbsup' }
subject(:service) { described_class.new(awardable, name, user) }
describe '#execute' do
describe 'publish to status page' do
let(:execute) { service.execute }
let(:issue_id) { awardable.noteable_id }
before do
create(:award_emoji, user: user, name: name, awardable: awardable)
end
context 'with recognized emoji' do
let(:name) { StatusPage::AWARD_EMOJI }
include_examples 'trigger status page publish'
end
context 'with unrecognized emoji' do
let(:name) { 'x' }
include_examples 'no trigger status page publish'
end
end
end
end
......@@ -4,7 +4,7 @@ require 'spec_helper'
describe StatusPage::TriggerPublishService do
let_it_be(:user) { create(:user) }
let_it_be(:project, refind: true) { create(:project) }
let_it_be(:project, refind: true) { create(:project, :repository) }
let(:service) { described_class.new(project, user, triggered_by) }
......@@ -142,8 +142,6 @@ describe StatusPage::TriggerPublishService do
end
context 'for merge requests' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:triggered_by) do
create(:note_on_merge_request, project: project)
end
......@@ -158,6 +156,39 @@ describe StatusPage::TriggerPublishService do
end
end
describe 'triggered by award emoji' do
let(:emoji_name) { StatusPage::AWARD_EMOJI }
let(:issue_id) { triggered_by.awardable.noteable_id }
let(:triggered_by) do
create(:award_emoji, name: emoji_name, awardable: awardable)
end
context 'for notes on issues' do
let_it_be(:awardable) { create(:note_on_issue, project: project) }
include_examples 'trigger status page publish'
context 'without recognized emoji' do
let(:emoji_name) { 'thumbsup' }
include_examples 'no trigger status page publish'
end
end
context 'for issues' do
let_it_be(:awardable) { create(:issue, project: project) }
include_examples 'no trigger status page publish'
end
context 'for notes on merge requests' do
let_it_be(:awardable) { create(:note_on_merge_request, project: project) }
include_examples 'no trigger status page publish'
end
end
describe 'triggered by unsupported type' do
context 'for some abitary type' do
let(:triggered_by) { Object.new }
......
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