Skip to content

Commit 915e3f7

Browse files
author
Jake Boxer
committed
Add spec for live reloading partials
1 parent 111fec3 commit 915e3f7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

spec/application_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,24 @@
245245
expect(text_in(response.body, "title")).to eql("Changed")
246246
end
247247

248+
it "reloads changed partials" do
249+
# On the first request, <p> text should not be "Changed"
250+
response = @request.get("/")
251+
expect(response).to be_ok
252+
expect(text_in(response.body, "p.spec-in-partial")).not_to eql("Changed")
253+
254+
# Load partial and change the <p> to "Changed"
255+
partial_path = File.join(@root, "app", "views", "subdir", "_partial.html.erb")
256+
partial_data = File.read(partial_path)
257+
partial_data.sub!(/<p class="spec-in-partial">[^<]*<\/p>/, "<p class=\"spec-in-partial\">Changed</p>")
258+
File.write(partial_path, partial_data)
259+
260+
# On the second request, <p> text should be "Changed"
261+
response = @request.get("/")
262+
expect(response).to be_ok
263+
expect(text_in(response.body, "p.spec-in-partial")).to eql("Changed")
264+
end
265+
248266
it "reloads changed views" do
249267
# On the first request, <h2> text should not be "Changed"
250268
response = @request.get("/")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p>This is coming from a partial.</p>
1+
<p class="spec-in-partial">This is coming from a partial.</p>

0 commit comments

Comments
 (0)