Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract model classes should be skipped without warning. #857

Merged
merged 1 commit into from
May 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Abstract model classes should be skipped without warning.
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.

Use shortened syntax and strip whitespace.
  • Loading branch information
lukeredpath authored and nickcharlton committed May 8, 2017
commit 1d235cdade3875b217ff7bb91eda3411ef502a1c
2 changes: 1 addition & 1 deletion lib/generators/administrate/routes/routes_generator.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 21 additions & 2 deletions spec/generators/routes_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -42,14 +42,16 @@
MSG
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
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
@@ -68,6 +70,23 @@ 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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this always pass since you load up the routes file before running the generator?

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