From 0d7d667c3532fac21dc37b05f7653d8e88041657 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 1 Nov 2024 09:37:25 -0400 Subject: [PATCH 1/5] bump ruby to 3.2.0 --- .ruby-version | 2 +- CHANGELOG | 3 +-- Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.ruby-version b/.ruby-version index ef538c281..944880fa1 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.2 +3.2.0 diff --git a/CHANGELOG b/CHANGELOG index 6892d7b40..8d1767dfe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,5 @@ [v#.#.#] ([month] [YYYY]) - - [entity]: - - [future tense verb] [feature] + - Ruby: Upgrade ruby version to 3.2.0 - Upgraded gems: - [gem] - Bugs fixes: diff --git a/Gemfile b/Gemfile index 73b616a68..ad3a18a54 100644 --- a/Gemfile +++ b/Gemfile @@ -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' @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index d3aabc909..ccdc8371c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -464,7 +464,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) @@ -649,7 +649,7 @@ DEPENDENCIES whenever RUBY VERSION - ruby 3.1.2p20 + ruby 3.2.0p0 BUNDLED WITH 2.3.16 From 93a20323650137aeec51679ede826c87a120d13c Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 1 Nov 2024 09:43:09 -0400 Subject: [PATCH 2/5] update File.exists? (deprecated in Ruby 3.2.0) to File.exist? --- app/models/attachment.rb | 10 +++++----- app/models/concerns/file_backed_model.rb | 8 ++++---- app/models/methodology.rb | 6 +++--- app/models/node.rb | 2 +- app/services/naming_service.rb | 4 ++-- lib/tasks/thor/setup.rb | 2 +- spec/jobs/kit_import_job_spec.rb | 8 ++++---- spec/lib/file_backed_model_spec.rb | 10 +++++----- spec/models/attachment_spec.rb | 2 +- spec/models/methodology_spec.rb | 12 ++++++------ spec/models/node_spec.rb | 4 ++-- spec/models/note_template_spec.rb | 16 ++++++++-------- 12 files changed, 42 insertions(+), 42 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 455afe832..89fcb3825 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -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 @@ -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) != '' @@ -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) @@ -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 diff --git a/app/models/concerns/file_backed_model.rb b/app/models/concerns/file_backed_model.rb index d7aa19cd3..7b546b5d2 100644 --- a/app/models/concerns/file_backed_model.rb +++ b/app/models/concerns/file_backed_model.rb @@ -99,12 +99,12 @@ 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 @@ -126,7 +126,7 @@ def initialize(attributes={}) 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 @@ -134,7 +134,7 @@ def 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 diff --git a/app/models/methodology.rb b/app/models/methodology.rb index b67559c30..2e05841c3 100644 --- a/app/models/methodology.rb +++ b/app/models/methodology.rb @@ -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 @@ -120,7 +120,7 @@ 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 @@ -128,7 +128,7 @@ def save 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 diff --git a/app/models/node.rb b/app/models/node.rb index d0dea2923..336d3ae97 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -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 diff --git a/app/services/naming_service.rb b/app/services/naming_service.rb index 58f43ae8a..0ef47a7b7 100644 --- a/app/services/naming_service.rb +++ b/app/services/naming_service.rb @@ -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) @@ -26,7 +26,7 @@ def self.name_file(original_filename:, pathname:) # If not, return the name with a count based alternative. # name: the project name def self.name_project(name) - return name unless Project.exists?(name: name) + return name unless Project.exist?(name: name) projects = Project.where("name LIKE ?", "#{name}_copy-%") project_names = projects.map(&:name) diff --git a/lib/tasks/thor/setup.rb b/lib/tasks/thor/setup.rb index b5ba1819c..e45767585 100644 --- a/lib/tasks/thor/setup.rb +++ b/lib/tasks/thor/setup.rb @@ -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) diff --git a/spec/jobs/kit_import_job_spec.rb b/spec/jobs/kit_import_job_spec.rb index 46fb9a1d6..c402334eb 100644 --- a/spec/jobs/kit_import_job_spec.rb +++ b/spec/jobs/kit_import_job_spec.rb @@ -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 diff --git a/spec/lib/file_backed_model_spec.rb b/spec/lib/file_backed_model_spec.rb index b6138c0ff..b962d16d6 100644 --- a/spec/lib/file_backed_model_spec.rb +++ b/spec/lib/file_backed_model_spec.rb @@ -40,7 +40,7 @@ class ExtensionFBM # ----------------------------------------------------------- File operations describe '.from_file' do it "loads an instance based on the file on disk" do - FileUtils.mkdir_p(pwd) unless File.exists?(pwd) + FileUtils.mkdir_p(pwd) unless File.exist?(pwd) File.open(rspec_file, 'w'){|f| f << 'bar'} expect(subject.class).to respond_to(:from_file) @@ -62,7 +62,7 @@ class ExtensionFBM end it "deletes the file from disk if this is a file-backed model" do - FileUtils.mkdir_p(pwd) unless File.exists?(pwd) + FileUtils.mkdir_p(pwd) unless File.exist?(pwd) File.open(rspec_file, 'w'){|f| f << 'foobar' } expect(File.exist?(rspec_file)).to be true @@ -104,7 +104,7 @@ class ExtensionFBM # ------------------------------------------------------------------- Finders describe '.all' do it "returns a new instance for each file in the .pwd" do - FileUtils.mkdir_p(pwd) unless File.exists?(pwd) + FileUtils.mkdir_p(pwd) unless File.exist?(pwd) (1..3).each do |i| File.open(pwd.join("#{i}.txt"), 'w'){|f| f << 'foo' } @@ -123,7 +123,7 @@ class ExtensionFBM end it "loads an instance based on the file name" do - FileUtils.mkdir_p(pwd) unless File.exists?(pwd) + FileUtils.mkdir_p(pwd) unless File.exist?(pwd) File.open(rspec_file, 'w'){|f| f << 'bar'} expect(subject.class).to respond_to(:find) @@ -142,7 +142,7 @@ class ExtensionFBM # ---------------------------------------------------------- Instance methods describe '#name' do it "responds to #name based on the filename" do - FileUtils.mkdir_p(pwd) unless File.exists?(pwd) + FileUtils.mkdir_p(pwd) unless File.exist?(pwd) File.open(rspec_file, 'w'){|f| f << 'bar' } bfbm = BasicFileBackedModel.from_file(rspec_file) diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index 4c609db48..98d3a66f9 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -18,7 +18,7 @@ end it 'should copy the source file into the attachments folder' do - expect(File.exists?(Attachment.pwd + "#{node.id}/#{attachment.filename}")).to be true + expect(File.exist?(Attachment.pwd + "#{node.id}/#{attachment.filename}")).to be true end it 'should be able to find attachments by filename' diff --git a/spec/models/methodology_spec.rb b/spec/models/methodology_spec.rb index 35fe54362..d8890c66c 100644 --- a/spec/models/methodology_spec.rb +++ b/spec/models/methodology_spec.rb @@ -35,11 +35,11 @@ mt.save filename = Methodology.pwd.join('mt_test.xml') - expect(File.exists?(filename)).to be true + expect(File.exist?(filename)).to be true expect(mt).to respond_to('destroy') expect(mt).to respond_to('delete') mt.destroy - expect(File.exists?(filename)).to be false + expect(File.exist?(filename)).to be false end it "destroy() works even if the file doesn't exist any more or never existed" do @@ -69,7 +69,7 @@ describe '#save' do it "creates the base dir if it doesn't exist when saving" do - FileUtils.rm_rf(Methodology.pwd) if File.exists?(Methodology.pwd) + FileUtils.rm_rf(Methodology.pwd) if File.exist?(Methodology.pwd) Timecop.freeze(Time.now) @@ -78,8 +78,8 @@ expect(mt.save).to be true new_methodology = Methodology.pwd.join("auto_#{Time.now.to_i}.xml") - expect(File.exists?(Methodology.pwd)).to be true - expect(File.exists?(new_methodology)).to be true + expect(File.exist?(Methodology.pwd)).to be true + expect(File.exist?(new_methodology)).to be true expect(File.read(new_methodology)).to eq(content) File.delete(new_methodology) @@ -93,7 +93,7 @@ ) expect(mt.save).to be true filename = Methodology.pwd.join('mt_test.xml') - expect(File.exists?(filename)).to be true + expect(File.exist?(filename)).to be true expect(File.read(filename)).to eq('bar') File.delete(filename) end diff --git a/spec/models/node_spec.rb b/spec/models/node_spec.rb index 3610e3a91..14692eded 100644 --- a/spec/models/node_spec.rb +++ b/spec/models/node_spec.rb @@ -27,11 +27,11 @@ end it 'deletes all associated attachments' do - expect(File.exists?(@attachment.fullpath)).to be false + expect(File.exist?(@attachment.fullpath)).to be false end it 'deletes its corresponding attachment subfolder' do - expect(File.exists?(Attachment.pwd.join(node.id.to_s))).to be false + expect(File.exist?(Attachment.pwd.join(node.id.to_s))).to be false end it "doesn't delete or nullify any associated Activities" do diff --git a/spec/models/note_template_spec.rb b/spec/models/note_template_spec.rb index 8d51a265b..d327d621c 100644 --- a/spec/models/note_template_spec.rb +++ b/spec/models/note_template_spec.rb @@ -25,7 +25,7 @@ expect { NoteTemplate.find('none_existent') }.to raise_error(FileBackedModel::FileNotFoundException) # Handle existing templates - FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exists?(NoteTemplate.pwd) + FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exist?(NoteTemplate.pwd) test_file = NoteTemplate.pwd.join('foo.txt') File.open( test_file, 'w' ){ |f| f << 'bar' } expect { NoteTemplate.find('foo') }.to_not raise_error() @@ -68,14 +68,14 @@ pending "prevents a template from being overwritten" it "creates the templates dir if it doesn't exist when saving" do - FileUtils.rm_rf(NoteTemplate.pwd) if File.exists?(NoteTemplate.pwd) + FileUtils.rm_rf(NoteTemplate.pwd) if File.exist?(NoteTemplate.pwd) nt = NoteTemplate.new(name: 'New Spec Template', content: 'Simple note content: *kapow*!') expect(nt.save).to be true new_note_template = NoteTemplate.pwd.join('new_spec_template.txt') - expect(File.exists?(NoteTemplate.pwd)).to be true - expect(File.exists?(new_note_template)).to be true + expect(File.exist?(NoteTemplate.pwd)).to be true + expect(File.exist?(new_note_template)).to be true expect(File.read(new_note_template)).to eq('Simple note content: *kapow*!') File.delete(new_note_template) end @@ -86,7 +86,7 @@ expect(nt.save).to be true filename = NoteTemplate.pwd.join('tpl_test.txt') - expect(File.exists?(filename)).to be true + expect(File.exist?(filename)).to be true expect(File.read(filename)).to eq('FooBar') File.delete(filename) end @@ -96,18 +96,18 @@ nt.save filename = NoteTemplate.pwd.join('tpl_test.txt') - expect(File.exists?(filename)).to be true + expect(File.exist?(filename)).to be true expect(nt).to respond_to('destroy') expect(nt).to respond_to('delete') nt.destroy - expect(File.exists?(filename)).to be false + expect(File.exist?(filename)).to be false end it "destroy() works even if the file doesn't exist any more or never existed" do nt = NoteTemplate.new(filename: 'foobar') expect { nt.destroy }.not_to raise_error - FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exists?(NoteTemplate.pwd) + FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exist?(NoteTemplate.pwd) filename = NoteTemplate.pwd.join('foobar.txt') File.open(filename,'w'){ |f| f<<'barfoo' } From 3c364c482b2b6dbed116ea64d9e1a298b25dd309 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 1 Nov 2024 10:15:44 -0400 Subject: [PATCH 3/5] lint --- app/models/concerns/file_backed_model.rb | 12 ++------ app/models/node.rb | 4 +-- app/services/naming_service.rb | 4 +-- lib/tasks/thor/setup.rb | 4 +-- spec/lib/file_backed_model_spec.rb | 38 +++++++++++------------- spec/models/node_spec.rb | 10 +++---- spec/models/note_template_spec.rb | 23 +++++++------- 7 files changed, 41 insertions(+), 54 deletions(-) diff --git a/app/models/concerns/file_backed_model.rb b/app/models/concerns/file_backed_model.rb index 7b546b5d2..d31b57e22 100644 --- a/app/models/concerns/file_backed_model.rb +++ b/app/models/concerns/file_backed_model.rb @@ -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) @@ -25,8 +24,6 @@ def self.included(base) end end - - module ClassMethods # ------------------------------------------------------- Common attributes # The default file extension to attach to each saved file. @@ -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!') @@ -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 @@ -107,7 +100,6 @@ def persisted?() @persisted ||= File.exist?(full_path) end - # ---------------------------------------------------------------- Enumerable # When comparing two NoteTemplate instances, sort them alphabetically on their @@ -119,7 +111,7 @@ 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 @@ -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 diff --git a/app/models/node.rb b/app/models/node.rb index 336d3ae97..9366ed97b 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -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 -------------------------------------------------------- @@ -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? diff --git a/app/services/naming_service.rb b/app/services/naming_service.rb index 0ef47a7b7..777d86725 100644 --- a/app/services/naming_service.rb +++ b/app/services/naming_service.rb @@ -28,7 +28,7 @@ def self.name_file(original_filename:, pathname:) def self.name_project(name) return name unless Project.exist?(name: name) - projects = Project.where("name LIKE ?", "#{name}_copy-%") + projects = Project.where('name LIKE ?', "#{name}_copy-%") project_names = projects.map(&:name) new_name( @@ -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) diff --git a/lib/tasks/thor/setup.rb b/lib/tasks/thor/setup.rb index e45767585..cd5b2f351 100644 --- a/lib/tasks/thor/setup.rb +++ b/lib/tasks/thor/setup.rb @@ -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' diff --git a/spec/lib/file_backed_model_spec.rb b/spec/lib/file_backed_model_spec.rb index b962d16d6..ad13450e9 100644 --- a/spec/lib/file_backed_model_spec.rb +++ b/spec/lib/file_backed_model_spec.rb @@ -11,22 +11,21 @@ class BasicFileBackedModel end subject { ::BasicFileBackedModel.new } - let(:pwd){ BasicFileBackedModel.pwd } - let(:rspec_file){ pwd.join('rspec.txt')} - it_behaves_like "ActiveModel" + let(:pwd) { BasicFileBackedModel.pwd } + let(:rspec_file) { pwd.join('rspec.txt') } + it_behaves_like 'ActiveModel' after(:all) do FileUtils.rm_rf('tmp/templates/') ::Configuration::where(name: 'admin:paths:rspec').limit(1).destroy_all end - # ------------------------------------------------------- Class configuration describe '.extension' do - it "defaults to a .txt extension" do + it 'defaults to a .txt extension' do expect(BasicFileBackedModel.extension).to eq('.txt') end - it "allows including classes to define their own" do + it 'allows including classes to define their own' do class ExtensionFBM include FileBackedModel set_extension :xml @@ -36,12 +35,11 @@ class ExtensionFBM end end - # ----------------------------------------------------------- File operations describe '.from_file' do - it "loads an instance based on the file on disk" do + it 'loads an instance based on the file on disk' do FileUtils.mkdir_p(pwd) unless File.exist?(pwd) - File.open(rspec_file, 'w'){|f| f << 'bar'} + File.open(rspec_file, 'w') { |f| f << 'bar' } expect(subject.class).to respond_to(:from_file) # expect(subject.class.from_file).to raise_error @@ -61,9 +59,9 @@ class ExtensionFBM expect(instance.destroy).to be true end - it "deletes the file from disk if this is a file-backed model" do + it 'deletes the file from disk if this is a file-backed model' do FileUtils.mkdir_p(pwd) unless File.exist?(pwd) - File.open(rspec_file, 'w'){|f| f << 'foobar' } + File.open(rspec_file, 'w') { |f| f << 'foobar' } expect(File.exist?(rspec_file)).to be true instance = subject.class.from_file(rspec_file) @@ -73,7 +71,7 @@ class ExtensionFBM end describe '#save' do - pending "generates a filename using the #name if provided" do + pending 'generates a filename using the #name if provided' do subject.name = 'Singing in the rain' should be true @@ -89,7 +87,7 @@ class ExtensionFBM # it "auto-generates a filename if no #name was provided" do # end - it "overwrites the contents of the file on disk" do + it 'overwrites the contents of the file on disk' do subject.name = 'rspec name' subject.content = 'barfoo' expect(subject.save).to be true @@ -100,14 +98,13 @@ class ExtensionFBM end end - # ------------------------------------------------------------------- Finders describe '.all' do - it "returns a new instance for each file in the .pwd" do + it 'returns a new instance for each file in the .pwd' do FileUtils.mkdir_p(pwd) unless File.exist?(pwd) (1..3).each do |i| - File.open(pwd.join("#{i}.txt"), 'w'){|f| f << 'foo' } + File.open(pwd.join("#{i}.txt"), 'w') { |f| f << 'foo' } end expect(BasicFileBackedModel.all.count).to eq(3) @@ -122,9 +119,9 @@ class ExtensionFBM end.to raise_exception(FileBackedModel::FileNotFoundException) end - it "loads an instance based on the file name" do + it 'loads an instance based on the file name' do FileUtils.mkdir_p(pwd) unless File.exist?(pwd) - File.open(rspec_file, 'w'){|f| f << 'bar'} + File.open(rspec_file, 'w') { |f| f << 'bar' } expect(subject.class).to respond_to(:find) @@ -138,12 +135,11 @@ class ExtensionFBM end end - # ---------------------------------------------------------- Instance methods describe '#name' do - it "responds to #name based on the filename" do + it 'responds to #name based on the filename' do FileUtils.mkdir_p(pwd) unless File.exist?(pwd) - File.open(rspec_file, 'w'){|f| f << 'bar' } + File.open(rspec_file, 'w') { |f| f << 'bar' } bfbm = BasicFileBackedModel.from_file(rspec_file) expect(bfbm).to respond_to(:name) diff --git a/spec/models/node_spec.rb b/spec/models/node_spec.rb index 14692eded..735bded26 100644 --- a/spec/models/node_spec.rb +++ b/spec/models/node_spec.rb @@ -148,8 +148,8 @@ end it 'ignores same value for hash properties (same key type)' do - node.set_property(:test_property, {port: 80, protocol: 'tcp'}) - node.set_property(:test_property, {port: 80, protocol: 'tcp'}) + node.set_property(:test_property, { port: 80, protocol: 'tcp' }) + node.set_property(:test_property, { port: 80, protocol: 'tcp' }) # Because we're getting a WithIndifferentAccess hash, can't compare # directly. @@ -163,8 +163,8 @@ # strings for DB serialisation. If we start sending Symbols, they # become Strings and by the time we're setting the second property # we'd be comparing strings with strings. - node.set_property(:test_property, {'port' => 80, 'protocol' => 'tcp'}) - node.set_property(:test_property, {port: 80, protocol: 'tcp'}) + node.set_property(:test_property, { 'port' => 80, 'protocol' => 'tcp' }) + node.set_property(:test_property, { port: 80, protocol: 'tcp' }) # Because we're getting a WithIndifferentAccess hash, can't compare # directly. @@ -198,7 +198,7 @@ it 'raises if you try to set :services or services_extras' do expect do - node.set_property(:services, [{port: '22', protocol: 'tcp'}]) + node.set_property(:services, [{ port: '22', protocol: 'tcp' }]) end.to raise_error(ArgumentError, /set_service/) expect do diff --git a/spec/models/note_template_spec.rb b/spec/models/note_template_spec.rb index d327d621c..acab6aee8 100644 --- a/spec/models/note_template_spec.rb +++ b/spec/models/note_template_spec.rb @@ -13,12 +13,12 @@ FileUtils.rm_rf('tmp/templates/') end - it "defines a class .pwd() method" do + it 'defines a class .pwd() method' do expect(NoteTemplate::methods).to include(:pwd) expect(NoteTemplate.pwd).to respond_to('join') end - it "provides a find(id) method" do + it 'provides a find(id) method' do expect(NoteTemplate::methods).to include(:find) # Handle non-existing @@ -27,14 +27,14 @@ # Handle existing templates FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exist?(NoteTemplate.pwd) test_file = NoteTemplate.pwd.join('foo.txt') - File.open( test_file, 'w' ){ |f| f << 'bar' } + File.open(test_file, 'w') { |f| f << 'bar' } expect { NoteTemplate.find('foo') }.to_not raise_error() nt = NoteTemplate.find('foo') expect(nt.content).to eq('bar') File.delete(test_file) end - it "validates presence of filename" do + it 'validates presence of filename' do nt = NoteTemplate.new(content: 'foobar') expect(nt).not_to be_valid() @@ -49,23 +49,23 @@ end it "doesn't accept bad characters in the name" do - nt = NoteTemplate.new(name: '../../../../../etc' ) + nt = NoteTemplate.new(name: '../../../../../etc') expect(nt).to_not be_valid() - nt.name = "foo" + nt.name = 'foo' expect(nt).to be_valid() nt.name = 'bar.txt' expect(nt).to_not be_valid() end - it "needs to be valid before it is saved on disk" do + it 'needs to be valid before it is saved on disk' do nt = NoteTemplate.new expect(nt).to_not be_valid() expect(nt.save).to be false end - pending "prevents a template from being overwritten" + pending 'prevents a template from being overwritten' it "creates the templates dir if it doesn't exist when saving" do FileUtils.rm_rf(NoteTemplate.pwd) if File.exist?(NoteTemplate.pwd) @@ -80,8 +80,7 @@ File.delete(new_note_template) end - - it "saves the template contents when saving the instance" do + it 'saves the template contents when saving the instance' do nt = NoteTemplate.new(content: 'FooBar', filename: 'tpl_test') expect(nt.save).to be true filename = NoteTemplate.pwd.join('tpl_test.txt') @@ -91,7 +90,7 @@ File.delete(filename) end - it "deletes file from disk on destroy" do + it 'deletes file from disk on destroy' do nt = NoteTemplate.new(content: 'FooBar', filename: 'tpl_test') nt.save @@ -109,7 +108,7 @@ FileUtils.mkdir_p(NoteTemplate.pwd) unless File.exist?(NoteTemplate.pwd) filename = NoteTemplate.pwd.join('foobar.txt') - File.open(filename,'w'){ |f| f<<'barfoo' } + File.open(filename, 'w') { |f| f << 'barfoo' } nt = NoteTemplate.from_file(filename) expect(nt.content).to eq('barfoo') From 4031708a1b90055393647e1452121fb26b0d513d Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 1 Nov 2024 12:12:32 -0400 Subject: [PATCH 4/5] update shoulda-matchers to version that doesn't use deprecated `Fixnum` class --- Gemfile | 2 +- Gemfile.lock | 8 +++----- app/services/naming_service.rb | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index ad3a18a54..81edd4093 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 5535145d5..c7689f702 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/app/services/naming_service.rb b/app/services/naming_service.rb index 777d86725..0151ac28a 100644 --- a/app/services/naming_service.rb +++ b/app/services/naming_service.rb @@ -26,7 +26,7 @@ def self.name_file(original_filename:, pathname:) # If not, return the name with a count based alternative. # name: the project name def self.name_project(name) - return name unless Project.exist?(name: name) + return name unless Project.exists?(name: name) projects = Project.where('name LIKE ?', "#{name}_copy-%") project_names = projects.map(&:name) From e34baa6312399259168234367f6db977e9dd8113 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Thu, 16 Jan 2025 17:47:35 -0500 Subject: [PATCH 5/5] fix ci by installing sqlite dependencies --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34613588b..4db6ef8d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + - name: Install sqlite3 dependencies + run: sudo apt-get install libsqlite3-dev - name: Install Ruby and gems uses: ruby/setup-ruby@v1 with: