diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14d8c3daa..953cc7013 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,29 +14,22 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7.4'] + ruby: ['2.4', '2.5', '2.6'] steps: - name: Checkout uses: actions/checkout@v1 - name: Setup Ruby - uses: ruby/setup-ruby@v1.79.0 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Install sqlite run: | sudo apt-get install libsqlite3-dev - - name: Update System - run: | - gem update --system --no-document - - - name: Bundle install for Annotate models - run: | - bundle install --jobs=4 --retry=3 - - name: Run Tests run: INTEGRATION_TESTS=1 bundle exec rspec diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 12de50ca4..5ce6ec569 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,9 +2,12 @@ name: "Code scanning - action" on: push: + branches-ignore: + - pr/* + - scratch/* pull_request: schedule: - - cron: '0 6 * * 4' + - cron: '0 20 * * 7' jobs: CodeQL-Build: diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 000000000..72a6bb16b --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,17 @@ +name: Release Drafter + +on: + push: + branches: + - develop + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "develop" + - uses: release-drafter/release-drafter@v5 + with: + config-name: release-drafter.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..9b6768d19 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.6.7 diff --git a/.travis.yml b/.travis.yml index 554f29dbc..05d05d26d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ rvm: env: - RAILS_ENV=development RACK_ENV=development INTEGRATION_TESTS=1 +cache: bundler + addons: apt_packages: - libsqlite3-dev diff --git a/Guardfile b/Guardfile index 602c7b57c..f93bc135e 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -# Note: The cmd option is now required due to the increasing number of ways +# NOTE: The cmd option is now required due to the increasing number of ways # rspec may be run, below are examples of the most common uses. # * bundler: 'bundle exec rspec' # * bundler binstubs: 'bin/rspec' diff --git a/Rakefile b/Rakefile index bfbd51b7d..43944f2dc 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ def exit_exception(e) exit e.status_code end -# Note : this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3 +# NOTE: this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3 begin require 'bundler' Bundler.setup(:default, :development) @@ -162,7 +162,7 @@ namespace :integration do fixtures[Digest::MD5.hexdigest(File.read(fname))] = File.expand_path(fname) end - candidates.keys.each do |digest| + candidates.each_key do |digest| next unless fixtures.key?(digest) candidates[digest].each do |fname| # Double-check contents in case of hash collision... diff --git a/annotate.gemspec b/annotate.gemspec index c5aa39a79..2a2d9bd12 100644 --- a/annotate.gemspec +++ b/annotate.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.specification_version = 4 if s.respond_to? :specification_version s.add_runtime_dependency(%q, '>= 10.4', '< 14.0') - s.add_runtime_dependency(%q, ['>= 6.1', '< 7.1']) + s.add_runtime_dependency(%q, ['>= 3.2', '< 8.0']) s.metadata = { "bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/", diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index a14a90c53..23af4d540 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -651,7 +651,8 @@ def get_loaded_model(model_path, file) # auto_load/eager_load paths. Try all possible model paths one by one. absolute_file = File.expand_path(file) model_paths = - $LOAD_PATH.select { |path| absolute_file.include?(path) } + $LOAD_PATH.map(&:to_s) + .select { |path| absolute_file.include?(path) } .map { |path| absolute_file.sub(path, '').sub(/\.rb$/, '').sub(/^\//, '') } model_paths .map { |path| get_loaded_model_by_path(path) } @@ -660,9 +661,7 @@ def get_loaded_model(model_path, file) # Retrieve loaded model class by path to the file where it's supposed to be defined. def get_loaded_model_by_path(model_path) - klass = ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(model_path)) - - klass if klass.is_a?(Class) && klass < ActiveRecord::Base + ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(model_path)) rescue StandardError, LoadError # Revert to the old way but it is not really robust ObjectSpace.each_object(::Class) @@ -905,9 +904,7 @@ def ignored_translation_table_colums(klass) # Construct the foreign column name in the translations table # eg. Model: Car, foreign column name: car_id foreign_column_name = [ - klass.translation_class.to_s - .gsub('::Translation', '').gsub('::', '_') - .downcase, + klass.table_name.to_s.singularize, '_id' ].join.to_sym @@ -948,9 +945,9 @@ def get_attributes(column, column_type, klass, options) # Check out if we got a geometric column # and print the type and SRID if column.respond_to?(:geometry_type) - attrs << "#{column.geometry_type}, #{column.srid}" + attrs << [column.geometry_type, column.try(:srid)].compact.join(', ') elsif column.respond_to?(:geometric_type) && column.geometric_type.present? - attrs << "#{column.geometric_type.to_s.downcase}, #{column.srid}" + attrs << [column.geometric_type.to_s.downcase, column.try(:srid)].compact.join(', ') end # Check if the column has indices and print "indexed" if true diff --git a/lib/annotate/version.rb b/lib/annotate/version.rb index d08e5a822..e103c6b87 100644 --- a/lib/annotate/version.rb +++ b/lib/annotate/version.rb @@ -1,5 +1,5 @@ module Annotate def self.version - '3.1.1' + '3.2.0' end end diff --git a/lib/tasks/annotate_models_migrate.rake b/lib/tasks/annotate_models_migrate.rake index 8e39868b1..58c07a5a9 100644 --- a/lib/tasks/annotate_models_migrate.rake +++ b/lib/tasks/annotate_models_migrate.rake @@ -16,6 +16,8 @@ if defined?(Rails::Application) && Rails.version.split('.').first.to_i >= 6 end migration_tasks.each do |task| + next unless Rake::Task.task_defined?(task) + Rake::Task[task].enhance do Rake::Task[Rake.application.top_level_tasks.last].enhance do annotation_options_task = if Rake::Task.task_defined?('app:set_annotation_options') diff --git a/spec/integration/rails_6.1.7/Gemfile b/spec/integration/rails_6.1.7/Gemfile index 7ff37895a..4271cddee 100644 --- a/spec/integration/rails_6.1.7/Gemfile +++ b/spec/integration/rails_6.1.7/Gemfile @@ -6,7 +6,18 @@ gem 'rails', '6.1.7' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server -gem 'puma', '~> 4.3.8' +gem 'puma', '~> 5.6' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production diff --git a/spec/integration/rails_7.0.4/Gemfile b/spec/integration/rails_7.0.4/Gemfile index c572fa4d5..6bdd0f6cc 100644 --- a/spec/integration/rails_7.0.4/Gemfile +++ b/spec/integration/rails_7.0.4/Gemfile @@ -6,7 +6,7 @@ gem 'rails', '7.0.4' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server -gem 'puma', '~> 4.3.8' +gem 'puma', '~> 5.6.1' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index bbc853487..e45b99fd8 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -389,8 +389,8 @@ def mock_column(name, type, options = {}) context 'with Globalize gem' do let :translation_klass do - double('Post::Translation', - to_s: 'Post::Translation', + double('Folder::Post::Translation', + to_s: 'Folder::Post::Translation', columns: [ mock_column(:id, :integer, limit: 8), mock_column(:post_id, :integer, limit: 8), @@ -1181,7 +1181,10 @@ def mock_column(name, type, options = {}) limit: { srid: 4326, type: 'geometry' }), mock_column(:location, :geography, geometric_type: 'Point', srid: 0, - limit: { srid: 0, type: 'geometry' }) + limit: { srid: 0, type: 'geometry' }), + mock_column(:non_srid, :geography, + geometric_type: 'Point', + limit: { type: 'geometry' }) ] end @@ -1195,6 +1198,7 @@ def mock_column(name, type, options = {}) # active :boolean default(FALSE), not null # geometry :geometry not null, geometry, 4326 # location :geography not null, point, 0 + # non_srid :geography not null, point # EOS end @@ -1984,7 +1988,7 @@ class FooWithKnownMacro < ActiveRecord::Base end end - context 'when the file includes invlaid multibyte chars (USASCII)' do + context 'when the file includes invalid multibyte chars (USASCII)' do context 'when class FooWithUtf8 is defined in "foo_with_utf8.rb"' do let :filename do 'foo_with_utf8.rb'