Skip to content

Commit

Permalink
Can set cookies for given domain
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed May 8, 2013
1 parent 6494884 commit aae2bcb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down
11 changes: 6 additions & 5 deletions lib/capybara/poltergeist/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ def cookies
def set_cookie(name, value, options = {})
options[:name] ||= name
options[:value] ||= value

if @started
options[:domain] = URI.parse(browser.current_url).host
else
options[:domain] = Capybara.app_host || "127.0.0.1"
options[:domain] ||= begin
if @started
URI.parse(browser.current_url).host
else
Capybara.app_host || "127.0.0.1"
end
end

browser.set_cookie(options)
Expand Down
12 changes: 12 additions & 0 deletions spec/integration/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ def session_url(path)
@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')
Expand Down

0 comments on commit aae2bcb

Please sign in to comment.