aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorMarshall Huss <mwhuss@gmail.com>2009-05-18 18:34:44 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-08 15:33:55 -0700
commit4d1552810f631898c3d7f758454c92ca35a8cb26 (patch)
treef76b0e9ecbf5aa46263d6515bd603ba7d90adf66 /activeresource/test
parent5786395760f1e1906c878df4023cac3741e66e87 (diff)
downloadrails-4d1552810f631898c3d7f758454c92ca35a8cb26.tar.gz
rails-4d1552810f631898c3d7f758454c92ca35a8cb26.tar.bz2
rails-4d1552810f631898c3d7f758454c92ca35a8cb26.zip
HTTP proxy support
[#2133 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/base_test.rb64
-rw-r--r--activeresource/test/connection_test.rb10
-rw-r--r--activeresource/test/fixtures/proxy.rb4
3 files changed, 78 insertions, 0 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
index 82d3b2ae96..e68d562d97 100644
--- a/activeresource/test/base_test.rb
+++ b/activeresource/test/base_test.rb
@@ -3,6 +3,7 @@ require "fixtures/person"
require "fixtures/customer"
require "fixtures/street_address"
require "fixtures/beast"
+require "fixtures/proxy"
require 'active_support/core_ext/hash/conversions'
class BaseTest < Test::Unit::TestCase
@@ -125,6 +126,28 @@ class BaseTest < Test::Unit::TestCase
assert_nil actor.site
end
+ def test_proxy_accessor_accepts_uri_or_string_argument
+ proxy = URI.parse('http://localhost')
+
+ assert_nothing_raised { Person.proxy = 'http://localhost' }
+ assert_equal proxy, Person.proxy
+
+ assert_nothing_raised { Person.proxy = proxy }
+ assert_equal proxy, Person.proxy
+ end
+
+ def test_should_use_proxy_prefix_and_credentials
+ assert_equal 'http://user:password@proxy.local:3000', ProxyResource.proxy.to_s
+ end
+
+ def test_proxy_variable_can_be_reset
+ actor = Class.new(ActiveResource::Base)
+ assert_nil actor.site
+ actor.proxy = 'http://localhost:31337'
+ actor.proxy = nil
+ assert_nil actor.site
+ end
+
def test_should_accept_setting_user
Forum.user = 'david'
assert_equal('david', Forum.user)
@@ -221,6 +244,47 @@ class BaseTest < Test::Unit::TestCase
assert_equal fruit.site, apple.site, 'subclass did not adopt changes from parent class'
end
+ def test_proxy_reader_uses_superclass_site_until_written
+ # Superclass is Object so returns nil.
+ assert_nil ActiveResource::Base.proxy
+ assert_nil Class.new(ActiveResource::Base).proxy
+
+ # Subclass uses superclass proxy.
+ actor = Class.new(Person)
+ assert_equal Person.proxy, actor.proxy
+
+ # Subclass returns frozen superclass copy.
+ assert !Person.proxy.frozen?
+ assert actor.proxy.frozen?
+
+ # Changing subclass proxy doesn't change superclass site.
+ actor.proxy = 'http://localhost:31337'
+ assert_not_equal Person.proxy, actor.proxy
+
+ # Changed subclass proxy is not frozen.
+ assert !actor.proxy.frozen?
+
+ # Changing superclass proxy doesn't overwrite subclass site.
+ Person.proxy = 'http://somewhere.else'
+ assert_not_equal Person.proxy, actor.proxy
+
+ # Changing superclass proxy after subclassing changes subclass site.
+ jester = Class.new(actor)
+ actor.proxy = 'http://nomad'
+ assert_equal actor.proxy, jester.proxy
+ assert jester.proxy.frozen?
+
+ # Subclasses are always equal to superclass proxy when not overridden
+ fruit = Class.new(ActiveResource::Base)
+ apple = Class.new(fruit)
+
+ fruit.proxy = 'http://market'
+ assert_equal fruit.proxy, apple.proxy, 'subclass did not adopt changes from parent class'
+
+ fruit.proxy = 'http://supermarket'
+ assert_equal fruit.proxy, apple.proxy, 'subclass did not adopt changes from parent class'
+ end
+
def test_user_reader_uses_superclass_user_until_written
# Superclass is Object so returns nil.
assert_nil ActiveResource::Base.user
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 831fbc4003..60a8204533 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -101,6 +101,16 @@ class ConnectionTest < Test::Unit::TestCase
assert_equal site, @conn.site
end
+ def test_proxy_accessor_accepts_uri_or_string_argument
+ proxy = URI.parse("http://proxy_user:proxy_password@proxy.local:4242")
+
+ assert_nothing_raised { @conn.proxy = "http://proxy_user:proxy_password@proxy.local:4242" }
+ assert_equal proxy, @conn.proxy
+
+ assert_nothing_raised { @conn.proxy = proxy }
+ assert_equal proxy, @conn.proxy
+ end
+
def test_timeout_accessor
@conn.timeout = 5
assert_equal 5, @conn.timeout
diff --git a/activeresource/test/fixtures/proxy.rb b/activeresource/test/fixtures/proxy.rb
new file mode 100644
index 0000000000..bb8e015df0
--- /dev/null
+++ b/activeresource/test/fixtures/proxy.rb
@@ -0,0 +1,4 @@
+class ProxyResource < ActiveResource::Base
+ self.site = "http://localhost"
+ self.proxy = "http://user:password@proxy.local:3000"
+end \ No newline at end of file