Commit 81fd784b authored by Peter Leitzen's avatar Peter Leitzen

Trigger publish only for eligible award emojis

parent 82f259bc
...@@ -51,6 +51,7 @@ module StatusPage ...@@ -51,6 +51,7 @@ module StatusPage
case triggered_by case triggered_by
when Issue then eligable_issue_id_from_issue when Issue then eligable_issue_id_from_issue
when Note then eligable_issue_id_from_note when Note then eligable_issue_id_from_note
when AwardEmoji then eligable_issue_id_from_award_emoji
else else
raise ArgumentError, "unsupported trigger type #{triggered_by.class}" raise ArgumentError, "unsupported trigger type #{triggered_by.class}"
end end
...@@ -89,5 +90,15 @@ module StatusPage ...@@ -89,5 +90,15 @@ module StatusPage
note.noteable_id note.noteable_id
end 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
end end
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe StatusPage::TriggerPublishService do describe StatusPage::TriggerPublishService do
let_it_be(:user) { create(:user) } 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) } let(:service) { described_class.new(project, user, triggered_by) }
...@@ -142,8 +142,6 @@ describe StatusPage::TriggerPublishService do ...@@ -142,8 +142,6 @@ describe StatusPage::TriggerPublishService do
end end
context 'for merge requests' do context 'for merge requests' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:triggered_by) do let_it_be(:triggered_by) do
create(:note_on_merge_request, project: project) create(:note_on_merge_request, project: project)
end end
...@@ -158,6 +156,39 @@ describe StatusPage::TriggerPublishService do ...@@ -158,6 +156,39 @@ describe StatusPage::TriggerPublishService do
end end
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 describe 'triggered by unsupported type' do
context 'for some abitary type' do context 'for some abitary type' do
let(:triggered_by) { Object.new } 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