BigW Consortium Gitlab

Commit 7a4e7ad0 by Zeger-Jan van de Weg

Fix tests and wrong choices during merge

parent 2bbe781d
...@@ -100,6 +100,14 @@ module Issuable ...@@ -100,6 +100,14 @@ module Issuable
order_by(method) order_by(method)
end end
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 end
def today? def today?
......
...@@ -343,6 +343,6 @@ class Note < ActiveRecord::Base ...@@ -343,6 +343,6 @@ class Note < ActiveRecord::Base
def award_emoji_name def award_emoji_name
original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] 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
end end
...@@ -7,7 +7,7 @@ module Notes ...@@ -7,7 +7,7 @@ module Notes
if note.award_emoji? if note.award_emoji?
return ToggleAwardEmojiService.new(project, current_user, params). return ToggleAwardEmojiService.new(project, current_user, params).
execute(note.award_emoji_name, note.note) execute(note.noteable, note.award_emoji_name)
end end
return unless valid_project?(note) return unless valid_project?(note)
......
...@@ -258,8 +258,10 @@ describe Projects::IssuesController do ...@@ -258,8 +258,10 @@ describe Projects::IssuesController do
end end
it "toggles the award emoji" do it "toggles the award emoji" do
expect { post(:toggle_award_emoji, namespace_id: project.namespace.path, expect do
project_id: project.path, id: issue.iid, name: "thumbsup") }.to change { AwardEmoji.count }.by(1) 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) expect(response.status).to eq(200)
end end
......
...@@ -214,4 +214,34 @@ describe Issue, "Issuable" do ...@@ -214,4 +214,34 @@ describe Issue, "Issuable" do
expect(issue.downvotes).to eq(1) expect(issue.downvotes).to eq(1)
end end
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 end
...@@ -51,5 +51,17 @@ describe Notes::CreateService, services: true do ...@@ -51,5 +51,17 @@ describe Notes::CreateService, services: true do
expect(note).to be_valid expect(note).to be_valid
expect(note.note).to eq(opts[:note]) expect(note.note).to eq(opts[:note])
end 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
end end
...@@ -16,23 +16,17 @@ describe ToggleAwardEmoji, services: true do ...@@ -16,23 +16,17 @@ describe ToggleAwardEmoji, services: true do
ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsdown") ToggleAwardEmojiService.new(project, user).execute(issue, "thumbsdown")
end 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 context 'when the emoji is set' do
it 'removes the emoji' do it 'removes the emoji' do
create(:award_emoji, awardable: issue, user: user) 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
end end
context 'when the award is not set yet' do context 'when the award is not set yet' do
it 'awards the emoji' 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 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