From 2ee3ea93bd9424a0bb9cb2f64002486733121d23 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 18 Mar 2014 19:58:51 +0600 Subject: [PATCH] [#345] remove deprecated dynamic finder methods --- app/controllers/admin/users_controller.rb | 2 +- app/controllers/application_controller.rb | 4 +-- app/controllers/groups/members_controller.rb | 4 +-- .../projects/comments_controller.rb | 2 +- .../users/omniauth_callbacks_controller.rb | 2 +- app/models/build_list.rb | 2 +- app/models/comment.rb | 2 +- app/models/concerns/acts_like_member.rb | 2 +- app/models/concerns/build_list_observer.rb | 2 +- app/models/concerns/feed/comment.rb | 2 +- app/models/concerns/feed/git.rb | 2 +- app/models/concerns/file_store_clean.rb | 2 +- app/models/concerns/git.rb | 2 +- app/models/git_hook.rb | 4 +-- app/models/mass_build.rb | 2 +- app/models/platform.rb | 4 +-- app/models/platform_content.rb | 2 +- app/models/product_build_list.rb | 2 +- app/models/project.rb | 4 +-- app/models/repository.rb | 4 +-- .../admin/register_requests/index.html.haml | 2 +- lib/tasks/add_branch.rake | 10 ++++---- lib/tasks/import.rake | 25 +++++++++---------- lib/tasks/migrate_repos_task.rake | 6 ++--- lib/tasks/new_core.rake | 2 +- lib/tasks/projects.rake | 8 +++--- lib/tasks/remove_branch.rake | 2 +- .../platforms/repositories_controller_spec.rb | 4 +-- spec/factories/mass_build.rb | 2 +- spec/factories/products.rb | 2 +- .../build_lists_publish_task_manager_spec.rb | 2 +- 31 files changed, 58 insertions(+), 59 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 91d66d3e6..84984d612 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -87,6 +87,6 @@ class Admin::UsersController < Admin::BaseController protected def find_user - @user = User.find_by_uname!(params[:id]) if params[:id] + @user = User.find_by!(uname: params[:id]) if params[:id].present? end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 59c62c8eb..7df3ee50d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -78,8 +78,8 @@ class ApplicationController < ActionController::Base return current_user end else - params['user_id'] && User.find_by_id(params['user_id']) || - params['group_id'] && Group.find_by_id(params['group_id']) || current_user + params['user_id'] && User.find(params['user_id']) || + params['group_id'] && Group.find(params['group_id']) || current_user end end diff --git a/app/controllers/groups/members_controller.rb b/app/controllers/groups/members_controller.rb index 4b730cf1e..5bc58d796 100644 --- a/app/controllers/groups/members_controller.rb +++ b/app/controllers/groups/members_controller.rb @@ -7,7 +7,7 @@ class Groups::MembersController < Groups::BaseController def update params['user'].keys.each do |user_id| role = params['user'][user_id] - if relation = @group.actors.where(actor_id: user_id, actor_type: 'User') #find_by_actor_id_and_actor_type(user_id, 'User') + if relation = @group.actors.where(actor_id: user_id, actor_type: 'User') relation.update_all(role: role) if @group.owner.id.to_s != user_id else relation = @group.actors.build(actor_id: user_id, actor_type: 'User', role: role) @@ -34,7 +34,7 @@ class Groups::MembersController < Groups::BaseController end def add - @user = User.find_by_uname(params[:user_uname]) + @user = User.find_by uname: params[:user_uname] if !@user flash[:error] = t("flash.collaborators.wrong_user", uname: params[:user_uname]) elsif @group.add_member(@user, params[:role]) diff --git a/app/controllers/projects/comments_controller.rb b/app/controllers/projects/comments_controller.rb index 21230f2ec..ce93068fc 100644 --- a/app/controllers/projects/comments_controller.rb +++ b/app/controllers/projects/comments_controller.rb @@ -47,7 +47,7 @@ class Projects::CommentsController < Projects::BaseController protected def find_commentable - @commentable = params[:issue_id].present? && @project.issues.find_by_serial_id(params[:issue_id]) || + @commentable = params[:issue_id].present? && @project.issues.find_by(serial_id: params[:issue_id]) || params[:commit_id].present? && @project.repo.commit(params[:commit_id]) end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 11189431e..38fab90d6 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -45,7 +45,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController else raise 'Provider #{provider} not handled' end - user = User.find_or_initialize_by_email(auth['info']['email']) + user = User.find_or_initialize_by email: auth['info']['email'] if user.new_record? user.name = name user.uname = name.gsub(/\s/, '').underscore diff --git a/app/models/build_list.rb b/app/models/build_list.rb index a1a1c4c82..260591c9f 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -420,7 +420,7 @@ class BuildList < ActiveRecord::Base end def set_packages(pkg_hash, project_name) - prj = Project.joins(repositories: :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(project_name) + prj = Project.joins(repositories: :platform).where('platforms.id = ?', save_to_platform.id).find_by!(name: project_name) build_package(pkg_hash['srpm'], 'source', prj) {|p| p.save!} pkg_hash['rpm'].each do |rpm_hash| build_package(rpm_hash, 'binary', prj) {|p| p.save!} diff --git a/app/models/comment.rb b/app/models/comment.rb index 9b1878195..5ea3c85c6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -200,7 +200,7 @@ class Comment < ActiveRecord::Base commentable.subscribes.create(user: user) if !commentable.subscribes.exists?(user_id: user.id) elsif commit_comment? recipients = project.admins - recipients << user << User.find_by_email(commentable.try(:committer).try(:email)) # commentor and committer + recipients << user << User.find_by(email: commentable.try(:committer).try(:email)) # commentor and committer recipients.compact.uniq.each do |user| options = {project_id: project.id, subscribeable_id: commentable_id, subscribeable_type: commentable.class.name, user_id: user.id} Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable) diff --git a/app/models/concerns/acts_like_member.rb b/app/models/concerns/acts_like_member.rb index a80088a59..03cf567c0 100644 --- a/app/models/concerns/acts_like_member.rb +++ b/app/models/concerns/acts_like_member.rb @@ -27,7 +27,7 @@ module ActsLikeMember module ClassMethods def find_by_insensitive_uname(uname) - find_by_uname(uname) || by_uname(uname).first + find_by(uname: uname) || by_uname(uname).first end def find_by_insensitive_uname!(uname) diff --git a/app/models/concerns/build_list_observer.rb b/app/models/concerns/build_list_observer.rb index 0db713ea3..908e475d9 100644 --- a/app/models/concerns/build_list_observer.rb +++ b/app/models/concerns/build_list_observer.rb @@ -21,7 +21,7 @@ module BuildListObserver if status == self.class::SUCCESS # Update project average build time begin - statistic = project.project_statistics.find_or_create_by_arch_id(arch_id) + statistic = project.project_statistics.find_or_create_by arch_id: arch_id rescue ActiveRecord::RecordNotUnique retry end diff --git a/app/models/concerns/feed/comment.rb b/app/models/concerns/feed/comment.rb index 7a8a6e830..1f60ade43 100644 --- a/app/models/concerns/feed/comment.rb +++ b/app/models/concerns/feed/comment.rb @@ -68,7 +68,7 @@ module Feed::Comment end def can_notify_on_new_comment?(subscribe) - notifier = SettingsNotifier.find_by_user_id(subscribe.user_id) + notifier = SettingsNotifier.find_by user_id: subscribe.user_id notifier && notifier.new_comment && notifier.can_notify end end diff --git a/app/models/concerns/feed/git.rb b/app/models/concerns/feed/git.rb index 537baec6b..de5ab8ffa 100644 --- a/app/models/concerns/feed/git.rb +++ b/app/models/concerns/feed/git.rb @@ -49,7 +49,7 @@ module Feed::Git end when 'Hash' # 'Gollum::Committer' - actor = User.find_by_uname! record[:actor_name] + actor = User.find_by! uname: record[:actor_name] project = Project.find record[:project_id] project.admins.each do |recipient| diff --git a/app/models/concerns/file_store_clean.rb b/app/models/concerns/file_store_clean.rb index afced4ff9..f4fe70c42 100644 --- a/app/models/concerns/file_store_clean.rb +++ b/app/models/concerns/file_store_clean.rb @@ -14,7 +14,7 @@ module FileStoreClean def destroy_files_from_file_store(args = sha1_of_file_store_files) files = *args - token = User.find_by_uname('file_store').authentication_token + token = User.find_by(uname: 'file_store').authentication_token uri = URI APP_CONFIG['file_store_url'] Net::HTTP.start(uri.host, uri.port) do |http| files.each do |sha1| diff --git a/app/models/concerns/git.rb b/app/models/concerns/git.rb index c1da4c7ba..f8e97b6e4 100644 --- a/app/models/concerns/git.rb +++ b/app/models/concerns/git.rb @@ -106,7 +106,7 @@ module Git end def import_srpm(srpm_path = srpm.path, branch_name = 'import') - token = User.find_by_uname('rosa_system').authentication_token + token = User.find_by(uname: 'rosa_system').authentication_token opts = [srpm_path, path, branch_name, Rails.root.join('bin', 'file-store.rb'), token, APP_CONFIG['file_store_url']].join(' ') system("#{Rails.root.join('bin', 'import_srpm.sh')} #{opts} >> /dev/null 2>&1") end diff --git a/app/models/git_hook.rb b/app/models/git_hook.rb index 641b90495..5e6fb3b20 100644 --- a/app/models/git_hook.rb +++ b/app/models/git_hook.rb @@ -71,13 +71,13 @@ class GitHook def find_user(user) if user.blank? # Local push - User.find_by_email(project.repo.commit(newrev).author.email) rescue nil + User.find_by(email: project.repo.commit(newrev).author.email) rescue nil elsif user =~ /\Auser-\d+\Z/ # git push over http User.find(user.gsub('user-', '')) elsif user =~ /\Akey-\d+\Z/ # git push over ssh - SshKey.find_by_id(user.gsub('key-', '')).try(:user) + SshKey.find(user.gsub('key-', '')).try(:user) end end end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index f979c5676..965ca8f22 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -41,7 +41,7 @@ class MassBuild < ActiveRecord::Base next if name.blank? name.chomp!; name.strip! - if project = Project.joins(:repositories).where('repositories.id in (?)', save_to_platform.repository_ids).find_by_name(name) + if project = Project.joins(:repositories).where('repositories.id in (?)', save_to_platform.repository_ids).find_by(name: name) begin return if self.reload.stop_build increase_rt = increase_release_tag? diff --git a/app/models/platform.rb b/app/models/platform.rb index dbea18510..7b8fbc5fc 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -223,13 +223,13 @@ class Platform < ActiveRecord::Base end Rails.cache.fetch([platform_name, token, :platform_allowed], expires_in: 2.minutes) do - platform = Platform.find_by_name platform_name + platform = Platform.find_by name: platform_name next false unless platform next true unless platform.hidden? next false unless token next true if platform.tokens.by_active.where(authentication_token: token).exists? - user = User.find_by_authentication_token token + user = User.find_by authentication_token: token current_ability = Ability.new(user) if user && current_ability.can?(:show, platform) true diff --git a/app/models/platform_content.rb b/app/models/platform_content.rb index 46b26abcc..bc3256f35 100644 --- a/app/models/platform_content.rb +++ b/app/models/platform_content.rb @@ -21,7 +21,7 @@ class PlatformContent bfp_name = @path.match(/\/#{@platform.name}\/repository\/[\w]+\//) return nil unless bfp_name bfp_name = bfp_name[0].gsub(/\/#{@platform.name}\/repository\//, '').gsub('/', '') - build_for_platform = Platform.main.find_by_name bfp_name + build_for_platform = Platform.main.find_by name: bfp_name return nil unless build_for_platform end diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index d963b6cc8..32ad4ed22 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -40,7 +40,7 @@ class ProductBuildList < ActiveRecord::Base belongs_to :user # see: Issue #6 - before_validation -> { self.arch_id = Arch.find_by_name('x86_64').id }, on: :create + before_validation -> { self.arch_id = Arch.find_by(name: 'x86_64').id }, on: :create # field "not_delete" can be changed only if build has been completed before_validation -> { self.not_delete = false unless build_completed?; true } validates :product_id, diff --git a/app/models/project.rb b/app/models/project.rb index 5b446377a..cac685c39 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -165,7 +165,7 @@ class Project < ActiveRecord::Base #path #share by NFS end - def build_for(mass_build, repository_id, arch = Arch.find_by_name('i586'), priority = 0, increase_rt = false) + def build_for(mass_build, repository_id, arch = Arch.find_by(name: 'i586'), priority = 0, increase_rt = false) build_for_platform = mass_build.build_for_platform save_to_platform = mass_build.save_to_platform user = mass_build.user @@ -245,7 +245,7 @@ class Project < ActiveRecord::Base archive = archive_by_treeish_and_format tag.name, format sha1 = Digest::SHA1.file(archive[:path]).hexdigest unless FileStoreClean.file_exist_on_file_store? sha1 - token = User.find_by_uname('rosa_system').authentication_token + token = User.find_by(uname: 'rosa_system').authentication_token begin resp = JSON `curl --user #{token}: -POST -F 'file_store[file]=@#{archive[:path]};filename=#{name}-#{tag.name}.#{tag_file_format(format)}' #{APP_CONFIG['file_store_url']}/api/v1/upload` rescue # Dont care about it diff --git a/app/models/repository.rb b/app/models/repository.rb index 83c9aeb51..2aec39b92 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -35,13 +35,13 @@ class Repository < ActiveRecord::Base def regenerate(build_for_platform_id = nil) build_for_platform = Platform.main.find build_for_platform_id if platform.personal? - status = repository_statuses.find_or_create_by_platform_id(build_for_platform.try(:id) || platform_id) + status = repository_statuses.find_or_create_by(platform_id: build_for_platform.try(:id) || platform_id) status.regenerate end def resign if platform.main? - status = repository_statuses.find_or_create_by_platform_id(platform_id) + status = repository_statuses.find_or_create_by(platform_id: platform_id) status.resign end end diff --git a/app/views/admin/register_requests/index.html.haml b/app/views/admin/register_requests/index.html.haml index d4bf2368f..f23a77182 100644 --- a/app/views/admin/register_requests/index.html.haml +++ b/app/views/admin/register_requests/index.html.haml @@ -18,7 +18,7 @@ %tr{class: cycle("odd", "even")} %td= check_box_tag 'request_ids[]', request.id %td= request.name - - @user = User.find_by_email(request.email) if request.approved + - @user = User.find_by(email: request.email) if request.approved %td= link_to_if @user, request.email, @user %td= request.interest %td= request.more diff --git a/lib/tasks/add_branch.rake b/lib/tasks/add_branch.rake index 95be01962..756f15a4b 100644 --- a/lib/tasks/add_branch.rake +++ b/lib/tasks/add_branch.rake @@ -18,7 +18,7 @@ namespace :add_branch do dst_branch = ENV['DST_BRANCH'] group = ENV['GROUP'] say "START add branch #{dst_branch} from #{src_branch} in #{group} group" - Group.find_by_uname(group).projects.find_each do |p| + Group.find_by(uname: group).projects.find_each do |p| next if p.repo.branches.map(&:name).include?(dst_branch) next if p.repo.branches.map(&:name).exclude?(src_branch) say "===== Process #{p.name} project" @@ -32,7 +32,7 @@ namespace :add_branch do src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011' dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts' say "START add branch #{dst_branch} from #{src_branch}" - Platform.find_by_name(dst_branch).repositories.each do |r| + Platform.find_by(name: dst_branch).repositories.each do |r| say "=== Process #{r.name} repo" r.projects.find_each do |p| next if p.repo.branches.map(&:name).include?(dst_branch) @@ -46,9 +46,9 @@ namespace :add_branch do desc "Add branch for owner projects by list" task list: :environment do source = ENV['SOURCE'] || 'https://dl.dropbox.com/u/984976/texlive.txt' - owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'import') - platform = Platform.find_by_name!(ENV['PLATFORM'] || 'rosa2012.1') - repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main') + owner = User.find_by(uname: ENV['OWNER']) || Group.find_by!(uname: ENV['OWNER'] || 'import') + platform = Platform.find_by!(name: ENV['PLATFORM'] || 'rosa2012.1') + repo = platform.repositories.find_by!(name: ENV['REPO'] || 'main') src_branch = ENV['SRC_BRANCH'] || 'import_cooker' dst_branch = ENV['DST_BRANCH'] || 'rosa2012.1' say "START fork from #{src_branch} to #{dst_branch} branch using #{source} for #{owner.uname}. Add to repo '#{platform.name}/#{repo.name}'." diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index ecd2265ec..adb2e8623 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -5,9 +5,8 @@ namespace :import do desc "Load projects" task projects: :environment do source = ENV['SOURCE'] || 'http://dl.dropbox.com/u/984976/package_list.txt' - #owner = User.find_by_uname(ENV['OWNER_UNAME']) || Group.find_by_uname(ENV['OWNER_UNAME']) || User.first - owner = Group.find_by_uname("npp_team") - platform = Platform.find_by_name("RosaNPP") # RosaNPP + owner = Group.find_by uname: "npp_team" + platform = Platform.find_by name: "RosaNPP" # RosaNPP repo = platform.repositories.first rescue nil say "START import projects from '#{source}' for '#{owner.uname}'.#{repo ? " To repo '#{platform.name}/#{repo.name}'." : ''}" ask 'Press enter to continue' @@ -33,9 +32,9 @@ namespace :import do list = ENV['LIST'] #|| 'https://dl.dropbox.com/u/984976/alt_import.txt' mask = ENV['MASK'] || '*.src.rpm' hidden = ENV['HIDDEN'] == 'true' ? true : false - owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'altlinux') - platform = Platform.find_by_name!(ENV['PLATFORM'] || 'altlinux5') - repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main') + owner = User.find_by(uname: ENV['OWNER']) || Group.find_by!(uname: ENV['OWNER'] || 'altlinux') + platform = Platform.find_by!(name: ENV['PLATFORM'] || 'altlinux5') + repo = platform.repositories.find_by!(name: ENV['REPO'] || 'main') clear = ENV['CLEAR'] == 'true' ? true : false say "START import projects from '#{base}' using '#{list || mask}' for '#{owner.uname}' to repo '#{platform.name}/#{repo.name}'." @@ -47,10 +46,10 @@ namespace :import do project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) repo.projects << project rescue nil else # check if project already added - if project = repo.projects.find_by_name(name) || repo.projects.by_name(name).first # fallback to speedup + if project = repo.projects.find_by(name: name) || repo.projects.by_name(name).first # fallback to speedup print "Found project '#{project.name_with_owner}' in '#{platform.name}/#{repo.name}'." elsif scoped = Project.where(owner_id: owner.id, owner_type: owner.class) and - project = scoped.find_by_name(name) || scoped.by_name(name).first + project = scoped.find_by(name: name) || scoped.by_name(name).first begin repo.projects << project rescue nil rescue Exception => e @@ -109,10 +108,10 @@ namespace :import do desc "Parse repository for changes" task parse: :environment do release = ENV['RELEASE'] || 'official/2011' - platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011") - repository = platform.repositories.find_by_name(ENV['REPOSITORY'] || 'main') + platform = Platform.find_by(name: ENV['PLATFORM'] || "mandriva2011") + repository = platform.repositories.find_by(name: ENV['REPOSITORY'] || 'main') source = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name, '{release,updates}') - owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first} + owner = Group.find_or_create_by(uname: ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first} branch = ENV['BRANCH'] || "import_#{platform.name}" say "START (#{Time.now.utc})" @@ -127,10 +126,10 @@ namespace :import do project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) print "Use project #{project.name_with_owner}. " else # search project through repository - if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup + if project = repository.projects.find_by(name: name) || repository.projects.by_name(name).first # fallback to speedup print "Found project #{project.name_with_owner} in #{platform.name}/#{repository.name}. " elsif scoped = Project.where(owner_id: owner.id, owner_type: owner.class) and - project = scoped.find_by_name(name) || scoped.by_name(name).first + project = scoped.find_by(name: name) || scoped.by_name(name).first repository.projects << project print "Add project #{project.name_with_owner} to #{platform.name}/#{repository.name}. " else diff --git a/lib/tasks/migrate_repos_task.rake b/lib/tasks/migrate_repos_task.rake index 08d4ae5e4..eecbb1279 100644 --- a/lib/tasks/migrate_repos_task.rake +++ b/lib/tasks/migrate_repos_task.rake @@ -5,15 +5,15 @@ namespace :repositories do repo_dirs = Dir["/root/mandriva_main_git/*.git"] total = repo_dirs.length - cooker = Platform.find_by_name!("cooker") - main = cooker.repositories.find_by_name!("main") + cooker = Platform.find_by! name: "cooker" + main = cooker.repositories.find_by! name: "main" repo_dirs.each_with_index do |repo_dir, index| project_name = File.basename(repo_dir, ".git") puts "Creating project(#{index}/#{total}): #{project_name}" - if main.projects.find_by_name(project_name) + if main.projects.find_by name: project_name puts "\t Already created. Skipping" next end diff --git a/lib/tasks/new_core.rake b/lib/tasks/new_core.rake index 56952652a..041d8bf01 100644 --- a/lib/tasks/new_core.rake +++ b/lib/tasks/new_core.rake @@ -4,7 +4,7 @@ namespace :new_core do task update_packages: :environment do say "[#{Time.zone.now}] Starting to extract rpms..." - token = User.find_by_uname('rosa_system').authentication_token + token = User.find_by(uname: 'rosa_system').authentication_token BuildList.where(new_core: true). where(status: [ BuildList::SUCCESS, diff --git a/lib/tasks/projects.rake b/lib/tasks/projects.rake index 22f80768b..2ed671a6e 100644 --- a/lib/tasks/projects.rake +++ b/lib/tasks/projects.rake @@ -30,10 +30,10 @@ end namespace :projects do desc 'Add projects from one platform repository to another' task copy_to_repo: :environment do - source_platform = Platform.find_by_name!(ENV['SRC_PLATFORM']) - dest_platform = Platform.find_by_name!(ENV['DST_PLATFORM']) - source_repo = source_platform.repositories.find_by_name!(ENV['SRC_REPO']) - dest_repo = dest_platform.repositories.find_by_name!(ENV['DST_REPO']) + source_platform = Platform.find_by! name: ENV['SRC_PLATFORM'] + dest_platform = Platform.find_by! name: ENV['DST_PLATFORM'] + source_repo = source_platform.repositories.find_by! name: ENV['SRC_REPO'] + dest_repo = dest_platform.repositories.find_by! name: ENV['DST_REPO'] say "Add from repo '#{source_platform.name}/#{source_repo.name}' to repo '#{dest_platform.name}/#{dest_repo.name}'." source_repo.projects.each do |pr| diff --git a/lib/tasks/remove_branch.rake b/lib/tasks/remove_branch.rake index 90752fc10..5019c52cb 100644 --- a/lib/tasks/remove_branch.rake +++ b/lib/tasks/remove_branch.rake @@ -4,7 +4,7 @@ namespace :remove_branch do branch = ENV['BRANCH'] group = ENV['GROUP'] say "START remove branch #{branch} from #{group} group" - Group.find_by_uname(group).projects.find_each do |p| + Group.find_by(uname: group).projects.find_each do |p| next if p.repo.branches.map(&:name).exclude?(branch) say "===== Process #{p.name} project" p.repo.git.native(:branch, {}, '-D', branch) diff --git a/spec/controllers/platforms/repositories_controller_spec.rb b/spec/controllers/platforms/repositories_controller_spec.rb index d433b611c..ec3b441c4 100644 --- a/spec/controllers/platforms/repositories_controller_spec.rb +++ b/spec/controllers/platforms/repositories_controller_spec.rb @@ -156,14 +156,14 @@ shared_examples_for 'platform admin user' do it 'should be able to perform regenerate_metadata action' do put :regenerate_metadata, id: @repository.id, platform_id: @platform.id response.should redirect_to(platform_repository_path(@platform, @repository)) - @repository.repository_statuses.find_by_platform_id(@platform.id). + @repository.repository_statuses.find_by(platform_id: @platform.id). waiting_for_regeneration?.should be_true end it 'should be able to perform regenerate_metadata action of personal repository' do put :regenerate_metadata, id: @personal_repository.id, platform_id: @personal_repository.platform.id, build_for_platform_id: @platform.id response.should redirect_to(platform_repository_path(@personal_repository.platform, @personal_repository)) - @personal_repository.repository_statuses.find_by_platform_id(@platform.id). + @personal_repository.repository_statuses.find_by(platform_id: @platform.id). waiting_for_regeneration?.should be_true end diff --git a/spec/factories/mass_build.rb b/spec/factories/mass_build.rb index 2266a9e1a..c88e32ef3 100644 --- a/spec/factories/mass_build.rb +++ b/spec/factories/mass_build.rb @@ -3,7 +3,7 @@ FactoryGirl.define do association :save_to_platform, factory: :platform association :user projects_list "first" - arches { [ Arch.find_or_create_by_name('x86_64').id ] } + arches { [ Arch.find_or_create_by(name: 'x86_64').id ] } auto_publish true stop_build false end diff --git a/spec/factories/products.rb b/spec/factories/products.rb index 5918ed477..cfa14a9de 100644 --- a/spec/factories/products.rb +++ b/spec/factories/products.rb @@ -6,6 +6,6 @@ FactoryGirl.define do time_living 150 # see: before_validation in ProductBuildList model - before(:create) { Arch.find_or_create_by_name('x86_64') } + before(:create) { Arch.find_or_create_by(name: 'x86_64') } end end diff --git a/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb b/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb index 77c02bc80..c331efed1 100644 --- a/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb +++ b/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb @@ -47,7 +47,7 @@ describe AbfWorker::BuildListsPublishTaskManager do it "ensures that repository_status has status publish" do build_list.save_to_repository.repository_statuses. - find_by_platform_id(build_list.build_for_platform_id).publish?. + find_by(platform_id: build_list.build_for_platform_id).publish?. should be_true end