From 54d31a2b34100993d208b41025570600b6a0efc0 Mon Sep 17 00:00:00 2001 From: Anthony Davis Date: Thu, 11 Sep 2014 12:39:36 -0500 Subject: [PATCH] VRFS-2001 - user-agent header was not set when switching Capybara sessions --- monitor/spec/production_spec.rb | 14 +++++++------- monitor/spec/support/utilities.rb | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/monitor/spec/production_spec.rb b/monitor/spec/production_spec.rb index 7094adc23..4a129836e 100755 --- a/monitor/spec/production_spec.rb +++ b/monitor/spec/production_spec.rb @@ -48,7 +48,7 @@ describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_fe end it "is possible for #{user1} to sign in and not get disconnected within 30 seconds" do - in_client(user1) do + as_monitor(user1) do puts "\n *** #{user1}'s client *** \n" sign_in_poltergeist user1 repeat_for(30.seconds) do @@ -60,7 +60,7 @@ describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_fe it "is possible for #{user1} and #{user2} to see each other online, and to send messages" do # this example heavily based on text_message_spec.rb in 'web' - in_client(user1) do + as_monitor(user1) do puts "\n *** #{user1}'s client *** \n" sign_in_poltergeist(user1) end @@ -69,7 +69,7 @@ describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_fe test_response = "#{SecureRandom.uuid} - Hey yourself, #{user2}!" test_goodbye = "#{SecureRandom.uuid} - OK bye!" - in_client(user2) do + as_monitor(user2) do puts "\n *** #{user2}'s client *** \n" sign_in_poltergeist(user2) expect(page).to have_xpath( @@ -83,7 +83,7 @@ describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_fe send_text_message(test_message) end - in_client(user1) do + as_monitor(user1) do puts "\n *** #{user1}'s client *** \n" expect(page).to have_xpath( "//div[@class='friend-name' and @user-id='#{user2.id}']/span[@class='friend-status']", @@ -94,14 +94,14 @@ describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_fe send_text_message(test_response, close_on_send: true) end - in_client(user2) do + as_monitor(user2) do puts "\n *** #{user2}'s client *** \n" find('.previous-message-text', text: test_response) send_text_message(test_goodbye, close_on_send: true) end - in_client(user1) { puts "\n *** #{user1}'s client *** \n"; sign_out_poltergeist } - in_client(user2) { puts "\n *** #{user2}'s client *** \n"; sign_out_poltergeist } + as_monitor(user1) { puts "\n *** #{user1}'s client *** \n"; sign_out_poltergeist } + as_monitor(user2) { puts "\n *** #{user2}'s client *** \n"; sign_out_poltergeist } end let(:queue_limit) { 5 } diff --git a/monitor/spec/support/utilities.rb b/monitor/spec/support/utilities.rb index 9003be855..c350e80b0 100755 --- a/monitor/spec/support/utilities.rb +++ b/monitor/spec/support/utilities.rb @@ -49,6 +49,12 @@ def in_client(name) yield end +def as_monitor(name) + session_name = name.class == JamRuby::User ? name.id : name + Capybara.session_name = mapped_session_name(session_name) + page.driver.headers = { 'User-Agent' => 'monitor' } + yield +end def cookie_jar Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar