From 8e945d6d9208dbe01b4664e09ba4e50dcaf92890 Mon Sep 17 00:00:00 2001 From: Luke Redpath Date: Mon, 16 May 2016 12:30:08 +0100 Subject: [PATCH 1/2] Abstract model classes should be skipped without warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve also clarified the existing specs by including an assertion against the presence of a warning, so the name of the spec matches what is actually being tested. --- .../administrate/routes/routes_generator.rb | 2 +- spec/generators/routes_generator_spec.rb | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/generators/administrate/routes/routes_generator.rb b/lib/generators/administrate/routes/routes_generator.rb index cf7b45e3aa..13689bd21b 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 { |klass| klass.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..3985007726 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 From 4551dc67b773cb8617651164041598563b73c9bb Mon Sep 17 00:00:00 2001 From: Luke Redpath Date: Mon, 16 May 2016 12:34:58 +0100 Subject: [PATCH 2/2] Use shortened syntax and strip whitespace. --- lib/generators/administrate/routes/routes_generator.rb | 2 +- spec/generators/routes_generator_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/administrate/routes/routes_generator.rb b/lib/generators/administrate/routes/routes_generator.rb index 13689bd21b..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.reject { |klass| klass.abstract_class? } + 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 3985007726..a5ce3476ab 100644 --- a/spec/generators/routes_generator_spec.rb +++ b/spec/generators/routes_generator_spec.rb @@ -56,11 +56,11 @@ def self.table_name routes = file("config/routes.rb") expect(routes).to have_correct_syntax end - - it 'skips abstract models without a warning' do + + 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