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
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
4 changes: 3 additions & 1 deletion lib/generators/administrate/dashboard/dashboard_generator.rb
Original file line number Diff line number Diff line change
@@ -50,7 +50,9 @@ def namespace
end

def attributes
klass.reflections.keys + klass.attribute_names - redundant_attributes
klass.reflections.keys +
klass.columns.map(&:name) -
redundant_attributes
end

def form_attributes
23 changes: 23 additions & 0 deletions spec/generators/dashboard_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -349,6 +349,29 @@ class Ticket < ActiveRecord::Base
remove_constants :Account, :Ticket
end
end

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

ActiveRecord::Schema.define do
create_table :accounts
end

class Account < ActiveRecord::Base
reset_column_information
attribute :tmp_attribute, :boolean
end

dashboard = file("app/dashboards/account_dashboard.rb")

run_generator ["account"]

expect(dashboard).not_to contain("tmp_attribute")
ensure
remove_constants :Account
end
end
end
end

describe "COLLECTION_ATTRIBUTES" do