1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Can set cookies for given domain

This commit is contained in:
Dmitry Vorotilin 2013-04-22 11:21:03 +04:00
parent 6494884aca
commit aae2bcb02b
3 changed files with 19 additions and 5 deletions

View file

@ -337,6 +337,7 @@ Include as much information as possible. For example:
* Invalid selectors throw a useful error message
* Tie us to the 0.4 version of faye-websocket since the 0.5 version
contains breaking changes.
* Can set cookies for given domain
### 1.2.0 ###

View file

@ -177,11 +177,12 @@ module Capybara::Poltergeist
def set_cookie(name, value, options = {})
options[:name] ||= name
options[:value] ||= value
options[:domain] ||= begin
if @started
options[:domain] = URI.parse(browser.current_url).host
URI.parse(browser.current_url).host
else
options[:domain] = Capybara.app_host || "127.0.0.1"
Capybara.app_host || "127.0.0.1"
end
end
browser.set_cookie(options)

View file

@ -406,6 +406,18 @@ module Capybara::Poltergeist
@driver.cookies['foo'].expires.should == time
end
it 'can set cookies for given domain' do
port = @session.server.port
@driver.set_cookie 'capybara', '127.0.0.1'
@driver.set_cookie 'capybara', 'localhost', :domain => 'localhost'
@session.visit("http://localhost:#{port}/poltergeist/get_cookie")
@driver.body.should include('localhost')
@session.visit("http://127.0.0.1:#{port}/poltergeist/get_cookie")
@driver.body.should include('127.0.0.1')
end
it 'can enable and disable cookies' do
@driver.cookies_enabled = false
@session.visit('/set_cookie')