Use association search in issuable create service

This commit is contained in:
Grzegorz Bizon 2016-04-21 13:40:52 +02:00
parent 006d8b268c
commit 01ab6d704c
2 changed files with 12 additions and 12 deletions

View file

@ -57,10 +57,11 @@ class IssuableBaseService < BaseService
end end
def filter_milestone def filter_milestone
return unless params[:milestone_id] milestone_id = params[:milestone_id]
return unless milestone_id
if params[:milestone_id] == IssuableFinder::NONE || if milestone_id == IssuableFinder::NONE ||
Milestone.find(params[:milestone_id]).try(:project) != project project.milestones.find_by(id: milestone_id).nil?
params[:milestone_id] = '' params[:milestone_id] = ''
end end
end end
@ -68,9 +69,8 @@ class IssuableBaseService < BaseService
def filter_labels def filter_labels
return if params[:label_ids].to_a.empty? return if params[:label_ids].to_a.empty?
params[:label_ids].select! do |label_id| params[:label_ids] =
Label.find(label_id).try(:project) == project project.labels.where(id: params[:label_ids]).pluck(:id)
end
end end
def update(issuable) def update(issuable)

View file

@ -4,13 +4,13 @@ describe Issues::CreateService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
describe :execute do describe '#execute' do
let(:issue) { Issues::CreateService.new(project, user, opts).execute } let(:issue) { described_class.new(project, user, opts).execute }
context 'valid params' do context 'when params are valid' do
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
let(:milestone) { create(:milestone, project: project) } let(:milestone) { create(:milestone, project: project) }
let(:labels) { create_list(:label, 4, project: project) } let(:labels) { create_pair(:label, project: project) }
before do before do
project.team << [user, :master] project.team << [user, :master]
@ -45,7 +45,7 @@ describe Issues::CreateService, services: true do
expect(Todo.where(attributes).count).to eq 1 expect(Todo.where(attributes).count).to eq 1
end end
context 'label that belongs to different project' do context 'when label belongs to different project' do
let(:label) { create(:label) } let(:label) { create(:label) }
let(:opts) do let(:opts) do
@ -59,7 +59,7 @@ describe Issues::CreateService, services: true do
end end
end end
context 'milestone that belongs to different project' do context 'when milestone belongs to different project' do
let(:milestone) { create(:milestone) } let(:milestone) { create(:milestone) }
let(:opts) do let(:opts) do