diff --git a/.travis.yml b/.travis.yml index 1e319c35..c2b66fc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ gemfile: - gemfiles/Gemfile-rails.5.1.x - gemfiles/Gemfile-rails.5.2.x - gemfiles/Gemfile-rails.6.0.x + - gemfiles/Gemfile-rails.6.1.x - gemfiles/Gemfile-rails.edge before_install: - gem install bundler -v '< 2' @@ -26,14 +27,20 @@ matrix: exclude: - rvm: 2.2 gemfile: gemfiles/Gemfile-rails.6.0.x + - rvm: 2.2 + gemfile: gemfiles/Gemfile-rails.6.1.x - rvm: 2.2 gemfile: gemfiles/Gemfile-rails.edge - rvm: 2.3 gemfile: gemfiles/Gemfile-rails.6.0.x + - rvm: 2.3 + gemfile: gemfiles/Gemfile-rails.6.1.x - rvm: 2.3 gemfile: gemfiles/Gemfile-rails.edge - rvm: 2.4 gemfile: gemfiles/Gemfile-rails.6.0.x + - rvm: 2.4 + gemfile: gemfiles/Gemfile-rails.6.1.x - rvm: 2.4 gemfile: gemfiles/Gemfile-rails.edge cache: bundler diff --git a/Gemfile b/Gemfile index 4d0f5549..8bedd344 100644 --- a/Gemfile +++ b/Gemfile @@ -6,19 +6,20 @@ if ENV["edge"] gem "activerecord", :github => "rails/rails" end + +group :development, :test do + gem 'minitest', '~> 5.14.0' +end + group :development do - gem 'minitest', '5.10.1' gem 'mocha' gem "rake" gem "yard" - platforms :ruby_21 do - gem "activerecord", "< 5.0" - gem "activesupport", "< 5.0" - end - platforms :ruby do - gem "sqlite3" + gem "activerecord", "< 7.0" + gem "activesupport", "< 7.0" + gem "sqlite3", '~> 1.4' gem "redcarpet" if RUBY_VERSION > "2.1.0" @@ -30,8 +31,4 @@ group :development do gem "activerecord-jdbcsqlite3-adapter" gem "jruby-openssl", :require => false # Silence openssl warnings. end -end - -group :test do - gem 'minitest', '5.10.1' -end +end \ No newline at end of file diff --git a/gemfiles/Gemfile-rails.6.1.x b/gemfiles/Gemfile-rails.6.1.x new file mode 100644 index 00000000..f686f7bc --- /dev/null +++ b/gemfiles/Gemfile-rails.6.1.x @@ -0,0 +1,21 @@ +source "http://rubygems.org" + +gemspec :path => ".." + +gem "activerecord", "~> 6.1.1" + +group :development do + gem 'mocha' + gem "rake" + gem "yard" + + platforms :ruby do + gem "sqlite3", '~> 1.4' + gem "redcarpet" + end + + platforms :jruby do + gem "activerecord-jdbcsqlite3-adapter" + gem "jruby-openssl", :require => false # Silence openssl warnings. + end +end diff --git a/lib/rails_erd/domain.rb b/lib/rails_erd/domain.rb index f292409b..bf836b89 100644 --- a/lib/rails_erd/domain.rb +++ b/lib/rails_erd/domain.rb @@ -49,7 +49,13 @@ def initialize(models = [], options = {}) # Returns the domain model name, which is the name of your Rails # application or +nil+ outside of Rails. def name - defined? Rails and Rails.application and Rails.application.class.parent.name + return unless defined?(Rails) && Rails.application + + if Rails.application.class.respond_to?(:module_parent) + Rails.application.class.module_parent.name + else + Rails.application.class.parent.name + end end # Returns all entities of your domain model. diff --git a/test/test_helper.rb b/test/test_helper.rb index 2febc6db..ff664526 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,6 +16,14 @@ ActiveSupport::TestCase.test_order = :random end +# Patch to make Rails 6.1 work. +module Kernel + # class_eval on an object acts like singleton_class.class_eval. + def class_eval(*args, &block) + singleton_class.class_eval(*args, &block) + end +end + class ActiveSupport::TestCase include RailsERD @@ -171,6 +179,11 @@ def name_to_object_symbol_pairs(name) parts[1..-1].inject([[Object, parts.first.to_sym]]) do |pairs,string| last_parent, last_child = pairs.last + # Fixes for Rails 6. No idea if this is actually correct as I can't decipher what the heck is going on in this + # code. + if last_child == :ActiveRecord || last_child == :primary + break [] + end break pairs unless last_parent.const_defined?(last_child) diff --git a/test/unit/attribute_test.rb b/test/unit/attribute_test.rb index f4f51404..f7d98a76 100644 --- a/test/unit/attribute_test.rb +++ b/test/unit/attribute_test.rb @@ -3,9 +3,9 @@ class AttributeTest < ActiveSupport::TestCase def with_native_limit(type, new_limit) - ActiveRecord::Base.connection.class_eval do + ActiveRecord::Base.connection.singleton_class.class_eval do undef :native_database_types - define_method :native_database_types do + define_method(:native_database_types) do super().tap do |types| types[type][:limit] = new_limit end @@ -13,9 +13,9 @@ def with_native_limit(type, new_limit) end yield ensure - ActiveRecord::Base.connection.class_eval do + ActiveRecord::Base.connection.singleton_class.class_eval do undef :native_database_types - define_method :native_database_types do + define_method(:native_database_types) do super() end end @@ -266,14 +266,14 @@ def create_attribute(model, name) end test "limit should return nil for oddball column types that misuse the limit attribute" do - create_model "Business", :location => :integer - attribute = create_attribute(Business, "location") - attribute.column.class_eval do - define_method :limit do + create_model "Business", :location => :integer do + define_singleton_method :limit do # https://github.com/voormedia/rails-erd/issues/21 { :srid => 4326, :type => "point", :geographic => true } end end + + attribute = create_attribute(Business, "location") assert_nil attribute.limit end @@ -306,13 +306,12 @@ def create_attribute(model, name) end test "scale should return nil for oddball column types that misuse the scale attribute" do - create_model "Kobold", :size => :integer - attribute = create_attribute(Kobold, "size") - attribute.column.class_eval do + create_model "Kobold", :size => :integer do define_method :scale do 1..5 end end + attribute = create_attribute(Kobold, "size") assert_nil attribute.scale end end