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

Fix dashboard generator for attributes that are neither reflections nor columns #1290

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

s-mage
Copy link
Contributor

@s-mage s-mage commented Feb 23, 2019

Rails allow to define custom attribute. It's usually used for coersion but nothing prevents me to use it as attr_accessor. For such cases generator was failing with undefined method 'has_one?' for nil:NilClass (NoMethodError)

With this fix generator doesn't try to define what's that and relies on column names instead of attribute names.

# Attributes is a rails 5 feature
if ActiveRecord.version >= Gem::Version.new(5)
it "skips temporary attributes" do
begin

Choose a reason for hiding this comment

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

Style/RedundantBegin: Redundant begin block detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no it's not for ruby <= 2.5

@s-mage
Copy link
Contributor Author

s-mage commented Mar 8, 2019

ruby 2.2 and 2.3 fails are not caused by my changes

@nickcharlton
Copy link
Member

This solves the same issue as #1100 for me on a project I'm integrating with which used attr_encrypted. I'm hoping this works more broadly, too.

I'm going to shortly drop older than Ruby 2.4 support, so I'm just going to ignore those failures (and drop that begin, too. So for now I'm going to merge this.

Thanks for your PR!

Rails allows for custom attributes, and these are often used with gems
such as `attr_encrypted`. Previously, the Dashboard generator would fail
with:

> undefined method `has_one?' for nil:NilClass (NoMethodError)

Instead of failing with an error, this ensures we rely on column names
instead of attributes names.
@nickcharlton nickcharlton merged commit 4e36c31 into thoughtbot:master Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants