Skip to content

Instantly share code, notes, and snippets.

@vast

vast/bureau.ru_spec.rb Secret

Created Feb 26, 2018
Embed
What would you like to do?
# frozen_string_literal: true
RSpec.describe "bureau.ru move", js: true do
include Capybara::DSL
OLD_HOST = "artgorbunov-s1.ru"
YANDEX_BOT_UA = "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
before do
page.driver.add_headers("User-Agent" => "Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34")
end
context "when visiting artgorbunov.ru" do
it "redirects to bureau.ru" do
visit "http://#{OLD_HOST}/bureau"
expect(page.current_url).to eq "http://bureau.ru/bureau/"
expect(page).to have_content("открыто в 2007 году")
end
end
context "when visiting bureau.ru directly" do
context "as a YandexBot" do
it "returns page as is" do
page.driver.add_headers("User-Agent" => YANDEX_BOT_UA)
visit "http://bureau.ru/bureau/"
expect(page.current_url).to eq "http://bureau.ru/bureau/"
expect(page).to have_content("открыто в 2007 году")
end
end
context "as someone who already has session" do
it "returns page as is" do
page.driver.set_cookie("sessionId", "qwe123", domain: "bureau.ru")
visit "http://bureau.ru/bureau/"
expect(page.current_url).to eq "http://bureau.ru/bureau/"
expect(page).to have_content("открыто в 2007 году")
end
end
context "as someone who has already transfered their cookies" do
it "returns page as is" do
page.driver.set_cookie("cookie_transfer_complete", "1", domain: "bureau.ru")
visit "http://bureau.ru/bureau/"
expect(page.current_url).to eq "http://bureau.ru/bureau/"
expect(page).to have_content("открыто в 2007 году")
end
end
context "otherwise" do
let(:cookies) do
{
sessionId: "qwe123",
name: "name_cookie",
email: "email_cookie",
b_name: "b_name_cookie",
b_email: "b_email_cookie"
}
end
before { page.driver.clear_cookies }
it "transfers cookies from artgorbunov.ru" do
cookies.each do |cookie, value|
page.driver.set_cookie(cookie, value, domain: OLD_HOST)
end
visit "http://#{OLD_HOST}/projects/marytrufel-stickers/"
expect(page.current_url).to eq "http://bureau.ru/projects/marytrufel-stickers/"
expect(page.driver.cookies["sessionId"].value).to eq "qwe123"
expect(page.driver.cookies["cookie_transfer_complete"].value).to eq "1"
expect(page.driver.cookies["name"].value).to eq "name_cookie"
expect(page.driver.cookies["email"].value).to eq "email_cookie"
expect(page.driver.cookies["b_name"].value).to eq "b_name_cookie"
expect(page.driver.cookies["b_email"].value).to eq "b_email_cookie"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.