DEV: simpler spec for wayback machine crawler layout (#7696)

follow-up on 42809f4d
This commit is contained in:
Maja Komel 2019-06-05 03:24:52 +02:00 committed by Sam
parent 1cf0b549ab
commit 9779307efc
1 changed files with 34 additions and 31 deletions

View File

@ -2677,7 +2677,6 @@ RSpec.describe TopicsController do
end end
describe "crawler" do describe "crawler" do
context "when not a crawler" do context "when not a crawler" do
it "renders with the application layout" do it "renders with the application layout" do
get topic.url get topic.url
@ -2690,14 +2689,14 @@ RSpec.describe TopicsController do
end end
context "when a crawler" do context "when a crawler" do
let(:topic) { Fabricate(:topic) } it "renders with the crawler layout, and handles proper pagination" do
let(:page1_time) { 3.months.ago } page1_time = 3.months.ago
let(:page2_time) { 2.months.ago } page2_time = 2.months.ago
let(:page3_time) { 1.month.ago } page3_time = 1.month.ago
before do
freeze_time page1_time freeze_time page1_time
topic = Fabricate(:topic)
Fabricate(:post, topic: topic) Fabricate(:post, topic: topic)
Fabricate(:post, topic: topic) Fabricate(:post, topic: topic)
@ -2711,40 +2710,44 @@ RSpec.describe TopicsController do
# ugly, but no inteface to set this and we don't want to create # ugly, but no inteface to set this and we don't want to create
# 100 posts to test this thing # 100 posts to test this thing
TopicView.stubs(:chunk_size).returns(2) TopicView.stubs(:chunk_size).returns(2)
user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
get topic.url, env: { "HTTP_USER_AGENT" => user_agent }
body = response.body
expect(body).to have_tag(:body, with: { class: 'crawler' })
expect(body).to_not have_tag(:meta, with: { name: 'fragment' })
expect(body).to include('<link rel="next" href="' + topic.relative_url + "?page=2")
expect(response.headers['Last-Modified']).to eq(page1_time.httpdate)
get topic.url + "?page=2", env: { "HTTP_USER_AGENT" => user_agent}
body = response.body
expect(response.headers['Last-Modified']).to eq(page2_time.httpdate)
expect(body).to include('<link rel="prev" href="' + topic.relative_url)
expect(body).to include('<link rel="next" href="' + topic.relative_url + "?page=3")
get topic.url + "?page=3", env: { "HTTP_USER_AGENT" => user_agent}
body = response.body
expect(response.headers['Last-Modified']).to eq(page3_time.httpdate)
expect(body).to include('<link rel="prev" href="' + topic.relative_url + "?page=2")
end end
shared_examples "crawler layout" do |user_agent, via| context "wayback machine" do
it "renders with the crawler layout, and handles proper pagination" do it "renders crawler layout" do
get topic.url, env: { "HTTP_USER_AGENT" => user_agent, "HTTP_VIA" => via } get topic.url, env: { "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "HTTP_VIA" => "HTTP/1.0 web.archive.org (Wayback Save Page)" }
body = response.body body = response.body
expect(body).to have_tag(:body, with: { class: 'crawler' }) expect(body).to have_tag(:body, with: { class: 'crawler' })
expect(body).to_not have_tag(:meta, with: { name: 'fragment' }) expect(body).to_not have_tag(:meta, with: { name: 'fragment' })
expect(body).to include('<link rel="next" href="' + topic.relative_url + "?page=2")
expect(response.headers['Last-Modified']).to eq(page1_time.httpdate)
get topic.url + "?page=2", env: { "HTTP_USER_AGENT" => user_agent, "HTTP_VIA" => via }
body = response.body
expect(response.headers['Last-Modified']).to eq(page2_time.httpdate)
expect(body).to include('<link rel="prev" href="' + topic.relative_url)
expect(body).to include('<link rel="next" href="' + topic.relative_url + "?page=3")
get topic.url + "?page=3", env: { "HTTP_USER_AGENT" => user_agent, "HTTP_VIA" => via }
body = response.body
expect(response.headers['Last-Modified']).to eq(page3_time.httpdate)
expect(body).to include('<link rel="prev" href="' + topic.relative_url + "?page=2")
end end
end end
include_examples "crawler layout", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", nil
include_examples "crawler layout", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "HTTP/1.0 web.archive.org (Wayback Save Page)"
end end
end end
describe "#reset_bump_date" do describe "#reset_bump_date" do