Class: Capybara::Driver::Mechanize
- Inherits:
-
Object
- Object
- Capybara::Driver::Mechanize
- Defined in:
- lib/monkey-patches/capybara-mechanize-patches.rb
Defined Under Namespace
Classes: FakeURI
Instance Method Summary collapse
- #add_cookie(attribs) ⇒ Object
- #cookie_named(name) ⇒ Object
- #cookies ⇒ Object
- #delete_all_cookies ⇒ Object
- #delete_cookie(cookie_name) ⇒ Object
- #process_remote_request(method, url, *options) ⇒ Object
Instance Method Details
#add_cookie(attribs) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 76 def (attribs) c = Mechanize::Cookie.new(attribs[:name],attribs[:value]) # remember: mechanize always removes leading '.' from domains c.domain = attribs[:domain].sub!(/^./, '') c.path = '/' c.expires = attribs[:expires] c.secure = attribs[:secure] agent..add(FakeURI.new(c.domain),c) end |
#cookie_named(name) ⇒ Object
55 56 57 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 55 def (name) .find { |c| c[:name] == name } end |
#cookies ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 35 def = [] agent..jar.each do |domain| domain[1].each do |path| path[1].each do || .push({ :name => [1].name, :value => [1].value, :domain => [1].domain, :secure => [1].secure, :expires => [1].expires, :path => [1].path }) end end end end |
#delete_all_cookies ⇒ Object
71 72 73 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 71 def agent..clear! end |
#delete_cookie(cookie_name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 59 def () agent..jar.each do |domain| domain[1].each do |path| path[1].each do || if [0] == agent..jar[domain[0]][path[0]].delete([0]) end end end end end |
#process_remote_request(method, url, *options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/monkey-patches/capybara-mechanize-patches.rb', line 5 def process_remote_request(method, url, *) if remote?(url) remote_uri = URI.parse(url) @scheme = remote_uri.scheme if remote_uri.scheme if remote_uri.host.nil? #TODO: Ascertain whether this is really true... if(method == :post && url == "" && @prev_url) #patch #require 'uri' #url = "http://#{URI.parse(@prev_url).host}#{URI.parse(@prev_url).path}" #p url url = @prev_url #patch else remote_host = @last_remote_host || Capybara.app_host || Capybara.default_host url = File.join(remote_host, url) #url = "http://#{url}" unless url.include?("http") url = "#{@scheme}://#{url}" unless url.match(/^http.*/) end else @last_remote_host = "#{remote_uri.host}:#{remote_uri.port}" end @prev_url = url #patch reset_cache @agent.send *( [method, url] + ) @last_request_remote = true end end |