Skip to content

Commit 9929dbd

Browse files
authored
Rails: alias last_response to response (#863)
1 parent c732c3f commit 9929dbd

11 files changed

+58
-56
lines changed

spec/config/asset_pipeline_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
it "handles asset requests" do
99
get("/assets/stylesheets/application.css")
1010

11-
expect(last_response.body).to match("#feed-title")
11+
expect(response.body).to match("#feed-title")
1212
end
1313
end

spec/requests/debug_controller_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup
2121

2222
get "/debug"
2323

24-
page = last_response.body
24+
page = response.body
2525
expect(page).to have_tag("dd", text: /#{RUBY_VERSION}/)
2626
end
2727

@@ -31,7 +31,7 @@ def setup
3131

3232
get "/debug"
3333

34-
page = last_response.body
34+
page = response.body
3535
expect(page).to have_tag("dd", text: /testy/)
3636
end
3737

@@ -40,7 +40,7 @@ def setup
4040

4141
get "/debug"
4242

43-
page = last_response.body
43+
page = response.body
4444
expect(page).to have_tag("dd", text: /42/)
4545
end
4646

@@ -49,7 +49,7 @@ def setup
4949

5050
get "/debug"
5151

52-
rendered = Capybara.string(last_response.body)
52+
rendered = Capybara.string(response.body)
5353
expect(rendered).to have_selector("li", text: /Migration B - 2/)
5454
.and have_selector("li", text: /Migration C - 3/)
5555
end
@@ -59,7 +59,7 @@ def setup
5959
it "displays Heroku instructions" do
6060
get("/heroku")
6161

62-
expect(last_response.body).to include("add an hourly task")
62+
expect(response.body).to include("add an hourly task")
6363
end
6464
end
6565
end

spec/requests/exports_controller_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def expected_xml
2121

2222
get "/feeds/export"
2323

24-
expect(last_response.body).to eq(expected_xml)
24+
expect(response.body).to eq(expected_xml)
2525
end
2626

2727
it "responds with xml content type" do
2828
login_as(create(:user))
2929

3030
get "/feeds/export"
3131

32-
expect(last_response.header["Content-Type"]).to include("application/xml")
32+
expect(response.header["Content-Type"]).to include("application/xml")
3333
end
3434

3535
it "responds with disposition attachment" do
@@ -39,7 +39,7 @@ def expected_xml
3939

4040
expected =
4141
"attachment; filename=\"stringer.opml\"; filename*=UTF-8''stringer.opml"
42-
expect(last_response.header["Content-Disposition"]).to eq(expected)
42+
expect(response.header["Content-Disposition"]).to eq(expected)
4343
end
4444
end
4545
end

spec/requests/feeds_controller_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
get "/feeds"
1212

13-
rendered = Capybara.string(last_response.body)
13+
rendered = Capybara.string(response.body)
1414
expect(rendered).to have_selector("li.feed", count: 2)
1515
end
1616

@@ -19,7 +19,7 @@
1919

2020
get "/feeds"
2121

22-
page = last_response.body
22+
page = response.body
2323
expect(page).to have_tag("#add-some-feeds")
2424
end
2525
end
@@ -31,7 +31,7 @@
3131

3232
get "/feed/#{story.feed_id}"
3333

34-
expect(last_response.body).to have_tag("#stories")
34+
expect(response.body).to have_tag("#stories")
3535
end
3636
end
3737

@@ -42,7 +42,7 @@
4242

4343
get "/feeds/#{feed.id}/edit"
4444

45-
rendered = Capybara.string(last_response.body)
45+
rendered = Capybara.string(response.body)
4646
expect(rendered).to have_field("feed_name", with: "Rainbows/unicorns")
4747
end
4848
end
@@ -93,7 +93,7 @@ def params(feed, **overrides)
9393

9494
get "/feeds/new"
9595

96-
page = last_response.body
96+
page = response.body
9797
expect(page).to have_tag("form#add-feed-setup")
9898
end
9999
end
@@ -127,7 +127,7 @@ def params(feed, **overrides)
127127
stub_request(:get, feed_url).to_return(status: 404)
128128
post("/feeds", params: { feed_url: })
129129

130-
page = last_response.body
130+
page = response.body
131131
expect(page).to have_tag(".error")
132132
end
133133
end
@@ -142,7 +142,7 @@ def params(feed, **overrides)
142142

143143
post("/feeds", params: { feed_url: })
144144

145-
expect(last_response.body).to have_tag(".error")
145+
expect(response.body).to have_tag(".error")
146146
end
147147
end
148148
end

spec/requests/fever_controller_spec.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def cannot_auth
1111
{ api_version: 3, auth: 0 }
1212
end
1313

14-
def last_response_as_object
15-
JSON.parse(last_response.body, symbolize_names: true)
14+
def response_as_object
15+
JSON.parse(response.body, symbolize_names: true)
1616
end
1717

1818
def params(user: create(:user), **overrides)
@@ -23,29 +23,29 @@ def params(user: create(:user), **overrides)
2323
it "authenticates request with correct api_key" do
2424
get("/fever", params:)
2525

26-
expect(last_response_as_object).to include(standard_answer)
26+
expect(response_as_object).to include(standard_answer)
2727
end
2828

2929
it "does not authenticate request with incorrect api_key" do
3030
get "/fever", params: params(api_key: "foo")
3131

32-
expect(last_response_as_object).to include(cannot_auth)
32+
expect(response_as_object).to include(cannot_auth)
3333
end
3434

3535
it "does not authenticate request when api_key is not provided" do
3636
create(:user)
3737

3838
get "/fever", params: params(api_key: nil)
3939

40-
expect(last_response_as_object).to include(cannot_auth)
40+
expect(response_as_object).to include(cannot_auth)
4141
end
4242
end
4343

4444
describe "#get" do
4545
it "returns standard answer" do
4646
get("/fever", params:)
4747

48-
expect(last_response_as_object).to include(standard_answer)
48+
expect(response_as_object).to include(standard_answer)
4949
end
5050

5151
it "returns groups and feeds by groups when 'groups' header is provided" do
@@ -54,7 +54,7 @@ def params(user: create(:user), **overrides)
5454
get("/fever", params: params(groups: nil))
5555

5656
groups = [{ group_id: feed.group_id, feed_ids: feed.id.to_s }]
57-
expect(last_response_as_object).to include(standard_answer)
57+
expect(response_as_object).to include(standard_answer)
5858
.and include(groups: [feed.group.as_fever_json], feeds_groups: groups)
5959
end
6060

@@ -64,15 +64,15 @@ def params(user: create(:user), **overrides)
6464
get("/fever", params: params(feeds: nil))
6565

6666
groups = [{ group_id: feed.group_id, feed_ids: feed.id.to_s }]
67-
expect(last_response_as_object).to include(standard_answer)
67+
expect(response_as_object).to include(standard_answer)
6868
.and include(feeds: [feed.as_fever_json], feeds_groups: groups)
6969
end
7070

7171
it "returns favicons hash when 'favicons' header provided" do
7272
get("/fever", params: params(favicons: nil))
7373

7474
favicon = { id: 0, data: a_string_including("image/gif;base64") }
75-
expect(last_response_as_object).to include(standard_answer)
75+
expect(response_as_object).to include(standard_answer)
7676
.and include(favicons: [favicon])
7777
end
7878

@@ -82,7 +82,7 @@ def params(user: create(:user), **overrides)
8282

8383
get("/fever", params: params(items: nil, since_id: 5))
8484

85-
expect(last_response_as_object).to include(standard_answer)
85+
expect(response_as_object).to include(standard_answer)
8686
.and include(items: [story_two.as_fever_json], total_items: 2)
8787
end
8888

@@ -91,7 +91,7 @@ def params(user: create(:user), **overrides)
9191

9292
get("/fever", params: params(items: nil))
9393

94-
expect(last_response_as_object).to include(standard_answer)
94+
expect(response_as_object).to include(standard_answer)
9595
.and include(items: stories.map(&:as_fever_json), total_items: 2)
9696
end
9797

@@ -100,14 +100,14 @@ def params(user: create(:user), **overrides)
100100

101101
get("/fever", params: params(items: nil, with_ids: story.id))
102102

103-
expect(last_response_as_object).to include(standard_answer)
103+
expect(response_as_object).to include(standard_answer)
104104
.and include(items: [story.as_fever_json], total_items: 1)
105105
end
106106

107107
it "returns links as empty array when 'links' header is provided" do
108108
get("/fever", params: params(links: nil))
109109

110-
expect(last_response_as_object).to include(standard_answer)
110+
expect(response_as_object).to include(standard_answer)
111111
.and include(links: [])
112112
end
113113

@@ -116,7 +116,7 @@ def params(user: create(:user), **overrides)
116116

117117
get("/fever", params: params(unread_item_ids: nil))
118118

119-
expect(last_response_as_object).to include(standard_answer)
119+
expect(response_as_object).to include(standard_answer)
120120
.and include(unread_item_ids: stories.map(&:id).join(","))
121121
end
122122

@@ -125,7 +125,7 @@ def params(user: create(:user), **overrides)
125125

126126
get("/fever", params: params(saved_item_ids: nil))
127127

128-
expect(last_response_as_object).to include(standard_answer)
128+
expect(response_as_object).to include(standard_answer)
129129
.and include(saved_item_ids: stories.map(&:id).join(","))
130130
end
131131
end
@@ -136,31 +136,31 @@ def params(user: create(:user), **overrides)
136136

137137
post("/fever", params: params(mark: "item", as: "read", id: story.id))
138138

139-
expect(last_response_as_object).to include(standard_answer)
139+
expect(response_as_object).to include(standard_answer)
140140
end
141141

142142
it "commands to mark story as unread" do
143143
story = create(:story, :read)
144144

145145
post("/fever", params: params(mark: "item", as: "unread", id: story.id))
146146

147-
expect(last_response_as_object).to include(standard_answer)
147+
expect(response_as_object).to include(standard_answer)
148148
end
149149

150150
it "commands to save story" do
151151
story = create(:story)
152152

153153
post("/fever", params: params(mark: "item", as: "saved", id: story.id))
154154

155-
expect(last_response_as_object).to include(standard_answer)
155+
expect(response_as_object).to include(standard_answer)
156156
end
157157

158158
it "commands to unsave story" do
159159
story = create(:story, :starred)
160160

161161
post("/fever", params: params(mark: "item", as: "unsaved", id: story.id))
162162

163-
expect(last_response_as_object).to include(standard_answer)
163+
expect(response_as_object).to include(standard_answer)
164164
end
165165

166166
it "commands to mark group as read" do
@@ -170,7 +170,7 @@ def params(user: create(:user), **overrides)
170170

171171
post("/fever", params: params(mark: "group", as: "read", id:, before:))
172172

173-
expect(last_response_as_object).to include(standard_answer)
173+
expect(response_as_object).to include(standard_answer)
174174
end
175175

176176
it "commands to mark entire feed as read" do

spec/requests/imports_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
get "/feeds/import"
1111

12-
page = last_response.body
12+
page = response.body
1313
expect(page).to have_tag("input#opml_file")
1414
end
1515
end

spec/requests/passwords_controller_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313

1414
get "/setup/password"
1515

16-
page = last_response.body
16+
page = response.body
1717
expect(page).to have_tag("form#password_setup")
1818
end
1919
end
@@ -24,7 +24,7 @@ def setup
2424

2525
post "/setup/password"
2626

27-
page = last_response.body
27+
page = response.body
2828
expect(page).to have_tag("div.error")
2929
end
3030

@@ -34,15 +34,15 @@ def setup
3434
post "/setup/password",
3535
params: { password: "foo", password_confirmation: "bar" }
3636

37-
page = last_response.body
37+
page = response.body
3838
expect(page).to have_tag("div.error")
3939
end
4040

4141
it "accepts confirmed passwords and redirects to next step" do
4242
post "/setup/password",
4343
params: { password: "foo", password_confirmation: "foo" }
4444

45-
expect(URI.parse(last_response.location).path).to eq("/feeds/import")
45+
expect(URI.parse(response.location).path).to eq("/feeds/import")
4646
end
4747
end
4848
end

0 commit comments

Comments
 (0)