8000 Fix CSV responses when index overriding with the call alias method by megos · Pull Request #8031 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Fix CSV responses when index overriding with the call alias method #8031

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def index
yield(format) if block_given?
end
end
alias :index! :index

protected

Expand Down
41 changes: 33 additions & 8 deletions spec/unit/authorization/index_overriding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@
before do
load_resources { ActiveAdmin.register Post }
@controller = Admin::PostsController.new
end

@controller.instance_eval do
def index
super do
render body: "Rendered from passed block"
return
context "with the call super" do
before do
@controller.instance_eval do
def index
super do |format|
format.html { render body: "Rendered from passed block" }
end
end
end
end

it "should call block passed to overridden index" do
get :index
expect(response.body).to eq "Rendered from passed block"
end

it "can CSV responses" do
get :index, format: :csv
expect(response.header["Content-Type"]).to eq "text/csv; charset=utf-8"
end
end

it "should call block passed to overridden index" do
get :index
expect(response.body).to eq "Rendered from passed block"
context "with the call alias method" do
before do
@controller.instance_eval do
def index
index! do
# Do nothing
end
end
end
end

it "can CSV responses" do
get :index, format: :csv
expect(response.header["Content-Type"]).to eq "text/csv; charset=utf-8"
end
end
end
2 changes: 1 addition & 1 deletion spec/unit/resource_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def call_after_destroy(obj); end

it "should have actual action methods" do
controller.class.clear_action_methods! # make controller recalculate :action_methods on the next call
expect(controller.action_methods.sort).to eq ["batch_action", "create", "destroy", "edit", "index", "new", "show", "update"]
expect(controller.action_methods.sort).to eq ["batch_action", "create", "destroy", "edit", "index", "index!", "new", "show", "update"]
end
end
end
Expand Down
0