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) 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..3f56d67e48f 100644 --- a/src/api/app/controllers/webui/repositories_controller.rb +++ b/src/api/app/controllers/webui/repositories_controller.rb @@ -194,11 +194,12 @@ 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 /^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 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..f9aab90bb4c 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 @@ -246,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 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/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/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) 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..e65721e73f9 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 @@ -189,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, [*'C'..'Z'].cycle) { |letter| "#{staging_workflow.project.name}:Staging:#{letter}" } end + # rubocop:enable Style/ArrayCoercion 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')