Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit 4f6d1c1d authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Rename Labels::CreateService to Labels::FindOrCreateService

parent f53cc60ac39d
...@@ -734,7 +734,7 @@ def build_missing_services ...@@ -734,7 +734,7 @@ def build_missing_services
def create_labels def create_labels
Label.templates.each do |label| Label.templates.each do |label|
params = label.attributes.except('id', 'template', 'created_at', 'updated_at') params = label.attributes.except('id', 'template', 'created_at', 'updated_at')
Labels::CreateService.new(owner, self, params).execute Labels::FindOrCreateService.new(owner, self, params).execute
end end
end end
......
...@@ -19,7 +19,7 @@ def create_list(board, params) ...@@ -19,7 +19,7 @@ def create_list(board, params)
end end
def find_or_create_label(params) def find_or_create_label(params)
::Labels::CreateService.new(current_user, project, params).execute ::Labels::FindOrCreateService.new(current_user, project, params).execute
end end
def label_params def label_params
......
...@@ -88,7 +88,7 @@ def find_or_create_label_ids ...@@ -88,7 +88,7 @@ def find_or_create_label_ids
return unless labels return unless labels
params[:label_ids] = labels.split(',').map do |label_name| params[:label_ids] = labels.split(',').map do |label_name|
service = Labels::CreateService.new(current_user, project, title: label_name.strip) service = Labels::FindOrCreateService.new(current_user, project, title: label_name.strip)
label = service.execute label = service.execute
label.id label.id
......
module Labels module Labels
class CreateService class FindOrCreateService
def initialize(current_user, project, params = {}) def initialize(current_user, project, params = {})
@current_user = current_user @current_user = current_user
@group = project.group @group = project.group
......
...@@ -43,7 +43,7 @@ def label_links ...@@ -43,7 +43,7 @@ def label_links
def find_or_create_label!(label) def find_or_create_label!(label)
params = label.attributes.slice('title', 'description', 'color') params = label.attributes.slice('title', 'description', 'color')
new_label = CreateService.new(current_user, project, params).execute new_label = FindOrCreateService.new(current_user, project, params).execute
new_label.id new_label.id
end end
......
...@@ -75,7 +75,7 @@ def nice_label_color(name) ...@@ -75,7 +75,7 @@ def nice_label_color(name)
def create_label(name) def create_label(name)
params = { title: name, color: nice_label_color(name) } params = { title: name, color: nice_label_color(name) }
::Labels::CreateService.new(project.owner, project, params).execute ::Labels::FindOrCreateService.new(project.owner, project, params).execute
end end
def user_info(person_id) def user_info(person_id)
......
...@@ -15,7 +15,7 @@ def klass ...@@ -15,7 +15,7 @@ def klass
def create! def create!
params = attributes.except(:project) params = attributes.except(:project)
service = ::Labels::CreateService.new(project.owner, project, params) service = ::Labels::FindOrCreateService.new(project.owner, project, params)
label = service.execute label = service.execute
raise ActiveRecord::RecordInvalid.new(label) unless label.persisted? raise ActiveRecord::RecordInvalid.new(label) unless label.persisted?
......
...@@ -234,7 +234,7 @@ def escape_for_markdown(s) ...@@ -234,7 +234,7 @@ def escape_for_markdown(s)
def create_label(name) def create_label(name)
params = { name: name, color: nice_label_color(name) } params = { name: name, color: nice_label_color(name) }
::Labels::CreateService.new(project.owner, project, params).execute ::Labels::FindOrCreateService.new(project.owner, project, params).execute
end end
def format_content(raw_content) def format_content(raw_content)
......
...@@ -19,7 +19,7 @@ def generate(project) ...@@ -19,7 +19,7 @@ def generate(project)
] ]
labels.each do |params| labels.each do |params|
::Labels::CreateService.new(project.owner, project).execute(params) ::Labels::FindOrCreateService.new(project.owner, project).execute(params)
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Labels::CreateService, services: true do describe Labels::FindOrCreateService, services: true do
describe '#execute' do describe '#execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group) } let(:group) { create(:group) }
......
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