aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/abstract_unit.rb7
-rw-r--r--activeresource/test/cases/base_test.rb19
-rw-r--r--activeresource/test/cases/finder_test.rb2
-rw-r--r--activeresource/test/cases/format_test.rb2
-rw-r--r--activeresource/test/fixtures/sound.rb6
5 files changed, 33 insertions, 3 deletions
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb
index 129efeb879..195f93f2a6 100644
--- a/activeresource/test/abstract_unit.rb
+++ b/activeresource/test/abstract_unit.rb
@@ -75,6 +75,10 @@ def setup_response
</person>
eof
+ @startup_sound = {
+ :name => "Mac Startup Sound", :author => { :name => "Jim Reekes" }
+ }.to_xml(:root => 'sound')
+
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, @matz
mock.get "/people/2.xml", {}, @david
@@ -97,6 +101,7 @@ def setup_response
mock.put "/people/1/addresses/1.xml", {}, nil, 204
mock.delete "/people/1/addresses/1.xml", {}, nil, 200
mock.post "/people/1/addresses.xml", {}, nil, 201, 'Location' => '/people/1/addresses/5'
+ mock.get "/people/1/addresses/99.xml", {}, nil, 404
mock.get "/people//addresses.xml", {}, nil, 404
mock.get "/people//addresses/1.xml", {}, nil, 404
mock.put "/people//addresses/1.xml", {}, nil, 404
@@ -111,6 +116,8 @@ def setup_response
mock.head "/people/Greg/addresses/1.xml", {}, nil, 200
# customer
mock.get "/customers/1.xml", {}, @luis
+ # sound
+ mock.get "/sounds/1.xml", {}, @startup_sound
end
Person.user = nil
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index 6fabeeebcd..abf4259a54 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -475,6 +475,12 @@ class BaseTest < Test::Unit::TestCase
assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary')
end
+ def test_custom_element_path_without_required_prefix_param
+ assert_raise ActiveResource::MissingPrefixParam do
+ StreetAddress.element_path(1)
+ end
+ end
+
def test_module_element_path
assert_equal '/sounds/1.xml', Asset::Sound.element_path(1)
end
@@ -513,6 +519,12 @@ class BaseTest < Test::Unit::TestCase
assert_equal '/people/1/addresses/1.xml?type=work', StreetAddress.element_path(1, {:person_id => 1}, {:type => 'work'})
end
+ def test_custom_collection_path_without_required_prefix_param
+ assert_raise ActiveResource::MissingPrefixParam do
+ StreetAddress.collection_path
+ end
+ end
+
def test_custom_collection_path
assert_equal '/people/1/addresses.xml', StreetAddress.collection_path(:person_id => 1)
assert_equal '/people/1/addresses.xml', StreetAddress.collection_path('person_id' => 1)
@@ -560,6 +572,8 @@ class BaseTest < Test::Unit::TestCase
assert_equal Set.new([:the_param1]), person_class.prefix_parameters
person_class.prefix = "the_prefix/:the_param2"
assert_equal Set.new([:the_param2]), person_class.prefix_parameters
+ person_class.prefix = "the_prefix/:the_param1/other_prefix/:the_param2"
+ assert_equal Set.new([:the_param2, :the_param1]), person_class.prefix_parameters
end
end
@@ -1083,4 +1097,9 @@ class BaseTest < Test::Unit::TestCase
plan.save!
assert_equal 10.00, plan.price
end
+
+ def test_namespacing
+ sound = Asset::Sound.find(1)
+ assert_equal "Asset::Sound::Author", sound.author.class.to_s
+ end
end
diff --git a/activeresource/test/cases/finder_test.rb b/activeresource/test/cases/finder_test.rb
index fd09ef46d7..ebb783996d 100644
--- a/activeresource/test/cases/finder_test.rb
+++ b/activeresource/test/cases/finder_test.rb
@@ -84,7 +84,7 @@ class FinderTest < Test::Unit::TestCase
def test_find_by_id_not_found
assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) }
- assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
+ assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(99, :params => {:person_id => 1}) }
end
def test_find_all_sub_objects
diff --git a/activeresource/test/cases/format_test.rb b/activeresource/test/cases/format_test.rb
index c3733e13d8..bed95ef524 100644
--- a/activeresource/test/cases/format_test.rb
+++ b/activeresource/test/cases/format_test.rb
@@ -33,7 +33,7 @@ class FormatTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
remote_programmers = Person.find(:all)
assert_equal 2, remote_programmers.size
- assert remote_programmers.select { |p| p.name == 'David' }
+ assert remote_programmers.map { |p| p.name }.include? 'David'
end
end
end
diff --git a/activeresource/test/fixtures/sound.rb b/activeresource/test/fixtures/sound.rb
index 5c0ef5d55c..d9d2b99fcd 100644
--- a/activeresource/test/fixtures/sound.rb
+++ b/activeresource/test/fixtures/sound.rb
@@ -1,5 +1,9 @@
-module Asset
+module Asset
class Sound < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
end
end
+
+# to test namespacing in a module
+class Author
+end \ No newline at end of file