diff options
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/base_test.rb | 30 | ||||
-rw-r--r-- | activeresource/test/fixtures/beast.rb | 4 |
2 files changed, 32 insertions, 2 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index e0bbdc00bf..ad799806e5 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -43,6 +43,36 @@ class BaseTest < Test::Unit::TestCase assert_equal site, Person.site end + def test_site_reader_uses_superclass_site_until_written + # Superclass is Object so returns nil. + assert_nil ActiveResource::Base.site + assert_nil Class.new(ActiveResource::Base).site + + # Subclass uses superclass site. + actor = Class.new(Person) + assert_equal Person.site, actor.site + + # Subclass returns frozen superclass copy. + assert !Person.site.frozen? + assert actor.site.frozen? + + # Changing subclass site doesn't change superclass site. + actor.site = 'http://localhost:31337' + assert_not_equal Person.site, actor.site + + # Changed subclass site is not frozen. + assert !actor.site.frozen? + + # Changing superclass site doesn't overwrite subclass site. + Person.site = 'http://somewhere.else' + assert_not_equal Person.site, actor.site + + # Changing superclass site after subclassing changes subclass site. + jester = Class.new(actor) + actor.site = 'http://nomad' + assert_equal actor.site, jester.site + assert jester.site.frozen? + end def test_collection_name assert_equal "people", Person.collection_name diff --git a/activeresource/test/fixtures/beast.rb b/activeresource/test/fixtures/beast.rb index 1fe81da425..e31ec58346 100644 --- a/activeresource/test/fixtures/beast.rb +++ b/activeresource/test/fixtures/beast.rb @@ -10,5 +10,5 @@ class Forum < BeastResource end class Topic < BeastResource - site << '/forums/:forum_id' -end
\ No newline at end of file + self.site += '/forums/:forum_id' +end |