Commit 7a4e7ad0 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Fix tests and wrong choices during merge

parent 2bbe781d
......@@ -100,6 +100,14 @@ module Issuable
order_by(method)
end
end
def with_label(title)
if title.is_a?(Array) && title.size > 1
joins(:labels).where(labels: { title: title }).group(arel_table[:id]).having("COUNT(DISTINCT labels.title) = #{title.size}")
else
joins(:labels).where(labels: { title: title })
end
end
end
def today?
......
......@@ -343,6 +343,6 @@ class Note < ActiveRecord::Base
def award_emoji_name
original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1]
Gitlab::AwardEmoji.normilize_emoji_name(original_name)
Gitlab::AwardEmoji.normalize_emoji_name(original_name)
end
end
......@@ -7,7 +7,7 @@ module Notes
if note.award_emoji?
return ToggleAwardEmojiService.new(project, current_user, params).
execute(note.award_emoji_name, note.note)
execute(note.noteable, note.award_emoji_name)
end
return unless valid_project?(note)
......
......@@ -258,8 +258,10 @@ describe Projects::IssuesController do
end
it "toggles the award emoji" do
expect { post(:toggle_award_emoji, namespace_id: project.namespace.path,
project_id: project.path, id: issue.iid, name: "thumbsup") }.to change { AwardEmoji.count }.by(1)
expect do
post(:toggle_award_emoji, namespace_id: project.namespace.path,
project_id: project.path, id: issue.iid, name: "thumbsup")
end.to change { AwardEmoji.count }.by(1)
expect(response.status).to eq(200)
end
......
......@@ -214,4 +214,34 @@ describe Issue, "Issuable" do
expect(issue.downvotes).to eq(1)
end
end
describe ".with_label" do
let(:project) { create(:project, :public) }
let(:bug) { create(:label, project: project, title: 'bug') }
let(:feature) { create(:label, project: project, title: 'feature') }
let(:enhancement) { create(:label, project: project, title: 'enhancement') }
let(:issue1) { create(:issue, title: "Bugfix1", project: project) }
let(:issue2) { create(:issue, title: "Bugfix2", project: project) }
let(:issue3) { create(:issue, title: "Feature1", project: project) }
before(:each) do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << enhancement
issue3.labels << feature
end
it 'finds the correct issue containing just enhancement label' do
expect(Issue.with_label(enhancement.title)).to match_array([issue2])
end
it 'finds the correct issues containing the same label' do
expect(Issue.with_label(bug.title)).to match_array([issue1, issue2])
end
it 'finds the correct issues containing only both labels' do
expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2])
end
end
end
......@@ -51,5 +51,17 @@ describe Notes::CreateService, services: true do
expect(note).to be_valid
expect(note.note).to eq(opts[:note])
end
it "normalizes the emoji name" do
opts = {
note: ':+1:',
noteable_type: 'Issue',
noteable_id: issue.id
}
expect_any_instance_of(ToggleAwardEmojiService).to receive(:execute).with(issue, "thumbsup")
Notes::CreateService.new(project, user, opts).execute
end
end
end
......@@ -16,23 +16,17 @@ describe ToggleAwardEmoji, services: true do
ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsdown")
end
it 'normalizes the emoji name' do
expect(issue).to receive(:toggle_award_emoji).with("thumbsup", user)
ToggleAwardEmojiService.new(project, user).execute(issue, ":+1:")
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, ":+1:") }.to change { AwardEmoji.count }.by(-1)
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, ":+1:") }.to change { AwardEmoji.count }.by(1)
expect { ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsup") }.to change { AwardEmoji.count }.by(1)
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