Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Ruby to v3.2.0 and Rails to v8 #1313

Open
wants to merge 5 commits into
base: rails/upgrade-7.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.2.0
3 changes: 1 addition & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[v#.#.#] ([month] [YYYY])
- [entity]:
- [future tense verb] [feature]
- Ruby: Upgrade ruby version to 3.2.0
- Upgraded gems:
- paper_trail, rails, rails-html-sanitizer, rexml, rspec-rails
- Bugs fixes:
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.2'
ruby '3.2.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 7.2.1.1'
Expand Down Expand Up @@ -191,7 +191,7 @@ group :test do
gem 'capybara', '~> 3.39'
gem 'guard-rspec', require: false
gem 'selenium-webdriver', '~> 4.17'
gem 'shoulda-matchers', '~> 3.1'
gem 'shoulda-matchers', '~> 4.0.1'
gem 'timecop'

# Required by capybara
Expand Down Expand Up @@ -221,7 +221,7 @@ gem 'dradis-api', path: 'engines/dradis-api'
gem 'dradis-projects', '~> 4.14.0'

plugins_file = 'Gemfile.plugins'
if File.exists?(plugins_file)
if File.exist?(plugins_file)
eval(IO.read(plugins_file), binding)
end

Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ GEM
resque-status (0.5.0)
resque (~> 1.19)
rexml (3.3.9)
strscan
rinku (2.0.6)
rprogram (0.3.2)
rspec (3.13.0)
Expand Down Expand Up @@ -464,7 +463,7 @@ GEM
rprogram (~> 0.3)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
ruby_audit (2.1.0)
ruby_audit (2.2.0)
bundler-audit (~> 0.9.0)
rubyzip (2.3.2)
sanitize (6.0.2)
Expand All @@ -487,8 +486,8 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shellany (0.0.1)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
simple_form (5.2.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
Expand All @@ -507,7 +506,6 @@ GEM
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
stringio (3.1.1)
strscan (3.1.0)
terser (1.1.15)
execjs (>= 0.3.0, < 3)
thor (1.2.2)
Expand Down Expand Up @@ -633,7 +631,7 @@ DEPENDENCIES
sanitize (= 6.0.2)
sass-rails (~> 6.0)
selenium-webdriver (~> 4.17)
shoulda-matchers (~> 3.1)
shoulda-matchers (~> 4.0.1)
simple_form
sinatra (~> 2.2.3)
spring
Expand All @@ -649,7 +647,7 @@ DEPENDENCIES
whenever

RUBY VERSION
ruby 3.1.2p20
ruby 3.2.0p0

BUNDLED WITH
2.3.16
10 changes: 5 additions & 5 deletions app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Attachment < File
require 'fileutils'
# Set the path to the attachment storage
AttachmentPwd = Rails.env.test? ? Rails.root.join('tmp', 'attachments') : Rails.root.join('attachments')
FileUtils.mkdir_p(AttachmentPwd) unless File.exists?(AttachmentPwd)
FileUtils.mkdir_p(AttachmentPwd) unless File.exist?(AttachmentPwd)

SCREENSHOT_REGEX = /\!((https?:\/\/.+)|((\/pro)?\/projects\/(\d+)\/nodes\/(\d+)\/attachments\/(.+?)(\(.*\))?))\!/i

Expand Down Expand Up @@ -164,7 +164,7 @@ def initialize(*args)
@node_id = options[:node_id]
@tempfile = args[0] || options[:tempfile]

if File.exists?(fullpath) && File.file?(fullpath)
if File.exist?(fullpath) && File.file?(fullpath)
super(fullpath, 'rb+')
@initialfile = fullpath.clone
elsif @tempfile && File.basename(@tempfile) != ''
Expand All @@ -177,13 +177,13 @@ def initialize(*args)

# Closes the current file handle, this writes the content to the file system
def save
if File.exists?(fullpath) && File.file?(fullpath)
if File.exist?(fullpath) && File.file?(fullpath)
self.close
else
raise "Node with ID=#{@node_id} does not exist" unless @node_id && Node.exists?(@node_id)

@filename ||= File.basename(@tempfile)
FileUtils.mkdir(File.dirname(fullpath)) unless File.exists?(File.dirname(fullpath))
FileUtils.mkdir(File.dirname(fullpath)) unless File.exist?(File.dirname(fullpath))
self.close
FileUtils.cp(self.path, fullpath) if @intialfile != fullpath
if (@initialfile && @initialfile != fullpath)
Expand Down Expand Up @@ -213,7 +213,7 @@ def copy_to(node)
new_file_path = fullpath(node.id, name)

dir_name = File.dirname new_file_path
FileUtils.mkdir dir_name unless File.exists? dir_name
FileUtils.mkdir dir_name unless File.exist? dir_name

FileUtils.cp fullpath, new_file_path

Expand Down
20 changes: 6 additions & 14 deletions app/models/concerns/file_backed_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# http://asciicasts.com/episodes/219-active-model
# https://github.com/rails/rails/blob/master/activemodel/lib/active_model/conversion.rb
module FileBackedModel

class FileNotFoundException < Exception; end

def self.included(base)
Expand All @@ -25,8 +24,6 @@ def self.included(base)
end
end



module ClassMethods
# ------------------------------------------------------- Common attributes
# The default file extension to attach to each saved file.
Expand Down Expand Up @@ -56,12 +53,10 @@ def set_pwd(path)
@default_path = path
end


# ---------------------------------------------------- ActiveRecord finders

# Find by :id, which in this case is the file's basename
def find(id)

# Discard any input with weird characters
if (id =~ /\A[\x00\/\\:\*\?\"<>\|]\z/)
raise Exception.new('Not found!')
Expand All @@ -87,10 +82,8 @@ def all()
self.from_file(file)
end.sort
end

end # /ClassMethods


# --------------------------------------------------------- ActiveModel::Lint

# ActiveModel expects you to define an id() method to uniquely identify each
Expand All @@ -99,15 +92,14 @@ def id() persisted? ? self.filename : nil end

def new_record?()
# return true unless self.filename
return !File.exists?(full_path)
return !File.exist?(full_path)
end

# def destroyed?() true end
def persisted?()
@persisted ||= File.exists?(full_path)
@persisted ||= File.exist?(full_path)
end


# ---------------------------------------------------------------- Enumerable

# When comparing two NoteTemplate instances, sort them alphabetically on their
Expand All @@ -119,22 +111,22 @@ def <=>(other)
# -------------------------------------------------- Constructors & Lifecycle

# Constructor a la ActiveRecord. Attributes: :name, :file
def initialize(attributes={})
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end

def destroy
return true unless filename && File.exists?(full_path)
return true unless filename && File.exist?(full_path)
File.delete(full_path)
self
end
alias :delete :destroy

def save
return false if !valid?
FileUtils.mkdir_p(self.class.pwd) unless File.exists?(self.class.pwd)
FileUtils.mkdir_p(self.class.pwd) unless File.exist?(self.class.pwd)
File.open(full_path, 'w') do |f|
f << self.content
end
Expand All @@ -158,6 +150,6 @@ def name
end

def name=(new_name)
self.filename= new_name.gsub(/ /,'_').underscore
self.filename = new_name.gsub(/ /, '_').underscore
end
end
6 changes: 3 additions & 3 deletions app/models/methodology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def to_param() self.filename end

def new_record?()
# return true unless self.filename
return !File.exists?(full_path)
return !File.exist?(full_path)
end

# def destroyed?() true end
Expand Down Expand Up @@ -120,15 +120,15 @@ def initialize(attributes = {})

def save
return false if !valid?
FileUtils.mkdir_p(Methodology.pwd) unless File.exists?(Methodology.pwd)
FileUtils.mkdir_p(Methodology.pwd) unless File.exist?(Methodology.pwd)
File.open(full_path, 'w') do |f|
f << @content
end
return true
end

def destroy
return true unless filename && File.exists?(full_path)
return true unless filename && File.exist?(full_path)
File.delete(full_path)
self
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def nested_activities
}

scope :user_nodes, -> {
where("type_id IN (?)", Types::USER_TYPES)
where('type_id IN (?)', Types::USER_TYPES)
}

# -- Class Methods --------------------------------------------------------
Expand All @@ -84,7 +84,7 @@ def ancestor_of?(node)

# Return all the Attachment objects associated with this Node.
def attachments
Attachment.find(:all, :conditions => {:node_id => self.id})
Attachment.find(:all, conditions: { node_id: self.id })
end

def user_node?
Expand All @@ -102,7 +102,7 @@ def update_parents_counter_cache; end
# deleted too
def destroy_attachments
attachments_dir = Attachment.pwd.join(self.id.to_s)
FileUtils.rm_rf attachments_dir if File.exists?(attachments_dir)
FileUtils.rm_rf attachments_dir if File.exist?(attachments_dir)
end

def parent_node
Expand Down
6 changes: 3 additions & 3 deletions app/services/naming_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.name_file(original_filename:, pathname:)
# Remove newlines and duplicate spaces
original_filename = original_filename.squish

return original_filename unless File.exists?(pathname.join(original_filename))
return original_filename unless File.exist?(pathname.join(original_filename))

extension = File.extname(original_filename)
basename = File.basename(original_filename, extension)
Expand All @@ -28,7 +28,7 @@ def self.name_file(original_filename:, pathname:)
def self.name_project(name)
return name unless Project.exists?(name: name)

projects = Project.where("name LIKE ?", "#{name}_copy-%")
projects = Project.where('name LIKE ?', "#{name}_copy-%")
project_names = projects.map(&:name)

new_name(
Expand All @@ -40,7 +40,7 @@ def self.name_project(name)
private

def self.new_name(name:, sequence:, suffix: nil)
"%s_copy-%02i%s" % [name, sequence, suffix]
'%s_copy-%02i%s' % [name, sequence, suffix]
end

def self.next_sequence(matching_names: [], suffix: nil)
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/thor/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def configure
init_all = false
Dir['config/*.template'].each do |template|
config = File.join('config', File.basename(template, '.template'))
if !(File.exists?(config))
if !(File.exist?(config))
if (init_all)
puts "Initilizing #{config}..."
FileUtils.cp(template, config)
Expand All @@ -45,9 +45,9 @@ def configure
desc 'kit', 'Import files and projects from a specified Kit configuration file'
method_option :file, required: true, type: :string, desc: 'full path to the Kit file to use.'
def kit
puts "** Importing kit..."
puts '** Importing kit...'
KitImportJob.perform_now(options[:file], logger: default_logger)
puts "[ DONE ]"
puts '[ DONE ]'
end

desc 'welcome', 'adds initial content to the repo for demonstration purposes'
Expand Down
8 changes: 4 additions & 4 deletions spec/jobs/kit_import_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
expect(ProjectTemplate.find_template('dradis-template-welcome')).to_not be_nil

# report template files
expect(File.exists?(Rails.root.join('tmp', 'rspec', 'reports', 'word', 'dradis_welcome_template.v0.5.docm'))).to eq true
expect(File.exists?(Rails.root.join('tmp', 'rspec', 'reports', 'excel', 'dradis_template-excel-simple.v1.3.xlsx'))).to eq true
expect(File.exists?(Rails.root.join('tmp', 'rspec', 'reports', 'html_export', 'html_welcome_report.html.erb'))).to eq true
expect(File.exist?(Rails.root.join('tmp', 'rspec', 'reports', 'word', 'dradis_welcome_template.v0.5.docm'))).to eq true
expect(File.exist?(Rails.root.join('tmp', 'rspec', 'reports', 'excel', 'dradis_template-excel-simple.v1.3.xlsx'))).to eq true
expect(File.exist?(Rails.root.join('tmp', 'rspec', 'reports', 'html_export', 'html_welcome_report.html.erb'))).to eq true

# Check that no ruby file was copied
expect(File.exists?(Rails.root.join('tmp', 'rspec', 'reports', 'word', 'dradis_welcome_template.v0.5.rb'))).to eq false
expect(File.exist?(Rails.root.join('tmp', 'rspec', 'reports', 'word', 'dradis_welcome_template.v0.5.rb'))).to eq false
end

it 'can import kit without methodologies folder' do
Expand Down
Loading
Loading