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

Sort dashboard attributes #2133

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
<% attributes.each do |attr| -%>
<% attributes.sort.each do |attr| -%>
<%= attr %>: <%= field_type(attr) %>,
<% end -%>
}.freeze
Expand Down
9 changes: 6 additions & 3 deletions spec/generators/dashboard_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Foo < ApplicationRecord
load file("app/dashboards/foo_dashboard.rb")
attrs = FooDashboard::ATTRIBUTE_TYPES

expect(attrs[:id]).to eq(Administrate::Field::Number)
expect(attrs[:created_at]).to eq(Administrate::Field::DateTime)
expect(attrs[:id]).to eq(Administrate::Field::Number)
pablobm marked this conversation as resolved.
Show resolved Hide resolved
expect(attrs[:updated_at]).to eq(Administrate::Field::DateTime)
ensure
remove_constants :Foo, :FooDashboard
Expand Down Expand Up @@ -323,10 +323,13 @@ class Foo < ApplicationRecord

run_generator ["foo"]
load file("app/dashboards/foo_dashboard.rb")
all_attrs = FooDashboard::ATTRIBUTE_TYPES.keys
all_attrs = FooDashboard::ATTRIBUTE_TYPES.keys.sort
table_attrs = FooDashboard::COLLECTION_ATTRIBUTES

expect(table_attrs).to eq(all_attrs.first(table_attribute_limit))
expect(table_attrs).to contain_exactly(
:id,
*all_attrs.first(table_attribute_limit - 1),
)
expect(table_attrs).not_to eq(all_attrs)
ensure
remove_constants :Foo, :FooDashboard
Expand Down