Skip to content

Commit

Permalink
Clean up. Make sure this works with ruby 3.1 (#24)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ajkiessl authored Mar 23, 2023
1 parent e46e57b commit 31772ea
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 90 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ruby-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ Style/BlockDelimiters:

Naming/FileName:
Exclude:

Style/OptionalBooleanParameter:
Exclude:
- 'lib/etda_utilities/hosts.rb'
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.1.3
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ gem 'rubocop', require: false
gem 'rubocop-rspec', require: false

gem 'byebug', require: false

gem 'bundle-audit', require: false
45 changes: 23 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions etda_utilities.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/etda_utilities/access_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/etda_utilities/etda_file_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 4 additions & 12 deletions lib/etda_utilities/hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions spec/lib/etda_utilities_access_level_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
18 changes: 14 additions & 4 deletions spec/lib/etda_utilities_etda_file_paths_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 31772ea

Please sign in to comment.