From 31772eacdcaef219d765b927fdd3caa7bb81eccf Mon Sep 17 00:00:00 2001 From: Alex Kiessling <32677188+ajkiessl@users.noreply.github.com> Date: Thu, 23 Mar 2023 09:20:58 -0400 Subject: [PATCH] Clean up. Make sure this works with ruby 3.1 (#24) * Ruby version at 3.1.3. Requiring 3.1.x in gemspec. Upgrade rubocop and rubocop-rspec. Fixed rubocop alerts. * use different ruby setup for 3.1.3 * Remove bundle-audit. Not needed. We have dependabot * update readme --- .github/workflows/ruby-ci.yml | 6 +-- .rubocop.yml | 4 ++ .ruby-version | 2 +- .travis.yml | 33 -------------- Gemfile | 2 - Gemfile.lock | 45 ++++++++++--------- README.md | 2 +- etda_utilities.gemspec | 2 + lib/etda_utilities/access_level.rb | 1 + lib/etda_utilities/etda_file_paths.rb | 12 ++--- lib/etda_utilities/hosts.rb | 16 ++----- spec/lib/etda_utilities_access_level_spec.rb | 10 ++--- .../etda_utilities_etda_file_paths_spec.rb | 18 ++++++-- spec/lib/etda_utilities_hosts_spec.rb | 16 +++++++ spec/lib/etda_utilities_partner_spec.rb | 36 +++++++++++++++ 15 files changed, 115 insertions(+), 90 deletions(-) delete mode 100755 .travis.yml diff --git a/.github/workflows/ruby-ci.yml b/.github/workflows/ruby-ci.yml index a4d3ea6..0a41845 100644 --- a/.github/workflows/ruby-ci.yml +++ b/.github/workflows/ruby-ci.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v2 # Add or replace dependency steps here - name: Install Ruby and gems - uses: ruby/setup-ruby@8f312efe1262fb463d906e9bf040319394c18d3e # v1.92 + uses: ruby/setup-ruby@v1 with: bundler-cache: true # Add or replace test runners here @@ -33,11 +33,9 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Install Ruby and gems - uses: ruby/setup-ruby@8f312efe1262fb463d906e9bf040319394c18d3e # v1.92 + uses: ruby/setup-ruby@v1 with: bundler-cache: true # Add or replace any other lints here - - name: Security audit dependencies - run: bundle exec bundle-audit - name: Lint Ruby files run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index dfa560b..a762458 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -160,3 +160,7 @@ Style/BlockDelimiters: Naming/FileName: Exclude: + +Style/OptionalBooleanParameter: + Exclude: + - 'lib/etda_utilities/hosts.rb' diff --git a/.ruby-version b/.ruby-version index a4dd9db..ff365e0 100755 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.4 +3.1.3 diff --git a/.travis.yml b/.travis.yml deleted file mode 100755 index 1a9892d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: ruby -cache: bundler -sudo: required -#rvm: -#- 2.6.0 -jdk: -- oraclejdk12 -env: - global: - - NOKOGIRI_USE_SYSTEM_LIBRARIES=true - - JS=true -before_install: - - "gem --version" - - "gem update --system" - - "gem --version" - - 'gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"' -script: -- gem install bundler -- gem install rspec -- bundle exec rubocop -- bundle exec rspec -notifications: - email: - recipients: - secure: "l84DQVl48Z4/O/H/zAHFL6GmnBe5BHGQZj2rBv2/X7j1QfOOQEb3h0ZVk5+RdlGLvNjgc8va0sI6JJWa8QuQa68/T6RfcBoZHb90pKOIRoZOVjiwwUYC+mdRMv5s0vemJ2VxreAoJl5JmJ6TLvy5w52G7mmMOm+1VuYPv3MuvZ3nbFwm15qz6LxiRhyUJhaXcZhi1emZYsRd+qazQ9HlkKWMoCz68gi8zWVULnRbZSIHIEj4GV5bn9L67u+699LgIjKrT1Xeh0wnb/wtPIrgwheSksgqYcaRRkBmkaajjss2Zeg5m5hUteTTsx6mSAk3QSTjqVQ0t/Kh5En68W4B/VnA8qiuLolzHqaTqid8sa4rvh/JVAU3zsOvMun5f3OZzdgf7VTXM/E3A+L25KrVTk9UcQnPHcvJvdAIlr0ZZTX2G+3Vs/XSEPQk4KRfLFSqLUm4uYvh9INki7SlB7lllYudSMQzV/5Ghg2K6UaxP9PDRRxOCVPWeYuR3H3tesdBciv+6+d3LxDdAWVbxZwphlGtS5N7NlIl2du888wQ5COaOwSAlXIQWdRvvVfvvQaTTY245jdsiToNX+KSf27bT+szpHyzOaIsT1kO4DAIdSlSxdSK600GsM5RY80iIF92mFc9EjK24WqFZ0PpaSRZ3L4aUvl+HbdS/K4+q1uTCTM=" - on_success: change - on_failure: always - irc: - channels: - template: - - - diff --git a/Gemfile b/Gemfile index 2578a57..c0ddcbb 100755 --- a/Gemfile +++ b/Gemfile @@ -11,5 +11,3 @@ gem 'rubocop', require: false gem 'rubocop-rspec', require: false gem 'byebug', require: false - -gem 'bundle-audit', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 2c4d950..4f64cad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,20 +6,16 @@ PATH GEM remote: https://rubygems.org/ specs: - ast (2.4.0) - bundle-audit (0.1.0) - bundler-audit - bundler-audit (0.6.1) - bundler (>= 1.2.0, < 3) - thor (~> 0.18) + ast (2.4.2) byebug (11.1.1) diff-lcs (1.3) - jaro_winkler (1.5.4) - parallel (1.19.1) - parser (2.7.0.5) - ast (~> 2.4.0) - rainbow (3.0.0) + json (2.6.3) + parallel (1.22.1) + parser (3.2.1.1) + ast (~> 2.4.1) + rainbow (3.1.1) rake (13.0.1) + regexp_parser (2.7.0) rexml (3.2.5) rspec (3.7.0) rspec-core (~> 3.7.0) @@ -34,25 +30,30 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.7.0) rspec-support (3.7.1) - rubocop (0.80.1) - jaro_winkler (~> 1.5.1) + rubocop (1.48.1) + json (~> 2.3) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) - rexml + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.26.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - rubocop-rspec (1.30.1) - rubocop (>= 0.60.0) - ruby-progressbar (1.10.1) - thor (0.20.3) - unicode-display_width (1.6.1) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.27.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.1) + rubocop (~> 1.41) + rubocop-rspec (2.19.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + ruby-progressbar (1.13.0) + unicode-display_width (2.4.2) PLATFORMS ruby DEPENDENCIES - bundle-audit bundler (~> 2.3.a) byebug etda_utilities! diff --git a/README.md b/README.md index 03932a1..a4260a6 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # EtdaUtilities -[![Build Status](https://travis-ci.com/psu-stewardship/etda_utilities.svg?token=aQpbqAxsm8KshbvyB24o&branch=master)](https://travis-ci.com/psu-stewardship/etda_utilities) +![CI](https://github.com/psu-libraries/etda_utilities/actions/workflows/ruby-ci.yml/badge.svg) Common methods used by etda_workflow and etda_explore diff --git a/etda_utilities.gemspec b/etda_utilities.gemspec index c46da03..b1a6fdd 100755 --- a/etda_utilities.gemspec +++ b/etda_utilities.gemspec @@ -22,6 +22,8 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib", "lib/etda_utilities"] + spec.required_ruby_version = '~> 3.1' + spec.add_development_dependency "bundler", "~> 2.3.a" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.0" diff --git a/lib/etda_utilities/access_level.rb b/lib/etda_utilities/access_level.rb index af9927c..545e30c 100755 --- a/lib/etda_utilities/access_level.rb +++ b/lib/etda_utilities/access_level.rb @@ -6,6 +6,7 @@ module EtdaUtilities class AccessLevel attr_accessor :attributes + # attr_accessor :current_access_level # *** IMPORTANT NOTE *** # The order of the keys in this array matter and they should go from least restrictive to most restrictive diff --git a/lib/etda_utilities/etda_file_paths.rb b/lib/etda_utilities/etda_file_paths.rb index c48548d..1ad04aa 100755 --- a/lib/etda_utilities/etda_file_paths.rb +++ b/lib/etda_utilities/etda_file_paths.rb @@ -15,29 +15,29 @@ def explore_base_path end def workflow_upload_final_files_path - workflow_base_path + 'final_submission_files/' + "#{workflow_base_path}final_submission_files/" end def workflow_upload_format_review_path - workflow_base_path + 'format_review_files/' + "#{workflow_base_path}format_review_files/" end def workflow_restricted - workflow_base_path + RESTRICTED_DIR + '/' + "#{workflow_base_path}#{RESTRICTED_DIR}/" end def explore_open - explore_base_path + OPEN_DIR + '/' + "#{explore_base_path}#{OPEN_DIR}/" end def explore_psu_only - explore_base_path + RESTRICTED_INSTITUTION_DIR + '/' + "#{explore_base_path}#{RESTRICTED_INSTITUTION_DIR}/" end def detailed_file_path(file_id) str1 = format("%02d", ((file_id.to_i || 0) % 100)) str2 = file_id.to_s - str1 + '/' + str2 + '/' + "#{str1}/#{str2}/" end def explore_download_file_path(file_id, access_level, filename) diff --git a/lib/etda_utilities/hosts.rb b/lib/etda_utilities/hosts.rb index 8f4cb71..84bd8e2 100755 --- a/lib/etda_utilities/hosts.rb +++ b/lib/etda_utilities/hosts.rb @@ -9,7 +9,7 @@ def workflow_url(partner = nil, host = nil) else raise ArgumentError, "_partner and _host are required arguments" if partner.nil? || host.nil? - "https://" + new.workflow_submit_host(partner, host) + "https://#{new.workflow_submit_host(partner, host)}" end end @@ -19,7 +19,7 @@ def explore_url(partner = nil, host = nil) else raise ArgumentError, "_partner and _host are required arguments" if partner.nil? || host.nil? - "https://" + new.explore_host(partner, host) + "https://#{new.explore_host(partner, host)}" end end end @@ -56,16 +56,8 @@ def host_application(is_workflow = false) end def partner_host(partner) - case partner - when 'graduate' - "etda" - when 'honors' - "honors" - when 'milsch' - "millennium-scholars" - when 'sset' - "sset" - end + host_hash = { 'graduate' => "etda", 'honors' => "honors", 'milsch' => "millennium-scholars", 'sset' => "sset" } + host_hash[partner] end end end diff --git a/spec/lib/etda_utilities_access_level_spec.rb b/spec/lib/etda_utilities_access_level_spec.rb index e032ad7..80c5e71 100755 --- a/spec/lib/etda_utilities_access_level_spec.rb +++ b/spec/lib/etda_utilities_access_level_spec.rb @@ -2,19 +2,19 @@ RSpec.describe EtdaUtilities::AccessLevel, type: :model do describe 'AccessLevel' do - context '#ACCESS_LEVEL_KEYS' do + describe '#ACCESS_LEVEL_KEYS' do it 'constant containing all access levels' do - expect(described_class::ACCESS_LEVEL_KEYS).to match_array(['open_access', 'restricted_to_institution', 'restricted', '']) + expect(described_class::ACCESS_LEVEL_KEYS).to contain_exactly('open_access', 'restricted_to_institution', 'restricted', '') end end - context '#paper_access_level_keys' do + describe '#paper_access_level_keys' do it '#paper_access_level_keys returns an array of access_levels' do expect(described_class::ACCESS_LEVEL_KEYS).to match_array(described_class.paper_access_level_keys) end end - context '#partner_access_level' do + describe '#partner_access_level' do it 'returns access level information from a yml file' do yml_level = described_class.partner_access_levels['access_level'] expect(yml_level['open_access']).to include('Open Access') @@ -23,7 +23,7 @@ end end - context '#valid_levels' do + describe '#valid_levels' do it 'returns access_levels including no level' do expect(described_class.valid_levels).to match_array(described_class.paper_access_level_keys) end diff --git a/spec/lib/etda_utilities_etda_file_paths_spec.rb b/spec/lib/etda_utilities_etda_file_paths_spec.rb index 2137423..20acfe3 100755 --- a/spec/lib/etda_utilities_etda_file_paths_spec.rb +++ b/spec/lib/etda_utilities_etda_file_paths_spec.rb @@ -2,10 +2,11 @@ RSpec.describe EtdaUtilities::EtdaFilePaths, type: :model do describe 'EtdaFilePaths' do - context '#base_path' do + describe '#base_path' do it 'returns default workflow_base_path' do expect(described_class.new.workflow_base_path).to eql('tmp/') end + it 'returns default explore_default path' do expect(described_class.new.explore_base_path).to eql('tmp/') end @@ -15,12 +16,13 @@ it 'returns final-files path' do expect(subject.workflow_upload_final_files_path).to eql('tmp/final_submission_files/') end + it 'returns format-review path' do expect(subject.workflow_upload_format_review_path).to eql('tmp/format_review_files/') end end - context '#workflow_restricted' do + describe '#workflow_restricted' do it 'returns path of published restricted files' do expect(subject.workflow_restricted).to eql('tmp/restricted/') end @@ -30,53 +32,61 @@ it 'returns path of restricted to institution files' do expect(subject.explore_psu_only).to eql('tmp/restricted_institution/') end + it 'returns path of open_access files' do expect(subject.explore_open).to eql('tmp/open_access/') end end - context '#detailed_file_path' do + describe '#detailed_file_path' do it 'uses database record id to build the file path' do id = 2 expect(subject.detailed_file_path(id)).to eq('02/2/') id = 11 expect(subject.detailed_file_path(id)).to eq('11/11/') end + it 'works for bigger numbers' do id = 345 expect(subject.detailed_file_path(id)).to eq('45/345/') id = 19857 expect(subject.detailed_file_path(id)).to eq('57/19857/') end + it 'works for a submitted string' do id = "345" expect(subject.detailed_file_path(id)).to eq('45/345/') end end - context '#explore_download_file_path' do + describe '#explore_download_file_path' do file_id = 345 filename = 'myfile.pdf' it 'is nil for restricted files' do access_level = 'restricted' expect(subject.explore_download_file_path(file_id, access_level, filename)).to be_nil end + it 'returns a path for restricted_to_institution records' do access_level = 'restricted_to_institution' expect(subject.explore_download_file_path(file_id, access_level, filename)).to eq('tmp/restricted_institution/45/345/myfile.pdf') end + it 'returns a path for open_access records' do access_level = 'open_access' expect(subject.explore_download_file_path(file_id, access_level, filename)).to eq('tmp/open_access/45/345/myfile.pdf') end + it 'returns nil for unrecognized access levels' do access_level = 'iambogus' expect(subject.explore_download_file_path(file_id, access_level, filename)).to be_nil end + it 'returns nil if access_level is missing' do access_level = '' expect(subject.explore_download_file_path(file_id, access_level, filename)).to be_nil end + it 'returns nil if file_id is missing' do access_level = 'open_access' file_id = nil diff --git a/spec/lib/etda_utilities_hosts_spec.rb b/spec/lib/etda_utilities_hosts_spec.rb index 27019b7..017a5dd 100755 --- a/spec/lib/etda_utilities_hosts_spec.rb +++ b/spec/lib/etda_utilities_hosts_spec.rb @@ -5,27 +5,35 @@ it 'returns the correct production host for workflow graduate' do expect(subject.workflow_submit_host('graduate')).to eq('submit-etda.libraries.psu.edu') end + it 'returns the correct production host for workflow honors' do expect(subject.workflow_submit_host('honors')).to eq('submit-honors.libraries.psu.edu') end + it 'returns the correct production host for workflow millennium scholars' do expect(subject.workflow_submit_host('milsch')).to eq('submit-millennium-scholars.libraries.psu.edu') end + it 'returns the correct production host for workflow sset' do expect(subject.workflow_submit_host('sset')).to eq('submit-sset.libraries.psu.edu') end + it 'returns the correct QA host for workflow graduate' do expect(subject.workflow_submit_host('graduate', 'qa')).to eq('submit-etda-qa.libraries.psu.edu') end + it 'returns the correct QA host for workflow honors' do expect(subject.workflow_submit_host('honors', 'qa')).to eq('submit-honors-qa.libraries.psu.edu') end + it 'returns the correct QA host for workflow millennium scholars' do expect(subject.workflow_submit_host('milsch', 'qa')).to eq('submit-millennium-scholars-qa.libraries.psu.edu') end + it 'returns the correct QA host for workflow sset' do expect(subject.workflow_submit_host('sset', 'qa')).to eq('submit-sset-qa.libraries.psu.edu') end + it 'returns the correct host for workflow if environment is development' do expect(subject.workflow_submit_host('graduate', 'development')).to eq('localhost') end @@ -35,27 +43,35 @@ it 'returns the correct production host for explore graduate' do expect(subject.explore_host('graduate')).to eq('etda.libraries.psu.edu') end + it 'returns the correct production host for explore honors' do expect(subject.explore_host('honors')).to eq('honors.libraries.psu.edu') end + it 'returns the correct production host for explore millennium scholars' do expect(subject.explore_host('milsch')).to eq('millennium-scholars.libraries.psu.edu') end + it 'returns the correct production host for explore sset' do expect(subject.explore_host('sset')).to eq('sset.libraries.psu.edu') end + it 'returns the correct QA host for explore graduate' do expect(subject.explore_host('graduate', 'qa')).to eq('etda-explore-qa.libraries.psu.edu') end + it 'returns the correct QA host for explore honors' do expect(subject.explore_host('honors', 'qa')).to eq('honors-explore-qa.libraries.psu.edu') end + it 'returns the correct QA host for explore millennium scholars' do expect(subject.explore_host('milsch', 'qa')).to eq('millennium-scholars-explore-qa.libraries.psu.edu') end + it 'returns the correct QA host for explore sset' do expect(subject.explore_host('sset', 'qa')).to eq('sset-explore-qa.libraries.psu.edu') end + it 'returns the correct host for explore if environment is development' do expect(subject.explore_host('graduate', 'development')).to eq('localhost') end diff --git a/spec/lib/etda_utilities_partner_spec.rb b/spec/lib/etda_utilities_partner_spec.rb index 1f7edef..ddec0c7 100755 --- a/spec/lib/etda_utilities_partner_spec.rb +++ b/spec/lib/etda_utilities_partner_spec.rb @@ -11,30 +11,39 @@ it 'sets current.id to graduate' do expect(current_partner.id).to eql('graduate') end + it 'responds to graduate?' do expect(current_partner).to be_graduate end + it 'returns partner name' do expect(current_partner.name).to eq("Graduate School") end + it 'returns partner email' do expect(current_partner.email_address).to eq("gradthesis@psu.edu") end + it 'returns partner email list' do expect(current_partner.email_list).to eq('ul-etda-graduate-admin@pennstateoffice365.onmicrosoft.com') end + it 'returns partner slug' do expect(current_partner.slug).to eq("eTD") end + it 'returns partner label' do expect(current_partner.program_label).to eq("Graduate Program") end + it 'returns partner committee label' do expect(current_partner.committee_label).to eq("Committee Member") end + it 'returns partner committee list label' do expect(current_partner.committee_list_label).to eq("Committee Members") end + it 'returns partner header title' do expect(current_partner.header_title).to eq("Electronic Theses and Dissertations for Graduate School") end @@ -50,30 +59,39 @@ it 'sets current.id to honors' do expect(current_partner.id).to eql('honors') end + it 'responds to honors?' do expect(current_partner).to be_honors end + it 'returns partner name' do expect(current_partner.name).to eq("Schreyer Honors College") end + it 'returns partner email' do expect(current_partner.email_address).to eq("SHCAcademics@psu.edu") end + it 'returns partner email list' do expect(current_partner.email_list).to eq('ul-etda-honors-admin@pennstateoffice365.onmicrosoft.com') end + it 'returns partner slug' do expect(current_partner.slug).to eq("eHT") end + it 'returns partner label' do expect(current_partner.program_label).to eq("Area of Honors") end + it 'returns partner committee label' do expect(current_partner.committee_label).to eq("Thesis Supervisor") end + it 'returns partner committee list label' do expect(current_partner.committee_list_label).to eq("Thesis Supervisors") end + it 'returns partner header title' do expect(current_partner.header_title).to eq("Electronic Theses for Schreyer Honors College") end @@ -89,30 +107,39 @@ it 'sets current.id to milsch' do expect(current_partner.id).to eql('milsch') end + it 'responds to milsch?' do expect(current_partner).to be_milsch end + it 'returns partner name' do expect(current_partner.name).to eq("Millennium Scholars Program") end + it 'returns partner email' do expect(current_partner.email_address).to eq("millennium@psu.edu") end + it 'returns partner email list' do expect(current_partner.email_list).to eq('ul-etda-milsch-admin@pennstateoffice365.onmicrosoft.com') end + it 'returns partner slug' do expect(current_partner.slug).to eq("MSPT") end + it 'returns partner label' do expect(current_partner.program_label).to eq("Millennium Scholars Program") end + it 'returns partner committee label' do expect(current_partner.committee_label).to eq("Thesis Supervisor") end + it 'returns partner committee list label' do expect(current_partner.committee_list_label).to eq("Thesis Supervisor") end + it 'returns partner header title' do expect(current_partner.header_title).to eq("Electronic Theses for Millennium Scholars Program") end @@ -128,30 +155,39 @@ it 'sets current.id to sset' do expect(current_partner.id).to eql('sset') end + it 'responds to sset?' do expect(current_partner).to be_sset end + it 'returns partner name' do expect(current_partner.name).to eq("School of Science, Engineering, and Technology") end + it 'returns partner email' do expect(current_partner.email_address).to eq("sset@psu.edu") end + it 'returns partner email list' do expect(current_partner.email_list).to eq('ul-etda-sset-admin@pennstateoffice365.onmicrosoft.com') end + it 'returns partner slug' do expect(current_partner.slug).to eq("SSETT") end + it 'returns program label' do expect(current_partner.program_label).to eq("Program") end + it 'returns partner committee label' do expect(current_partner.committee_label).to eq("Committee Member") end + it 'returns partner committee list label' do expect(current_partner.committee_list_label).to eq("Committee Members") end + it 'returns partner header title' do expect(current_partner.header_title).to eq("Final Papers for the School of Science, Engineering, and Technology") end