Skip to content

Commit

Permalink
Switch sessions when the subdomain is switched
Browse files Browse the repository at this point in the history
  • Loading branch information
snelson committed Mar 25, 2011
1 parent 31236c2 commit 3dc26a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 10 additions & 6 deletions spec/acceptance/subdomains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
end

scenario "Access subdomain one" do
Capybara.default_host = "one.example.com"
Capybara.app_host = "http://one.example.com"
set_subdomain("one")
visit '/'
current_url.should == "http://one.example.com/" # passes
find("h1").text.should == "http://one.example.com/" # fails with envjs
find("h1").text.should == "http://one.example.com/" # passes
end

scenario "Access subdomain two" do
Capybara.default_host = "two.example.com"
Capybara.app_host = "http://two.example.com"
set_subdomain("two")
visit '/'
current_url.should == "http://two.example.com/" # passes
find("h1").text.should == "http://two.example.com/" # fails with envjs
find("h1").text.should == "http://two.example.com/" # passes
end

def set_subdomain(subdomain)
Capybara.default_host = "#{subdomain}.example.com"
Capybara.app_host = "http://#{subdomain}.example.com"
switch_session(subdomain)
end
end
13 changes: 12 additions & 1 deletion spec/acceptance/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
module HelperMethods
# Put helper methods you need to be available in all tests here.
def set_session(id)
Capybara.instance_variable_set('@session_pool', {
"#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions[id]
})
end

def switch_session(id)
$sessions ||= {}
$sessions[:default] ||= Capybara.current_session
$sessions[id] ||= Capybara::Session.new(Capybara.current_driver, Capybara.app)
set_session(id)
end
end

RSpec.configuration.include HelperMethods, :type => :acceptance

0 comments on commit 3dc26a0

Please sign in to comment.