From 705f15587bfbfde33ae10f7820e66370a054ad5a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 24 Feb 2017 14:11:10 -0600 Subject: [PATCH] Fix spec --- app/models/repository.rb | 96 ++++++---------------------- app/services/files/create_service.rb | 2 +- app/services/files/multi_service.rb | 6 +- app/services/files/update_service.rb | 2 +- 4 files changed, 25 insertions(+), 81 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 3bf89ee52a3..1762118278a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -746,99 +746,43 @@ class Repository @tags ||= raw_repository.tags end - # rubocop:disable Metrics/ParameterLists - def create_dir( - user, path, - message:, branch_name:, - author_email: nil, author_name: nil, - start_branch_name: nil, start_project: project) + def create_dir(user, path, **options) + options[:user] = user + options[:actions] = [{ action: :create_dir, file_path: path }] - multi_action( - user: user, - message: message, - branch_name: branch_name, - author_email: author_email, - author_name: author_name, - start_branch_name: start_branch_name, - start_project: start_project, - actions: [{ action: :create_dir, - file_path: path }]) + multi_action(**options) end - # rubocop:enable Metrics/ParameterLists - # rubocop:disable Metrics/ParameterLists - def create_file( - user, path, content, - message:, branch_name:, - author_email: nil, author_name: nil, - start_branch_name: nil, start_project: project) + def create_file(user, path, content, **options) + options[:user] = user + options[:actions] = [{ action: :create, file_path: path, content: content }] - multi_action( - user: user, - message: message, - branch_name: branch_name, - author_email: author_email, - author_name: author_name, - start_branch_name: start_branch_name, - start_project: start_project, - actions: [{ action: :create, - file_path: path, - content: content }]) + multi_action(**options) end - # rubocop:enable Metrics/ParameterLists - # rubocop:disable Metrics/ParameterLists - def update_file( - user, path, content, - message:, branch_name:, previous_path: nil, - author_email: nil, author_name: nil, - start_branch_name: nil, start_project: project) - action = if previous_path && previous_path != path - :move - else - :update - end + def update_file(user, path, content, **options) + previous_path = options.delete(:previous_path) + action = previous_path && previous_path != path ? :move : :update - multi_action( - user: user, - message: message, - branch_name: branch_name, - author_email: author_email, - author_name: author_name, - start_branch_name: start_branch_name, - start_project: start_project, - actions: [{ action: action, - file_path: path, - content: content, - previous_path: previous_path }]) + options[:user] = user + options[:actions] = [{ action: action, file_path: path, previous_path: previous_path, content: content }] + + multi_action(**options) end - # rubocop:enable Metrics/ParameterLists - # rubocop:disable Metrics/ParameterLists - def delete_file( - user, path, - message:, branch_name:, - author_email: nil, author_name: nil, - start_branch_name: nil, start_project: project) + def delete_file(user, path, **options) + options[:user] = user + options[:actions] = [{ action: :delete, file_path: path }] - multi_action( - user: user, - message: message, - branch_name: branch_name, - author_email: author_email, - author_name: author_name, - start_branch_name: start_branch_name, - start_project: start_project, - actions: [{ action: :delete, - file_path: path }]) + multi_action(**options) end - # rubocop:enable Metrics/ParameterLists # rubocop:disable Metrics/ParameterLists def multi_action( user:, branch_name:, message:, actions:, author_email: nil, author_name: nil, start_branch_name: nil, start_project: project) + GitOperationService.new(user, self).with_branch( branch_name, start_branch_name: start_branch_name, diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb index ec45a60eda1..65b5537fb68 100644 --- a/app/services/files/create_service.rb +++ b/app/services/files/create_service.rb @@ -16,7 +16,7 @@ module Files def validate super - if @file_content.empty? + if @file_content.nil? raise_error("You must provide content.") end diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb index ba99af00e96..0609c6219e7 100644 --- a/app/services/files/multi_service.rb +++ b/app/services/files/multi_service.rb @@ -21,7 +21,7 @@ module Files def validate super - + params[:actions].each_with_index do |action, index| if ACTIONS.include?(action[:action].to_s) action[:action] = action[:action].to_sym @@ -102,13 +102,13 @@ module Files raise_error("Your changes could not be committed because a file with the name `#{action[:file_path]}` already exists.") end - if action[:content].empty? + if action[:content].nil? raise_error("You must provide content.") end end def validate_update(action) - if action[:content].empty? + if action[:content].nil? raise_error("You must provide content.") end diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 462de06b6ff..54e1aaf3f67 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -18,7 +18,7 @@ module Files def validate super - if @file_content.empty? + if @file_content.nil? raise_error("You must provide content.") end