Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !259

Don't generate dashboards for non-constant models

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge gw-ignore-unnamed-classes into master Nov 20, 2015
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 3

Created by: gracewashere

Fixes #145 (closed) and #219 (closed)

Problem:

When the same has_and_belongs_to_many relationship is defined twice, Rails generates an unnamed subclass of ActiveRecord::Base. This is probably a bug in Rails.

The unnamed subclass shows up like this:

> ActiveRecord::Base.descendants.last
 #<Class:0x007fddea1bdf08> (call '#<Class:0x007fddea1bdf08>.connection' to establish a connection)

When the install generator tries to populate the DashboardManifest with all of the ActiveRecord models, it trips up on unnamed models, and generates a manifest with invalid syntax.

This results in a NameError for the user when they run the administrate:install generator:

/gems/administrate-0.1.0/lib/generators/administrate/dashboard/dashboard_generator.rb:87:
in `const_get': wrong constant name #<class:0x007fcf52bfe248> (NameError)

This error most often pops up in applications that are using the spring gem.

Solution:

  • Add a test case that reproduces the error by defining duplicate has_many associations.
  • In the install generator, ignore any models that are not constants. We determine constants by checking that the model's #name matches its #to_s.
  • Print a warning for the ignored models.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: gw-ignore-unnamed-classes