Skip to content

Commit

Permalink
Copy the index_header partial when generating views (#2582)
Browse files Browse the repository at this point in the history
The index_header contains the search bar and the
New resource button, which may need to be customized.
Currently this file is not created as part of the
generated customized view files, so it must
be created manually.
  • Loading branch information
littleforest committed May 16, 2024
1 parent 01ab492 commit 7b7ac38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/generators/administrate/views/index_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class IndexGenerator < Administrate::ViewGenerator
def copy_template
copy_resource_template("index")
copy_resource_template("_collection")
copy_resource_template("_index_header")
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions spec/generators/views/index_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

expect(contents).to eq(expected_contents)
end

it "copies the index_header partial into the `admin/application` namespace" do
expected_contents = contents_for_application_template("_index_header")
generated_file = file("app/views/admin/application/_index_header.html.erb")

run_generator []
contents = File.read(generated_file)

expect(contents).to eq(expected_contents)
end
end

describe "administrate:views:index resource" do
Expand All @@ -41,6 +51,15 @@

expect(contents).to eq(expected_contents)
end

it "copies the index_header partial into the `admin/resource` namespace" do
expected_contents = contents_for_application_template("_index_header")

run_generator ["users"]
contents = File.read(file("app/views/admin/users/_index_header.html.erb"))

expect(contents).to eq(expected_contents)
end
end

describe "administrate:views:index resource --namespace=<namespace>" do
Expand All @@ -61,5 +80,14 @@

expect(contents).to eq(expected_contents)
end

it "copies the index_header partial into the `namespace/resource` namespace" do
expected_contents = contents_for_application_template("_index_header")

run_generator ["users", "--namespace", "console"]
contents = File.read(file("app/views/console/users/_index_header.html.erb"))

expect(contents).to eq(expected_contents)
end
end
end

0 comments on commit 7b7ac38

Please sign in to comment.