diff options
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/CHANGELOG | 15 | ||||
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 15 | ||||
-rw-r--r-- | activeresource/test/base_test.rb | 6 | ||||
-rw-r--r-- | activeresource/test/fixtures/beast.rb | 14 |
4 files changed, 49 insertions, 1 deletions
diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index 144264cd5a..679fb832d4 100644 --- a/activeresource/CHANGELOG +++ b/activeresource/CHANGELOG @@ -1,5 +1,20 @@ *SVN* +* Allow subclassed resources to share the site info [Rick] + + class BeastResource < ActiveResource::Base + self.site = 'http://beast.caboo.se' + end + + class Forum < BeastResource + # taken from BeastResource + # self.site = 'http://beast.caboo.se' + end + + class Topic < BeastResource + site << '/forums/:forum_id' + end + * Fix issues with ActiveResource collection handling. Closes #6291. [bmilekic] * Use attr_accessor_with_default to dry up attribute initialization. References #6538. [Stuart Halloway] diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 5f3820b2be..fd583d40e9 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -6,11 +6,16 @@ module ActiveResource # calls. cattr_accessor :logger + def self.inherited(base) + base.site = site.to_s if site + super + end + class << self attr_reader :site def site=(site) - @site = site.is_a?(URI) ? site : URI.parse(site) + @site = create_site_uri_from(site) @connection = nil @site end @@ -78,6 +83,14 @@ module ActiveResource def find_single(scope, options) new(connection.get(element_path(scope, options)), options) end + + def create_site_uri_from(site) + returning site.is_a?(URI) ? site : URI.parse(site) do |uri| + def uri.<<(extra) + path << extra + end unless uri.respond_to?(:<<) + end + end end attr_accessor :attributes diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 685f9aa994..e0bbdc00bf 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -1,6 +1,7 @@ require "#{File.dirname(__FILE__)}/abstract_unit" require "fixtures/person" require "fixtures/street_address" +require "fixtures/beast" class BaseTest < Test::Unit::TestCase def setup @@ -171,4 +172,9 @@ class BaseTest < Test::Unit::TestCase def test_delete assert Person.delete(1) end + + def test_should_use_site_prefix_and_credentials + assert_equal 'http://foo:bar@beast.caboo.se', Forum.site.to_s + assert_equal 'http://foo:bar@beast.caboo.se/forums/:forum_id', Topic.site.to_s + end end diff --git a/activeresource/test/fixtures/beast.rb b/activeresource/test/fixtures/beast.rb new file mode 100644 index 0000000000..1fe81da425 --- /dev/null +++ b/activeresource/test/fixtures/beast.rb @@ -0,0 +1,14 @@ +class BeastResource < ActiveResource::Base + self.site = 'http://beast.caboo.se' + site.user = 'foo' + site.password = 'bar' +end + +class Forum < BeastResource + # taken from BeastResource + # self.site = 'http://beast.caboo.se' +end + +class Topic < BeastResource + site << '/forums/:forum_id' +end
\ No newline at end of file |