diff --git a/lib/generators/administrate/routes/routes_generator.rb b/lib/generators/administrate/routes/routes_generator.rb index cf7b45e3aa..0ef8952b77 100644 --- a/lib/generators/administrate/routes/routes_generator.rb +++ b/lib/generators/administrate/routes/routes_generator.rb @@ -43,7 +43,7 @@ def valid_dashboard_models end def database_models - ActiveRecord::Base.descendants + ActiveRecord::Base.descendants.reject(&:abstract_class?) end def invalid_database_models diff --git a/spec/generators/routes_generator_spec.rb b/spec/generators/routes_generator_spec.rb index 3dd17f5770..a5ce3476ab 100644 --- a/spec/generators/routes_generator_spec.rb +++ b/spec/generators/routes_generator_spec.rb @@ -21,20 +21,22 @@ stub_generator_dependencies routes = file("config/routes.rb") - run_generator + output = run_generator expect(routes).not_to contain("delayed/backend/active_record/jobs") + expect(output).to include("WARNING: Unable to generate a dashboard for Delayed::Backend::ActiveRecord::Job") end - it "skips models that aren't backed by the database" do + it "skips models that aren't backed by the database with a warning" do begin class ModelWithoutDBTable < ActiveRecord::Base; end stub_generator_dependencies routes = file("config/routes.rb") - run_generator + output = run_generator expect(routes).not_to contain("model_without_db_table") + expect(output).to include("WARNING: Unable to generate a dashboard for ModelWithoutDBTable") ensure remove_constants :ModelWithoutDBTable end @@ -54,6 +56,22 @@ def self.table_name routes = file("config/routes.rb") expect(routes).to have_correct_syntax end + + it "skips abstract models without a warning" do + stub_generator_dependencies + routes = file("config/routes.rb") + + begin + class AbstractModel < ActiveRecord::Base + self.abstract_class = true + end + + output = run_generator + + expect(routes).not_to contain("abstract_model") + expect(output).not_to include("WARNING: Unable to generate a dashboard for AbstractModel") + end + end end it "creates a root route for the admin namespace" do