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

Generate SHOW_PAGE_ATTRIBUTES as an explicit array #364

Merged
merged 1 commit into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* [#269] [FEATURE] Add a generator for copying default layout files
* [#328] [FEATURE] Add a generator for copying default sidebar partial
* [#295] [FEATURE] Add dashboard detection for ActiveRecord::Enum fields.
* [#364] [FEATURE] Improve dashboard generator by explicitly listing out the
generated `SHOW_PAGE_ATTRIBUTES` array elements.
* [#297] [I18n] Add Italian translations
* [#307] [I18n] Fix German grammatical errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys
SHOW_PAGE_ATTRIBUTES = [
<%=
attributes.map do |attr|
" :#{attr},"
end.join("\n")
%>
]

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
Expand Down
25 changes: 25 additions & 0 deletions spec/generators/dashboard_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,31 @@ class Foo < ActiveRecord::Base
end
end

describe "SHOW_PAGE_ATTRIBUTES" do
it "includes all attributes" do
begin
ActiveRecord::Schema.define do
create_table :foos do |t|
t.string :name
t.timestamps
end
end

class Foo < ActiveRecord::Base
reset_column_information
end

run_generator ["foo"]
load file("app/dashboards/foo_dashboard.rb")

attrs = FooDashboard::SHOW_PAGE_ATTRIBUTES
expect(attrs).to match_array([:name, :id, :created_at, :updated_at])
ensure
remove_constants :Foo, :FooDashboard
end
end
end

describe "resource controller" do
it "has valid syntax" do
controller = file("app/controllers/admin/customers_controller.rb")
Expand Down