Skip to content

Commit

Permalink
Fix CSV responses when index overriding with the call alias method
Browse files Browse the repository at this point in the history
  • Loading branch information
megos committed Jul 26, 2023
1 parent 2692838 commit 0e3da46
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/active_admin/resource_controller/streaming.rb
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
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).to have_http_status :ok
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).to have_http_status :ok
end
end
end

0 comments on commit 0e3da46

Please sign in to comment.