diff --git a/lib/generators/administrate/dashboard/templates/dashboard.rb.erb b/lib/generators/administrate/dashboard/templates/dashboard.rb.erb index 7c0a65c0a9..3e122d28e5 100644 --- a/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +++ b/lib/generators/administrate/dashboard/templates/dashboard.rb.erb @@ -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 diff --git a/spec/generators/dashboard_generator_spec.rb b/spec/generators/dashboard_generator_spec.rb index 85fb61451e..e0caa0acf1 100644 --- a/spec/generators/dashboard_generator_spec.rb +++ b/spec/generators/dashboard_generator_spec.rb @@ -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) expect(attrs[:updated_at]).to eq(Administrate::Field::DateTime) ensure remove_constants :Foo, :FooDashboard @@ -323,10 +323,10 @@ 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