From d5edda880237e0d399f477bdc5b6211f9ee4fe3b Mon Sep 17 00:00:00 2001 From: "depfu[bot]" <23717796+depfu[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2020 13:56:12 +0000 Subject: [PATCH 1/6] Update rubocop to version 0.88.0 --- src/api/Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/Gemfile.lock b/src/api/Gemfile.lock index 6a797501208..00701825302 100644 --- a/src/api/Gemfile.lock +++ b/src/api/Gemfile.lock @@ -334,7 +334,7 @@ GEM rspec-support (3.9.3) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.87.1) + rubocop (0.88.0) parallel (~> 1.10) parser (>= 2.7.1.1) rainbow (>= 2.2.2, < 4.0) From 9533a141b04971257e3bbb33fedfe115949ed7fb Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Tue, 14 Jul 2020 17:01:11 +0200 Subject: [PATCH 2/6] Auto-correct rubocop issues after major version update After upgrading the rubocop gem version from 0.87.1 to 0.88.0 the following new cop got introduced and autocorrected: * Style/ArrayCoercion * Style/CaseLikeIf * Style/HashAsLastArrayItem * Style/RedundantFileExtensionInRequire --- src/api/app/controllers/group_controller.rb | 7 ++++--- src/api/app/controllers/public_controller.rb | 7 ++++--- src/api/app/controllers/source_project_controller.rb | 7 ++++--- .../app/controllers/webui/kiwi/images_controller.rb | 2 +- src/api/app/controllers/webui/package_controller.rb | 5 +++-- .../app/controllers/webui/repositories_controller.rb | 5 +++-- src/api/app/controllers/webui/sitemaps_controller.rb | 5 +++-- src/api/app/controllers/webui/webui_controller.rb | 5 +++-- src/api/app/lib/suse/permission.rb | 5 +++-- src/api/app/models/bs_request.rb | 7 ++++--- src/api/app/models/event_subscription.rb | 10 ++++++---- .../app/models/event_subscription/find_for_event.rb | 5 +++-- src/api/app/models/project.rb | 5 +++-- src/api/app/models/review.rb | 7 ++++--- src/api/app/views/statistics/highest_rated.xml.builder | 5 +++-- src/api/config/application.rb | 2 +- ...3534_convert_notifications_event_payload_to_json.rb | 5 +++-- .../lib/tasks/statistics/github/code_frequency.rake | 5 +++-- .../lib/tasks/statistics/github/commit_activity.rake | 5 +++-- src/api/lib/xpath_engine.rb | 5 +++-- .../spec/controllers/webui/users_controller_spec.rb | 2 +- .../spec/db/data/project_log_entry_user_name_spec.rb | 2 +- src/api/spec/factories/project.rb | 9 +++++---- src/api/spec/factories/staging_workflow.rb | 2 +- src/api/spec/models/bs_request_spec.rb | 10 +++++----- src/api/spec/models/user_spec.rb | 2 +- src/api/spec/support/database_cleaner.rb | 6 +++--- src/api/test/functional/published_controller_test.rb | 5 +++-- src/api/test/unit/schema_test.rb | 5 +++-- 29 files changed, 87 insertions(+), 65 deletions(-) diff --git a/src/api/app/controllers/group_controller.rb b/src/api/app/controllers/group_controller.rb index 4f2ac59afa5..18d3bc66237 100644 --- a/src/api/app/controllers/group_controller.rb +++ b/src/api/app/controllers/group_controller.rb @@ -70,11 +70,12 @@ def command user = User.find_by_login!(params[:userid]) if params[:userid] - if params[:cmd] == 'add_user' + case params[:cmd] + when 'add_user' group.add_user(user) - elsif params[:cmd] == 'remove_user' + when 'remove_user' group.remove_user(user) - elsif params[:cmd] == 'set_email' + when 'set_email' group.set_email(params[:email]) else raise UnknownCommandError, 'cmd must be set to add_user or remove_user' diff --git a/src/api/app/controllers/public_controller.rb b/src/api/app/controllers/public_controller.rb index 5723cbc7c4b..3d83b06d0d1 100644 --- a/src/api/app/controllers/public_controller.rb +++ b/src/api/app/controllers/public_controller.rb @@ -48,7 +48,8 @@ def project_index # project visible/known ? @project = Project.get_by_name(params[:project]) path = unshift_public(request.path_info) - if params[:view] == 'info' + case params[:view] + when 'info' # nofilename since a package may have no source access if params[:nofilename] && params[:nofilename] != '1' render_error status: 400, errorcode: 'parameter_error', message: 'nofilename is not allowed as parameter' @@ -57,11 +58,11 @@ def project_index # path has multiple package= parameters path += '?' + request.query_string path += '&nofilename=1' unless params[:nofilename] - elsif params[:view] == 'verboseproductlist' + when 'verboseproductlist' @products = Product.all_products(@project, params[:expand]) render 'source/verboseproductlist' return - elsif params[:view] == 'productlist' + when 'productlist' @products = Product.all_products(@project, params[:expand]) render 'source/productlist' return diff --git a/src/api/app/controllers/source_project_controller.rb b/src/api/app/controllers/source_project_controller.rb index cefaedac99f..442c608fa14 100644 --- a/src/api/app/controllers/source_project_controller.rb +++ b/src/api/app/controllers/source_project_controller.rb @@ -22,15 +22,16 @@ def show # we let the backend list the packages after we verified the project is visible if params.key?(:view) - if params[:view] == 'verboseproductlist' + case params[:view] + when 'verboseproductlist' @products = Product.all_products(@project, params[:expand]) render 'source/verboseproductlist' return - elsif params[:view] == 'productlist' + when 'productlist' @products = Product.all_products(@project, params[:expand]) render 'source/productlist' return - elsif params[:view] == 'issues' + when 'issues' render_project_issues else pass_to_backend diff --git a/src/api/app/controllers/webui/kiwi/images_controller.rb b/src/api/app/controllers/webui/kiwi/images_controller.rb index 6281b60a632..f7b1f68d1d7 100644 --- a/src/api/app/controllers/webui/kiwi/images_controller.rb +++ b/src/api/app/controllers/webui/kiwi/images_controller.rb @@ -132,7 +132,7 @@ def image_params package_groups_attributes = [ :id, :_destroy, - packages_attributes: [:id, :name, :arch, :replaces, :bootdelete, :bootinclude, :_destroy] + { packages_attributes: [:id, :name, :arch, :replaces, :bootdelete, :bootinclude, :_destroy] } ] profiles_attributes = [ diff --git a/src/api/app/controllers/webui/package_controller.rb b/src/api/app/controllers/webui/package_controller.rb index 3c5a13baaa2..47e75d933ea 100644 --- a/src/api/app/controllers/webui/package_controller.rb +++ b/src/api/app/controllers/webui/package_controller.rb @@ -476,9 +476,10 @@ def update_build_log rescue Timeout::Error, IOError @log_chunk = '' rescue Backend::Error => e - if %r{Logfile is not that big}.match?(e.summary) + case e.summary + when %r{Logfile is not that big} @log_chunk = '' - elsif /start out of range/.match?(e.summary) + when /start out of range/ # probably build compare has cut log and offset is wrong, reset offset @log_chunk = '' @offset = old_offset diff --git a/src/api/app/controllers/webui/repositories_controller.rb b/src/api/app/controllers/webui/repositories_controller.rb index 404a27ba2b7..137052b967b 100644 --- a/src/api/app/controllers/webui/repositories_controller.rb +++ b/src/api/app/controllers/webui/repositories_controller.rb @@ -194,9 +194,10 @@ def change_flag def follow_change_flag_command(flag_type) architecture = Architecture.from_cache!(params[:architecture]) if params[:architecture] - if params[:command] == 'remove' + case params[:command] + when 'remove' @main_object.flags.of_type(flag_type).where(repo: params[:repository], architecture: architecture).delete_all - elsif %r{^set-(?disable|enable)$} =~ params[:command] + when %r{^set-(?disable|enable)$} flag = @main_object.flags.find_or_create_by(flag: flag_type, repo: params[:repository], architecture: architecture) flag.update(status: status) end diff --git a/src/api/app/controllers/webui/sitemaps_controller.rb b/src/api/app/controllers/webui/sitemaps_controller.rb index 1a3b36e52e8..1589b31496c 100644 --- a/src/api/app/controllers/webui/sitemaps_controller.rb +++ b/src/api/app/controllers/webui/sitemaps_controller.rb @@ -15,9 +15,10 @@ def packages projects_table = Project.arel_table predication = - if %r{home}.match?(project_name) + case project_name + when %r{home} projects_table[:name].matches("#{project_name}%") - elsif project_name == 'opensuse' + when 'opensuse' projects_table[:name].matches('openSUSE:%') else projects_table[:name].does_not_match_all(['home:%', 'DISCONTINUED:%', 'openSUSE:%']) diff --git a/src/api/app/controllers/webui/webui_controller.rb b/src/api/app/controllers/webui/webui_controller.rb index 29a945ebd91..c539b68a2f1 100644 --- a/src/api/app/controllers/webui/webui_controller.rb +++ b/src/api/app/controllers/webui/webui_controller.rb @@ -51,9 +51,10 @@ class Webui::WebuiController < ActionController::Base rescue_from Backend::Error, Timeout::Error do |exception| Airbrake.notify(exception) - message = if exception.is_a?(Backend::Error) + message = case exception + when Backend::Error 'There has been an internal error. Please try again.' - elsif exception.is_a?(Timeout::Error) + when Timeout::Error 'The request timed out. Please try again.' end diff --git a/src/api/app/lib/suse/permission.rb b/src/api/app/lib/suse/permission.rb index 6fdecad6d68..c08aedd81ee 100644 --- a/src/api/app/lib/suse/permission.rb +++ b/src/api/app/lib/suse/permission.rb @@ -21,9 +21,10 @@ def project_change?(project = nil) # is the owner of the project logger.debug "User #{@user.login} wants to change the project" - if project.is_a?(Project) + case project + when Project prj = project - elsif project.is_a?(String) + when String prj = Project.find_by_name(project) # avoid remote projects return false unless prj.is_a?(Project) diff --git a/src/api/app/models/bs_request.rb b/src/api/app/models/bs_request.rb index ce1fc8c2e66..af8d422a148 100644 --- a/src/api/app/models/bs_request.rb +++ b/src/api/app/models/bs_request.rb @@ -748,16 +748,17 @@ def change_review_state(new_review_state, opts = {}) self.comment = review.reason self.state = new_request_state self.commenter = User.session!.login - if new_request_state == :new + case new_request_state + when :new self.comment = 'All reviewers accepted request' save! Event::RequestReviewsDone.create(event_parameters) HistoryElement::RequestAllReviewsApproved.create(history_parameters) # pre-approved requests can be processed BsRequestAutoAcceptJob.perform_later(id) if approver - elsif new_request_state == :review + when :review save! - elsif new_request_state == :declined + when :declined HistoryElement::RequestDeclined.create(history_parameters) save! end diff --git a/src/api/app/models/event_subscription.rb b/src/api/app/models/event_subscription.rb index f5933c89101..efdc1382780 100644 --- a/src/api/app/models/event_subscription.rb +++ b/src/api/app/models/event_subscription.rb @@ -31,9 +31,10 @@ class EventSubscription < ApplicationRecord scope :for_eventtype, ->(eventtype) { where(eventtype: eventtype) } scope :defaults, -> { where(user_id: nil, group_id: nil) } scope :for_subscriber, lambda { |subscriber| - if subscriber.is_a?(User) + case subscriber + when User where(user: subscriber) - elsif subscriber.is_a?(Group) + when Group where(group: subscriber) else defaults @@ -49,9 +50,10 @@ def subscriber end def subscriber=(subscriber) - if subscriber.is_a?(User) + case subscriber + when User self.user = subscriber - elsif subscriber.is_a?(Group) + when Group self.group = subscriber end end diff --git a/src/api/app/models/event_subscription/find_for_event.rb b/src/api/app/models/event_subscription/find_for_event.rb index b77cbc9b856..300f6b59b0b 100644 --- a/src/api/app/models/event_subscription/find_for_event.rb +++ b/src/api/app/models/event_subscription/find_for_event.rb @@ -54,10 +54,11 @@ def filter_and_convert_groups_without_emails_to_users(receivers) new_receivers = [] receivers.each do |receiver| - if receiver.is_a?(User) + case receiver + when User new_receivers << receiver - elsif receiver.is_a?(Group) + when Group if receiver.email.present? new_receivers << receiver diff --git a/src/api/app/models/project.rb b/src/api/app/models/project.rb index 45bc188bb72..eeec73769d8 100644 --- a/src/api/app/models/project.rb +++ b/src/api/app/models/project.rb @@ -367,9 +367,10 @@ def validate_remote_permissions(request_data) end def has_dod_elements?(request_data) - if request_data.is_a?(Array) + case request_data + when Array request_data.any? { |r| r['download'] } - elsif request_data.is_a?(Hash) + when Hash request_data['download'].present? end end diff --git a/src/api/app/models/review.rb b/src/api/app/models/review.rb index 7299933c86c..98b301c1ac2 100644 --- a/src/api/app/models/review.rb +++ b/src/api/app/models/review.rb @@ -233,11 +233,12 @@ def change_state(new_state, comment) Event::ReviewChanged.create(bs_request.event_parameters) arguments = { review: self, comment: comment, user: User.session! } - if new_state == :accepted + case new_state + when :accepted HistoryElement::ReviewAccepted.create(arguments) - elsif new_state == :declined + when :declined HistoryElement::ReviewDeclined.create(arguments) - elsif new_state == :new + else HistoryElement::ReviewReopened.create(arguments) end true diff --git a/src/api/app/views/statistics/highest_rated.xml.builder b/src/api/app/views/statistics/highest_rated.xml.builder index 610b9d6864d..d9d902054b9 100644 --- a/src/api/app/views/statistics/highest_rated.xml.builder +++ b/src/api/app/views/statistics/highest_rated.xml.builder @@ -1,13 +1,14 @@ xml.highest_rated do @ratings.each do |rating| - if rating.object_type == 'Package' + case rating.object_type + when 'Package' xml.package( score: rating.score_calculated, count: rating.count, project: rating.packages.project.name, name: rating.packages.name ) - elsif rating.object_type == 'Project' + when 'Project' xml.project( score: rating.score_calculated, count: rating.count, diff --git a/src/api/config/application.rb b/src/api/config/application.rb index a673df397fe..9ba8d70fa99 100644 --- a/src/api/config/application.rb +++ b/src/api/config/application.rb @@ -4,7 +4,7 @@ # Assets should be precompiled for production (so we don't need the gems loaded then) Bundler.require(*Rails.groups(assets: ['development', 'test'])) -require_relative '../lib/rabbitmq_bus.rb' +require_relative '../lib/rabbitmq_bus' module OBSApi class Application < Rails::Application diff --git a/src/api/db/data/20170831143534_convert_notifications_event_payload_to_json.rb b/src/api/db/data/20170831143534_convert_notifications_event_payload_to_json.rb index 41aeb56b416..66b10813290 100644 --- a/src/api/db/data/20170831143534_convert_notifications_event_payload_to_json.rb +++ b/src/api/db/data/20170831143534_convert_notifications_event_payload_to_json.rb @@ -41,10 +41,11 @@ def traverse(&block) private def traverse_value(value, &block) - if value.is_a?(Hash) + case value + when Hash value.each { |key, sub_value| value[key] = traverse_value(sub_value, &block) } - elsif value.is_a?(Array) + when Array value.map { |element| traverse_value(element, &block) } else diff --git a/src/api/lib/tasks/statistics/github/code_frequency.rake b/src/api/lib/tasks/statistics/github/code_frequency.rake index 4033fb33702..d596a9e70ba 100644 --- a/src/api/lib/tasks/statistics/github/code_frequency.rake +++ b/src/api/lib/tasks/statistics/github/code_frequency.rake @@ -7,9 +7,10 @@ namespace :statistics do # The first time you make this request to github, it returns an empty json response with status 202 # because github generates the statistics asynchronously. Once they are generated will be 200. - if response.code == '202' + case response.code + when '202' puts 'Statistics are being generated in the background by github. Please re-run this task in a minute to get the results.' - elsif response.code == '200' + when '200' weeks = JSON.parse(response.body) File.open('code_frequency.csv', 'w') do |file| diff --git a/src/api/lib/tasks/statistics/github/commit_activity.rake b/src/api/lib/tasks/statistics/github/commit_activity.rake index 744b6261937..7b90e9b49ad 100644 --- a/src/api/lib/tasks/statistics/github/commit_activity.rake +++ b/src/api/lib/tasks/statistics/github/commit_activity.rake @@ -7,9 +7,10 @@ namespace :statistics do # The first time you make this request to github, it returns an empty json response with status 202 # because github generates the statistics asynchronously. Once they are generated will be 200. - if response.code == '202' + case response.code + when '202' puts 'Statistics are being generated in the background by github. Please re-run this task in a minute to get the results.' - elsif response.code == '200' + when '200' weeks = JSON.parse(response.body) File.open('commit_activity.csv', 'w') do |file| diff --git a/src/api/lib/xpath_engine.rb b/src/api/lib/xpath_engine.rb index 78ee89fd888..be327fa9dc6 100644 --- a/src/api/lib/xpath_engine.rb +++ b/src/api/lib/xpath_engine.rb @@ -389,7 +389,8 @@ def parse_predicate(root, stack) __send__(fname_int, root, *stack.shift) when :child qtype = stack.shift - if qtype == :qname + case qtype + when :qname stack.shift root << stack.shift qtype = stack.shift @@ -404,7 +405,7 @@ def parse_predicate(root, stack) parse_predicate(root, qtype) end root.pop - elsif qtype == :any + when :any # noop, already shifted else raise IllegalXpathError, "unhandled token '#{t.inspect}'" diff --git a/src/api/spec/controllers/webui/users_controller_spec.rb b/src/api/spec/controllers/webui/users_controller_spec.rb index 73fc93ce145..cec7f80eaeb 100644 --- a/src/api/spec/controllers/webui/users_controller_spec.rb +++ b/src/api/spec/controllers/webui/users_controller_spec.rb @@ -369,7 +369,7 @@ it 'returns user token as array of hash' do get :tokens, params: { q: 'foo', format: :json } - expect(JSON.parse(response.body)).to match_array(['name' => 'foobaz']) + expect(JSON.parse(response.body)).to match_array([{ 'name' => 'foobaz' }]) end end diff --git a/src/api/spec/db/data/project_log_entry_user_name_spec.rb b/src/api/spec/db/data/project_log_entry_user_name_spec.rb index b30ec1205df..d8459a7ffcb 100644 --- a/src/api/spec/db/data/project_log_entry_user_name_spec.rb +++ b/src/api/spec/db/data/project_log_entry_user_name_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -require_relative '../../../db/data/20180214132015_project_log_entry_user_name.rb' +require_relative '../../../db/data/20180214132015_project_log_entry_user_name' RSpec.describe ProjectLogEntryUserName, type: :model do let(:user) { create(:confirmed_user) } diff --git a/src/api/spec/factories/project.rb b/src/api/spec/factories/project.rb index db1dba559a1..ecba06a499c 100644 --- a/src/api/spec/factories/project.rb +++ b/src/api/spec/factories/project.rb @@ -14,11 +14,12 @@ if evaluator.maintainer role = Role.find_by_title('maintainer') - maintainers = [*evaluator.maintainer] + maintainers = Array(evaluator.maintainer) maintainers.each do |maintainer| - if maintainer.is_a?(User) + case maintainer + when User project.relationships.build(user: maintainer, role: role) - elsif maintainer.is_a?(Group) + when Group project.relationships.build(group: maintainer, role: role) end end @@ -191,7 +192,7 @@ factory :staging_project do # Staging workflows have 2 staging projects by default, *:Staging:A and *:Staging:B. - sequence(:name, [*'C'..'Z'].cycle) { |letter| "#{staging_workflow.project.name}:Staging:#{letter}" } + sequence(:name, Array('C'..'Z').cycle) { |letter| "#{staging_workflow.project.name}:Staging:#{letter}" } end end end diff --git a/src/api/spec/factories/staging_workflow.rb b/src/api/spec/factories/staging_workflow.rb index fa7d4d4ecd5..4166deee587 100644 --- a/src/api/spec/factories/staging_workflow.rb +++ b/src/api/spec/factories/staging_workflow.rb @@ -17,7 +17,7 @@ after(:create) do |staging_workflow, evaluator| # StagingWorkflow have some staging projects already after initialize new_staging_projects_count = evaluator.staging_project_count - staging_workflow.staging_projects.count - letters = [*'A'..'Z'] + letters = Array('A'..'Z') new_staging_projects_count.times do |index| letter = letters[index + staging_workflow.staging_projects.count] staging_workflow.staging_projects << create(:staging_project, name: "#{staging_workflow.project.name}:Staging:#{letter}", maintainer: staging_workflow.managers_group) diff --git a/src/api/spec/models/bs_request_spec.rb b/src/api/spec/models/bs_request_spec.rb index 2ae4bf127a3..12d5a840d21 100644 --- a/src/api/spec/models/bs_request_spec.rb +++ b/src/api/spec/models/bs_request_spec.rb @@ -377,7 +377,7 @@ context "when there is no action with type 'submit'" do let(:request_actions) do [ - { type: :foo, sourcediff: ['files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]]] }, + { type: :foo, sourcediff: [{ 'files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]] }] }, { type: 'bar' } ] end @@ -388,7 +388,7 @@ context 'when there is no sourcediff' do let(:request_actions) do [ - { type: :foo, sourcediff: ['files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]]] }, + { type: :foo, sourcediff: [{ 'files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]] }] }, { type: :submit } ] end @@ -409,7 +409,7 @@ context 'when the diff is at least one diff that has a shown attribute' do let(:request_actions) do - [{ type: :submit, sourcediff: ['files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]]] }] + [{ type: :submit, sourcediff: [{ 'files' => [['./my_file', { 'diff' => { 'shown' => '200' } }]] }] }] end it { expect(BsRequest.truncated_diffs?(request_actions)).to eq(true) } @@ -417,7 +417,7 @@ context 'when none of the diffs has a shown attribute' do let(:request_actions) do - [{ type: :submit, sourcediff: ['files' => [['./my_file', { 'diff' => { 'rev' => '1' } }]]] }] + [{ type: :submit, sourcediff: [{ 'files' => [['./my_file', { 'diff' => { 'rev' => '1' } }]] }] }] end it { expect(BsRequest.truncated_diffs?(request_actions)).to eq(false) } @@ -425,7 +425,7 @@ context "when there is a sourcediff attribute with no 'files'" do let(:request_actions) do - [{ type: :submit, sourcediff: ['other_data' => 'foo'] }] + [{ type: :submit, sourcediff: [{ 'other_data' => 'foo' }] }] end it { expect(BsRequest.truncated_diffs?(request_actions)).to eq(false) } diff --git a/src/api/spec/models/user_spec.rb b/src/api/spec/models/user_spec.rb index e9fe27d0c4f..dd456e64665 100644 --- a/src/api/spec/models/user_spec.rb +++ b/src/api/spec/models/user_spec.rb @@ -565,7 +565,7 @@ describe '#autocomplete_token' do subject { User.autocomplete_token('foo') } - it { expect(subject).to match_array([name: 'foobar']) } + it { expect(subject).to match_array([{ name: 'foobar' }]) } end end diff --git a/src/api/spec/support/database_cleaner.rb b/src/api/spec/support/database_cleaner.rb index dcce1c702ae..a4dd44a1092 100644 --- a/src/api/spec/support/database_cleaner.rb +++ b/src/api/spec/support/database_cleaner.rb @@ -11,15 +11,15 @@ config.before(:suite) do # Truncate all tables loaded in db/seeds.rb, except the static ones, in the # beginning to be consistent. - DatabaseCleaner.clean_with(:truncation, except: STATIC_TABLES) + DatabaseCleaner.clean_with(:deletion, except: STATIC_TABLES) end config.before do |example| - # For feature test we use truncation instead of transactions because the + # For feature test we use deletion instead of transactions because the # test suite and the capybara driver do not use the same server thread. if example.metadata[:type] == :feature || example.metadata[:type] == :migration || example.metadata[:thinking_sphinx] == true # Omit truncating what we have set up in db/seeds.rb except users and roles_user - DatabaseCleaner.strategy = :truncation, { except: STATIC_TABLES } + DatabaseCleaner.strategy = :deletion, { except: STATIC_TABLES } else DatabaseCleaner.strategy = :transaction end diff --git a/src/api/test/functional/published_controller_test.rb b/src/api/test/functional/published_controller_test.rb index aefe1118f4c..b6d0e593c25 100644 --- a/src/api/test/functional/published_controller_test.rb +++ b/src/api/test/functional/published_controller_test.rb @@ -116,12 +116,13 @@ def test_rpm_md_formats assert_equal 'myself', p['format']['rpm:provides']['rpm:entry'][0]['name'] assert_equal 'something', p['format']['rpm:conflicts']['rpm:entry']['name'] assert_equal 'old_crap', p['format']['rpm:obsoletes']['rpm:entry']['name'] - if p['name'] == 'package' + case p['name'] + when 'package' assert_equal 'package-1.0-1.src.rpm', p['format']['rpm:sourcerpm'] assert_equal '2156', p['format']['rpm:header-range']['end'] assert_equal 'package', p['format']['rpm:provides']['rpm:entry'][1]['name'] assert_equal 'package(x86-32)', p['format']['rpm:provides']['rpm:entry'][2]['name'] - elsif p['name'] == 'package_newweaktags' + when 'package_newweaktags' assert_equal 'package_newweaktags-1.0-1.src.rpm', p['format']['rpm:sourcerpm'] assert_equal '2300', p['format']['rpm:header-range']['end'] assert_equal 'package_newweaktags', p['format']['rpm:provides']['rpm:entry'][1]['name'] diff --git a/src/api/test/unit/schema_test.rb b/src/api/test/unit/schema_test.rb index ed38db8895c..229d7a10cdf 100644 --- a/src/api/test/unit/schema_test.rb +++ b/src/api/test/unit/schema_test.rb @@ -5,12 +5,13 @@ class SchemaTest < ActiveSupport::TestCase test 'schemas' do Find.find(CONFIG['schema_location']).each do |f| io = nil - if %r{\.rng$}.match?(f) + case f + when %r{\.rng$} testfile = f.gsub(%r{\.rng$}, '.xml') if File.exist?(testfile) io = IO.popen("xmllint --noout --relaxng #{f} #{testfile} 2>&1 > /dev/null", 'r') end - elsif %r{xsd}.match?(f) + when %r{xsd} testfile = f.gsub(%r{\.xsd$}, '.xml') if File.exist?(testfile) io = IO.popen("xmllint --noout --schema #{f} #{testfile} 2>&1 > /dev/null", 'r') From 2968e173e3f7abb6d1ad9bfbe8704275a33f3bc3 Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Tue, 14 Jul 2020 17:02:07 +0200 Subject: [PATCH 3/6] Transform case into hash lookup This fixes the `Style/HashLikeCase` cop which got introduced after the rubocop gem update from version 0.87.1 to 0.88.0 --- .../app/controllers/webui/webui_controller.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/api/app/controllers/webui/webui_controller.rb b/src/api/app/controllers/webui/webui_controller.rb index c539b68a2f1..f9aab90bb4c 100644 --- a/src/api/app/controllers/webui/webui_controller.rb +++ b/src/api/app/controllers/webui/webui_controller.rb @@ -247,17 +247,11 @@ def require_package private def send_login_information_rabbitmq(msg) - message = case msg - when :success - 'login,access_point=webui value=1' - when :disabled - 'login,access_point=webui,failure=disabled value=1' - when :logout - 'logout,access_point=webui value=1' - when :unauthenticated - 'login,access_point=webui,failure=unauthenticated value=1' - end - RabbitmqBus.send_to_bus('metrics', message) + message_mapping = { success: 'login,access_point=webui value=1', + disabled: 'login,access_point=webui,failure=disabled value=1', + logout: 'logout,access_point=webui value=1', + unauthenticated: 'login,access_point=webui,failure=unauthenticated value=1' } + RabbitmqBus.send_to_bus('metrics', message_mapping[msg]) end def authenticator From 33ab5c82a4a5758cdc4ce85a3ce9b81d4fd6a67d Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Wed, 15 Jul 2020 14:18:48 +0200 Subject: [PATCH 4/6] Revert rubocop autocorrection for Style/ArrayCoercion The autocorrection for this part of the code introduced changes in the behaviour of it. Therefore we ignore the cop here, and keep the code as it is. --- src/api/spec/factories/project.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/spec/factories/project.rb b/src/api/spec/factories/project.rb index ecba06a499c..e65721e73f9 100644 --- a/src/api/spec/factories/project.rb +++ b/src/api/spec/factories/project.rb @@ -190,9 +190,11 @@ end end + # rubocop:disable Style/ArrayCoercion factory :staging_project do # Staging workflows have 2 staging projects by default, *:Staging:A and *:Staging:B. - sequence(:name, Array('C'..'Z').cycle) { |letter| "#{staging_workflow.project.name}:Staging:#{letter}" } + sequence(:name, [*'C'..'Z'].cycle) { |letter| "#{staging_workflow.project.name}:Staging:#{letter}" } end + # rubocop:enable Style/ArrayCoercion end end From 1de2cc9c22bd9d0c5441672a2116ab6a66bb48c7 Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Wed, 15 Jul 2020 15:14:26 +0200 Subject: [PATCH 5/6] Extract helper and replace if with case Address Style/CaseLikeIf cop and move logic from view to a helper method (addressing a FIXME comment). --- src/api/app/helpers/webui/buildresult_helper.rb | 12 ++++++++++++ .../app/views/webui/package/_rpmlint_log.html.haml | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api/app/helpers/webui/buildresult_helper.rb b/src/api/app/helpers/webui/buildresult_helper.rb index aee886b83fd..b4199b7e39e 100644 --- a/src/api/app/helpers/webui/buildresult_helper.rb +++ b/src/api/app/helpers/webui/buildresult_helper.rb @@ -64,4 +64,16 @@ def collapse_link(expanded, main_name, repository_name = nil) end end end + + # Paints an rpmlog line green-ish when the line has a Warning and red when it has an error. + def colorize_line(line) + case line + when /\w+(?:\.\w+)+: W: / + tag.span(line.strip, style: 'color: olive;') + when /\w+(?:\.\w+)+: E: / + tag.span(line.strip, style: 'color: red;') + else + line.strip + end + end end diff --git a/src/api/app/views/webui/package/_rpmlint_log.html.haml b/src/api/app/views/webui/package/_rpmlint_log.html.haml index a0b80504aa0..d9317cec22a 100644 --- a/src/api/app/views/webui/package/_rpmlint_log.html.haml +++ b/src/api/app/views/webui/package/_rpmlint_log.html.haml @@ -1,8 +1,2 @@ --# FIXME: move this into a helper - @log.lines.each do |line| - - if /\w+(?:\.\w+)+: W: /.match?(line) - = tag.span(line.strip, style: 'color: olive;') - - elsif /\w+(?:\.\w+)+: E: /.match?(line) - = tag.span(line.strip, style: 'color: red;') - - else - = line.strip + = colorize_line(line) From 6909ea77bad28fbb3db9cd214e359a9cfafa7e5b Mon Sep 17 00:00:00 2001 From: Lukas Krause Date: Thu, 16 Jul 2020 22:48:55 +0200 Subject: [PATCH 6/6] Fix regex match group handling after moving to case statements The rubocop autocorrect for Style/CaseLikeIf does not take into account the match operator for regex, which in this case returns the matched data when using it with and if/elsif statement. After just moving this to an case statement, the data is not returned anymore. This could be fixed by using the `$LAST_MATCH_INFO` pseudo variable which contains the whole `MatchData` object of the latest regex matching group. --- src/api/app/controllers/webui/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/app/controllers/webui/repositories_controller.rb b/src/api/app/controllers/webui/repositories_controller.rb index 137052b967b..3f56d67e48f 100644 --- a/src/api/app/controllers/webui/repositories_controller.rb +++ b/src/api/app/controllers/webui/repositories_controller.rb @@ -197,9 +197,9 @@ def follow_change_flag_command(flag_type) case params[:command] when 'remove' @main_object.flags.of_type(flag_type).where(repo: params[:repository], architecture: architecture).delete_all - when %r{^set-(?disable|enable)$} + when /^set-(?disable|enable)$/ flag = @main_object.flags.find_or_create_by(flag: flag_type, repo: params[:repository], architecture: architecture) - flag.update(status: status) + flag.update(status: $LAST_MATCH_INFO['status']) end @main_object.store end