8000 Fix CSV responses when index overriding with the call alias method · activeadmin/activeadmin@0da137b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0da137b

Browse files
megosjavierjulio
authored andcommitted
Fix CSV responses when index overriding with the call alias method
1 parent a6d8d45 commit 0da137b

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

lib/active_admin/resource_controller/streaming.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def index
1515
yield(format) if block_given?
1616
end
1717
end
18+
alias :index! :index
1819

1920
protected
2021

spec/unit/authorization/index_overriding_spec.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,44 @@
55
before do
66
load_resources { ActiveAdmin.register Post }
77
@controller = Admin::PostsController.new
8+
end
89

9-
@controller.instance_eval do
10-
def index
11-
super do
12-
render body: "Rendered from passed block"
13-
return
10+
context "with the call super" do
11+
before do
12+
@controller.instance_eval do
13+
def index
14+
super do |format|
15+
format.html { render body: "Rendered from passed block" }
16+
end
1417
end
1518
end
1619
end
20+
21+
it "should call block passed to overridden index" do
22+
get :index
23+
expect(response.body).to eq "Rendered from passed block"
24+
end
25+
26+
it "can CSV responses" do
27+
get :index, format: :csv
28+
expect(response.header["Content-Type"]).to eq "text/csv; charset=utf-8"
29+
end
1730
end
1831

19-
it "should call block passed to overridden index" do
20-
get :index
21-
expect(response.body).to eq "Rendered from passed block"
32+
context "with the call alias method" do
33+
before do
34+
@controller.instance_eval do
35+
def index
36+
index! do
37+
# Do nothing
38+
end
39+
end
40+
end
41+
end
42+
43+
it "can CSV responses" do
44+
get :index, format: :csv
45+
expect(response.header["Content-Type"]).to eq "text/csv; charset=utf-8"
46+
end
2247
end
2348
end

0 commit comments

Comments
 (0)
0